Skip to content

Commit

Permalink
Add hysteresis and level 5 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoeiterer committed Jul 3, 2017
1 parent 342fc83 commit 4bdd40f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
62 changes: 54 additions & 8 deletions firmware/energy_level_algorithm.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,58 @@

uint8_t energyLevelAlgorithm(uint16_t chargeLevel){

if(chargeLevel >= 0.75*maxChargeLevel)
return 0x10;
else if(chargeLevel >= 0.5*maxChargeLevel)
return 0x20;
else if(chargeLevel >= 0.25*maxChargeLevel)
return 0x30;
else
return 0x40;
volatile static previous_level = level1;

switch(previous_level){
case level1:
if(chargeLevel > 0.8*maxChargeLevel)
return level1;
else{
previous_level = level2;
return level2;
}
break;

case level2:
if(chargeLevel > 0.85*maxChargeLevel){
previous_level = level1;
return level1;
}else if(chargeLevel < 0.85*maxChargeLevel && chargeLevel > 0.6*maxChargeLevel){
return level2;
}else{
previous_level = level3;
return level3;
}
break;
case level3:
if(chargeLevel > 0.65*maxChargeLevel){
previous_level = level2;
return level2;
}else if(chargeLevel < 0.65*maxChargeLevel && chargeLevel > 0.4*maxChargeLevel){
return level3;
}else{
previous_level = level4;
return level4;
}
break;
case level4:
if(chargeLevel > 0.45*maxChargeLevel){
previous_level = level3;
return level3;
}else if(chargeLevel < 0.45*maxChargeLevel && chargeLevel > 0.2*maxChargeLevel){
return level4;
}else{
previous_level = level5;
return level5;
}
break;
case level5:
if(chargeLevel > 0.25*maxChargeLevel){
previous_level = level4;
return level4;
}else{
return level5;
}
break;
}
}
5 changes: 5 additions & 0 deletions firmware/energy_level_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
#include <stdint.h>

#define maxChargeLevel 0x1300
#define level1 0x10
#define level2 0x20
#define level3 0x30
#define level4 0x40
#define level5 0x50

uint8_t energyLevelAlgorithm(uint16_t chargeLevel);

Expand Down

0 comments on commit 4bdd40f

Please sign in to comment.