Skip to content

Commit 76d8ec2

Browse files
jenkiethomasjfox
authored andcommitted
Added averaged power_display for displays
1 parent d935b37 commit 76d8ec2

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

Arduino_Pedelec_Controller/Arduino_Pedelec_Controller.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ float voltage_1s,voltage_2s = 0.0; //Voltage history 1s and 2s before "now"
225225
float voltage_display = 0.0; //averaged voltage
226226
float current_display = 0.0; //averaged current
227227
double power=0.0; //calculated power
228+
double power_display=0.0; //averaged power for display
228229
double power_set = 0; //Set Power
229230
double power_poti = 0.0; //set power, calculated with current poti setting
230231
double power_throttle=0.0; //set power, calculated with current throttle setting
@@ -664,6 +665,7 @@ if (loadcell.is_ready()) //new conversion result from load cell available
664665
voltage_display = 0.99*voltage_display + 0.01*voltage; //averaged voltage for display
665666
current_display = 0.99*current_display + 0.01*current; //averaged current for display
666667
power=current*voltage;
668+
power_display = current_display*voltage_display;
667669

668670
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
669671
#ifdef SUPPORT_XCELL_RT

Arduino_Pedelec_Controller/display.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -357,20 +357,20 @@ static void display_16x2_view_main()
357357
lcd.print(spd,0);
358358
lcd.print(MY_F(" km/h "));
359359

360-
double power_display = power;
361-
if (power_display > 999)
362-
power_display = 999;
363-
else if (power_display < 0)
364-
power_display = 0;
360+
double power_temp = power_display;
361+
if (power_temp > 999)
362+
power_temp = 999;
363+
else if (power_temp < 0)
364+
power_temp = 0;
365365

366-
if (power_display<10)
366+
if (power_temp<10)
367367
{lcd.print(MY_F(" "));}
368-
if (power_display<100)
368+
if (power_temp<100)
369369
{lcd.print(MY_F(" "));}
370-
if (power_display < 0)
370+
if (power_temp < 0)
371371
lcd.print(MY_F("0"));
372372
else
373-
lcd.print(power_display,0);
373+
lcd.print(power_temp,0);
374374
lcd.print(MY_F(" W "));
375375

376376
// Break status
@@ -986,11 +986,11 @@ static void display_nokia_view_main()
986986
lcd.print(battery_percent_fromcapacity);
987987

988988
lcd.setCursor(0,1);
989-
if (power<99.5)
989+
if (power_display<99.5)
990990
{lcd.print(MY_F(" "));}
991-
if (power<9.5)
991+
if (power_display<9.5)
992992
{lcd.print(MY_F(" "));}
993-
lcd.print(power,0);
993+
lcd.print(power_display,0);
994994

995995
lcd.setCursor(9,1);
996996
if (wh<99.5)
@@ -1020,7 +1020,7 @@ static void display_nokia_view_main()
10201020

10211021
lcd.setCursor(0,4);
10221022
if ( spd > 5.0)
1023-
lcd.print(power/spd,1);
1023+
lcd.print(power_display/spd,1);
10241024
else
10251025
lcd.print(MY_F("---"));
10261026
lcd.print(MY_F("/"));
@@ -1082,9 +1082,9 @@ static void display_nokia_view_graphic()
10821082

10831083
//print the electrical power (Watt) in the top right corner
10841084
lcd.setCursorInPixels(84-4*6,0);
1085-
if (power<99.5) {lcd.print(MY_F(" "));}
1086-
if (power<9.5) {lcd.print(MY_F(" "));}
1087-
lcd.print(power,0);
1085+
if (power_display<99.5) {lcd.print(MY_F(" "));}
1086+
if (power_display<9.5) {lcd.print(MY_F(" "));}
1087+
lcd.print(power_display,0);
10881088
lcd.print(MY_F("W"));
10891089

10901090
drawSpeed(spd, 20, 2); //centered vertically
@@ -1098,7 +1098,7 @@ static void display_nokia_view_graphic()
10981098
//- the limit line shows the target power that is selected by the user (power_set_for_display)
10991099
//- the bar shows the currenlty measured electrical power that the moter consumes
11001100
lcd.setCursorInPixels(72,1);
1101-
lcd.drawVerticalBar((word)(max(curr_power_max,curr_power_poti_max)), (word)(max(power_set,0)), (word)(power), 11, 4);
1101+
lcd.drawVerticalBar((word)(max(curr_power_max,curr_power_poti_max)), (word)(max(power_set,0)), (word)(power_display), 11, 4);
11021102

11031103
//print battery percent left
11041104
lcd.setCursorInPixels(0,1);
@@ -1299,7 +1299,7 @@ void display_update()
12991299

13001300

13011301
#if (DISPLAY_TYPE & DISPLAY_TYPE_BMS3)
1302-
slcd3_update(map(battery_percent_fromcapacity,0,100,0,16),wheel_time, 0, max(power/9.75,0), (byte)0x20*(!brake_stat));
1302+
slcd3_update(map(battery_percent_fromcapacity,0,100,0,16),wheel_time, 0, max(power_display/9.75,0), (byte)0x20*(!brake_stat));
13031303
#endif
13041304
}
13051305

Arduino_Pedelec_Controller/globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern float current_display;
3030
extern byte battery_percent_fromvoltage;
3131
extern byte battery_percent_fromcapacity;
3232
extern double power;
33+
extern double power_display;
3334
extern double power_set;
3435
extern float wh;
3536
extern double wh_human;

0 commit comments

Comments
 (0)