This repository has been archived by the owner on Oct 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
lcd.c
2412 lines (2052 loc) · 67 KB
/
lcd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* LCD3 firmware
*
* Copyright (C) Casainho, 2018.
*
* Released under the GPL License, Version 3
*/
#include <string.h>
#include "stm8s.h"
#include "stm8s_gpio.h"
#include "stm8s_iwdg.h"
#include "gpio.h"
#include "timers.h"
#include "ht162.h"
#include "lcd.h"
#include "adc.h"
#include "main.h"
#include "config.h"
#include "button.h"
#include "eeprom.h"
#include "pins.h"
#include "uart.h"
#define LCD_MENU_CONFIG_SUBMENU_MAX_NUMBER 10
uint8_t ui8_lcd_frame_buffer[LCD_FRAME_BUFFER_SIZE];
uint8_t ui8_lcd_field_offset[] = {
ASSIST_LEVEL_DIGIT_OFFSET,
ODOMETER_DIGIT_OFFSET,
TEMPERATURE_DIGIT_OFFSET,
WHEEL_SPEED_OFFSET,
BATTERY_POWER_DIGIT_OFFSET,
0
};
uint8_t ui8_lcd_digit_mask[] = {
NUMBER_0_MASK,
NUMBER_1_MASK,
NUMBER_2_MASK,
NUMBER_3_MASK,
NUMBER_4_MASK,
NUMBER_5_MASK,
NUMBER_6_MASK,
NUMBER_7_MASK,
NUMBER_8_MASK,
NUMBER_9_MASK
};
uint8_t ui8_lcd_digit_mask_inverted[] = {
NUMBER_0_MASK_INVERTED,
NUMBER_1_MASK_INVERTED,
NUMBER_2_MASK_INVERTED,
NUMBER_3_MASK_INVERTED,
NUMBER_4_MASK_INVERTED,
NUMBER_5_MASK_INVERTED,
NUMBER_6_MASK_INVERTED,
NUMBER_7_MASK_INVERTED,
NUMBER_8_MASK_INVERTED,
NUMBER_9_MASK_INVERTED
};
static uint32_t ui32_battery_voltage_accumulated_x10000 = 0;
static uint16_t ui16_battery_voltage_filtered_x10;
static uint16_t ui16_battery_current_accumulated_x5 = 0;
static uint16_t ui16_battery_current_filtered_x5;
static uint16_t ui16_battery_power_accumulated = 0;
static uint16_t ui16_battery_power_filtered_x50;
static uint16_t ui16_battery_power_filtered;
static uint32_t ui32_wh_sum_x5 = 0;
static uint32_t ui32_wh_sum_counter = 0;
static uint32_t ui32_wh_x10 = 0;
static uint8_t ui8_config_wh_x10_offset;
static uint32_t ui32_torque_sensor_force_x1000;
static uint32_t ui32_torque_accumulated = 0;
static uint16_t ui32_torque_accumulated_filtered_x10;
static uint8_t ui8_motor_controller_init = 1;
static uint8_t ui8_lights_state = 0;
static uint8_t lcd_lights_symbol = 0;
static uint8_t ui8_lcd_menu = 0;
static uint8_t ui8_lcd_menu_config_submenu_state = 0;
static uint8_t ui8_lcd_menu_flash_counter = 0;
static uint16_t ui16_lcd_menu_flash_counter_temperature = 0;
static uint8_t ui8_lcd_menu_flash_state;
static uint8_t ui8_lcd_menu_flash_state_temperature;
static uint8_t ui8_lcd_menu_config_submenu_number = 0;
static uint8_t ui8_lcd_menu_config_submenu_active = 0;
static struct_motor_controller_data motor_controller_data;
static struct_configuration_variables configuration_variables;
static uint16_t ui16_battery_soc_watts_hour;
static uint8_t ui8_reset_to_defaults_counter;
static uint8_t ui8_state_temp_field;
uint8_t ui8_lcd_power_off_time_counter_minutes = 0;
static uint16_t ui16_lcd_power_off_time_counter = 0;
static uint8_t offroad_mode_assist_symbol_state = 0;
static uint8_t offroad_mode_assist_symbol_state_blink_counter = 0;
void low_pass_filter_battery_voltage_current_power (void);
void lcd_enable_motor_symbol (uint8_t ui8_state);
void lcd_enable_lights_symbol (uint8_t ui8_state);
void lcd_enable_walk_symbol (uint8_t ui8_state);
void lcd_enable_km_symbol (uint8_t ui8_state);
void lcd_enable_wheel_speed_point_symbol (uint8_t ui8_state);
void lcd_enable_kmh_symbol (uint8_t ui8_state);
void lcd_enable_mph_symbol (uint8_t ui8_state);
void lcd_enable_odo_symbol (uint8_t ui8_state);
void calc_wh (void);
void assist_level_state (void);
void brake (void);
void odometer (void);
void odometer_increase_field_state (void);
void wheel_speed (void);
void power (void);
void power_off_management (void);
uint8_t first_time_management (void);
void temperature (void);
void battery_soc (void);
void low_pass_filter_pedal_torque (void);
void lights_state (void);
void lcd_set_backlight_intensity (uint8_t ui8_intensity);
void walk_assist_state (void);
void offroad_mode (void);
void lcd_execute_main_screen (void);
void lcd_execute_menu_config (void);
void lcd_execute_menu_config_power (void);
void lcd_execute_menu_config_submenu_wheel_config (void);
void lcd_execute_menu_config_submenu_battery (void);
void lcd_execute_menu_config_submenu_battery_soc (void);
void lcd_execute_menu_config_submenu_assist_level (void);
void lcd_execute_menu_config_submenu_motor_startup_power_boost (void);
void lcd_execute_menu_config_submenu_motor_temperature (void);
void lcd_execute_menu_config_submenu_lcd ();
void lcd_execute_menu_config_submenu_offroad_mode (void);
void lcd_execute_menu_config_submenu_various (void);
void lcd_execute_menu_config_submenu_technical (void);
void update_menu_flashing_state (void);
void advance_on_submenu (uint8_t* ui8_p_state, uint8_t ui8_state_max_number);
void calc_battery_soc_watts_hour (void);
void calc_odometer (void);
static void automatic_power_off_management (void);
void lcd_power_off (void);
void lcd_enable_vol_symbol (uint8_t ui8_state);
void lcd_enable_w_symbol (uint8_t ui8_state);
void lcd_enable_odometer_point_symbol (uint8_t ui8_state);
void lcd_enable_brake_symbol (uint8_t ui8_state);
void lcd_enable_assist_symbol (uint8_t ui8_state);
void lcd_enable_battery_power_1_symbol (uint8_t ui8_state);
void lcd_enable_temperature_1_symbol (uint8_t ui8_state);
void lcd_enable_kmh_symbol (uint8_t ui8_state);
void lcd_enable_wheel_speed_point_symbol (uint8_t ui8_state);
void lcd_enable_temperature_degrees_symbol (uint8_t ui8_state);
void lcd_enable_dst_symbol (uint8_t ui8_state);
void lcd_enable_tm_symbol (uint8_t ui8_state);
void lcd_update (void);
void lcd_clear (void);
void lcd_set_frame_buffer (void);
void lcd_print (uint32_t ui32_number, uint8_t ui8_lcd_field, uint8_t ui8_options);
void clock_lcd (void)
{
lcd_clear (); // start by clear LCD
if (first_time_management ())
return;
update_menu_flashing_state ();
// enter menu configurations: UP + DOWN click event
if (get_button_up_down_click_event () &&
ui8_lcd_menu != 1)
{
clear_button_up_down_click_event ();
ui8_lcd_menu = 1;
}
// enter in menu set power: ONOFF + UP click event
if (!configuration_variables.ui8_offroad_func_enabled &&
get_button_onoff_state () && get_button_up_state ())
{
button_clear_events ();
ui8_lcd_menu = 2;
}
// change temperature field state: ONOFF + DOWN click event
if (!configuration_variables.ui8_offroad_func_enabled &&
get_button_onoff_state () && get_button_down_state ())
{
button_clear_events ();
if (ui8_state_temp_field == 0)
{
configuration_variables.ui8_temperature_field_config++;
if (configuration_variables.ui8_throttle_adc_measures_motor_temperature)
{
if (configuration_variables.ui8_temperature_field_config > 2) { configuration_variables.ui8_temperature_field_config = 0; }
}
else
{
if (configuration_variables.ui8_temperature_field_config > 1) { configuration_variables.ui8_temperature_field_config = 0; }
}
ui8_state_temp_field = 1;
}
}
else
{
ui8_state_temp_field = 0;
}
calc_battery_soc_watts_hour ();
switch (ui8_lcd_menu)
{
case 0:
lcd_execute_main_screen ();
break;
case 1:
lcd_execute_menu_config ();
break;
case 2:
lcd_execute_menu_config_power ();
break;
}
low_pass_filter_battery_voltage_current_power ();
low_pass_filter_pedal_torque ();
calc_wh ();
calc_odometer ();
automatic_power_off_management ();
lcd_update ();
// power off system: ONOFF long click event
power_off_management ();
}
void lcd_execute_main_screen (void)
{
temperature ();
assist_level_state ();
odometer ();
wheel_speed ();
walk_assist_state ();
offroad_mode ();
power ();
battery_soc ();
lights_state ();
brake ();
}
void lcd_execute_menu_config (void)
{
// button check when submenu is not active
if (!ui8_lcd_menu_config_submenu_active)
{
// leave config menu with a button_onoff_long_click
if (get_button_onoff_long_click_event ())
{
clear_button_onoff_long_click_event ();
ui8_lcd_menu = 0;
// save the updated variables on EEPROM
eeprom_write_variables ();
return;
}
// advance on submenu on button_onoff_click_event
advance_on_submenu (&ui8_lcd_menu_config_submenu_number, LCD_MENU_CONFIG_SUBMENU_MAX_NUMBER);
// check if we should enter a submenu
if (get_button_up_click_event () || get_button_down_click_event ())
{
clear_button_up_click_event ();
clear_button_down_click_event ();
ui8_lcd_menu_config_submenu_active = 1;
ui8_config_wh_x10_offset = 1;
}
// print submenu number only half of the time
if (ui8_lcd_menu_flash_state)
{
lcd_print (ui8_lcd_menu_config_submenu_number, WHEEL_SPEED_FIELD, 1);
}
}
// ui8_lcd_menu_config_submenu_active == 1
else
{
switch (ui8_lcd_menu_config_submenu_number)
{
case 0:
lcd_execute_menu_config_submenu_wheel_config ();
break;
case 1:
lcd_execute_menu_config_submenu_battery ();
break;
case 2:
lcd_execute_menu_config_submenu_battery_soc ();
break;
case 3:
lcd_execute_menu_config_submenu_assist_level ();
break;
case 4:
lcd_execute_menu_config_submenu_motor_startup_power_boost ();
break;
case 5:
lcd_execute_menu_config_submenu_motor_temperature ();
break;
case 6:
lcd_execute_menu_config_submenu_lcd ();
break;
case 7:
lcd_execute_menu_config_submenu_offroad_mode ();
break;
case 8:
lcd_execute_menu_config_submenu_various ();
break;
case 9:
lcd_execute_menu_config_submenu_technical ();
break;
default:
ui8_lcd_menu_config_submenu_number = 0;
break;
}
// leave config menu with a button_onoff_long_click
if (get_button_onoff_long_click_event ())
{
clear_button_onoff_long_click_event ();
ui8_lcd_menu_config_submenu_active = 0;
ui8_lcd_menu_config_submenu_state = 0;
}
}
}
void lcd_execute_menu_config_submenu_wheel_config (void)
{
// advance on submenus on button_onoff_click_event
advance_on_submenu (&ui8_lcd_menu_config_submenu_state, 3);
switch (ui8_lcd_menu_config_submenu_state)
{
// menu to choose max wheel speed
case 0:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
configuration_variables.ui8_wheel_max_speed++;
if (configuration_variables.ui8_wheel_max_speed >= 99) { configuration_variables.ui8_wheel_max_speed = 99; }
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
configuration_variables.ui8_wheel_max_speed--;
if (configuration_variables.ui8_wheel_max_speed < 1) { configuration_variables.ui8_wheel_max_speed = 1; }
}
// print wheel speed only half of the time
if (ui8_lcd_menu_flash_state)
{
lcd_print (((uint16_t) configuration_variables.ui8_wheel_max_speed) * 10, WHEEL_SPEED_FIELD, 0);
}
lcd_enable_kmh_symbol (1);
break;
// menu to choose wheel perimeter
case 1:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
configuration_variables.ui16_wheel_perimeter += 10;
// max value is 3000 mm
if (configuration_variables.ui16_wheel_perimeter >= 3000) { configuration_variables.ui16_wheel_perimeter = 3000; }
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
configuration_variables.ui16_wheel_perimeter -= 10;
// min value is 750 mm
if (configuration_variables.ui16_wheel_perimeter < 750) { configuration_variables.ui16_wheel_perimeter = 750; }
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui16_wheel_perimeter, ODOMETER_FIELD, 1);
}
break;
// menu to choose Km/h or MP/h
case 2:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
configuration_variables.ui8_units_type++;
if (configuration_variables.ui8_units_type > 1) { configuration_variables.ui8_units_type = 1; }
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
configuration_variables.ui8_units_type--;
if (configuration_variables.ui8_units_type != 0) { configuration_variables.ui8_units_type = 0; }
}
if (ui8_lcd_menu_flash_state)
{
if (configuration_variables.ui8_units_type)
lcd_enable_mph_symbol (1);
else
lcd_enable_kmh_symbol (1);
}
break;
}
}
void lcd_execute_menu_config_submenu_battery (void)
{
advance_on_submenu (&ui8_lcd_menu_config_submenu_state, 4);
switch (ui8_lcd_menu_config_submenu_state)
{
// battery max current
case 0:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
configuration_variables.ui8_battery_max_current++;
if (configuration_variables.ui8_battery_max_current > 100) { configuration_variables.ui8_battery_max_current = 100; }
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
if (configuration_variables.ui8_battery_max_current > 0)
configuration_variables.ui8_battery_max_current--;
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui8_battery_max_current, ODOMETER_FIELD, 1);
}
break;
// battery low voltage cut-off
case 1:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
if (configuration_variables.ui16_battery_low_voltage_cut_off_x10 < 630) { configuration_variables.ui16_battery_low_voltage_cut_off_x10++; }
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
if (configuration_variables.ui16_battery_low_voltage_cut_off_x10 > 161) { configuration_variables.ui16_battery_low_voltage_cut_off_x10--; }
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui16_battery_low_voltage_cut_off_x10, ODOMETER_FIELD, 0);
}
break;
// battery cells number
case 2:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
if (configuration_variables.ui8_battery_cells_number < 15) { configuration_variables.ui8_battery_cells_number++; }
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
if (configuration_variables.ui8_battery_cells_number > 7) { configuration_variables.ui8_battery_cells_number--; }
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui8_battery_cells_number, ODOMETER_FIELD, 1);
}
break;
// battery pack resistance
case 3:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
if (configuration_variables.ui16_battery_pack_resistance_x1000 < 1001) { configuration_variables.ui16_battery_pack_resistance_x1000++; }
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
if (configuration_variables.ui16_battery_pack_resistance_x1000 > 0) { configuration_variables.ui16_battery_pack_resistance_x1000--; }
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui16_battery_pack_resistance_x1000, ODOMETER_FIELD, 1);
}
break;
}
lcd_print (ui8_lcd_menu_config_submenu_state, WHEEL_SPEED_FIELD, 1);
}
void lcd_execute_menu_config_submenu_battery_soc (void)
{
uint8_t ui8_temp;
advance_on_submenu (&ui8_lcd_menu_config_submenu_state, 5);
switch (ui8_lcd_menu_config_submenu_state)
{
// menu to enable/disable show of numeric watts hour value
case 0:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
configuration_variables.ui8_show_numeric_battery_soc |= 1;
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
configuration_variables.ui8_show_numeric_battery_soc &= ~1;
}
ui8_temp = ((configuration_variables.ui8_show_numeric_battery_soc & 1) ? 1 : 0);
if (ui8_lcd_menu_flash_state)
{
lcd_print (ui8_temp, ODOMETER_FIELD, 1);
}
break;
// menu to enable/disable show of numeric watts hour value in incrementing or decementing percentage
case 1:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
configuration_variables.ui8_show_numeric_battery_soc |= 2;
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
configuration_variables.ui8_show_numeric_battery_soc &= ~2;
}
ui8_temp = ((configuration_variables.ui8_show_numeric_battery_soc & 2) ? 1 : 0);
if (ui8_lcd_menu_flash_state)
{
lcd_print (ui8_temp, ODOMETER_FIELD, 1);
}
break;
// battery_voltage_reset_wh_counter
case 2:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
if (configuration_variables.ui16_battery_voltage_reset_wh_counter_x10 < 630) { configuration_variables.ui16_battery_voltage_reset_wh_counter_x10++; }
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
if (configuration_variables.ui16_battery_voltage_reset_wh_counter_x10 > 161) { configuration_variables.ui16_battery_voltage_reset_wh_counter_x10--; }
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui16_battery_voltage_reset_wh_counter_x10, ODOMETER_FIELD, 0);
}
break;
// menu to choose watts hour value to be equal to 100% of battery SOC
case 3:
if (get_button_up_click_event ())
{
button_clear_events ();
// increment at 10 units
configuration_variables.ui32_wh_x10_100_percent += 100;
if (configuration_variables.ui32_wh_x10_100_percent > 99900) { configuration_variables.ui32_wh_x10_100_percent = 99900; }
}
if (get_button_down_click_event ())
{
button_clear_events ();
configuration_variables.ui32_wh_x10_100_percent -= 100;
if (configuration_variables.ui32_wh_x10_100_percent < 100) { configuration_variables.ui32_wh_x10_100_percent = 0; }
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui32_wh_x10_100_percent, ODOMETER_FIELD, 0);
}
break;
// menu to set current watts hour value
case 4:
// on the very first time, use current value of ui32_wh_x10
if (ui8_config_wh_x10_offset)
{
ui8_config_wh_x10_offset = 0;
configuration_variables.ui32_wh_x10_offset = ui32_wh_x10;
}
// keep reseting this values
ui32_wh_sum_x5 = 0;
ui32_wh_sum_counter = 0;
ui32_wh_x10 = 0;
if (get_button_up_click_event ())
{
button_clear_events ();
// increment at 10 units
configuration_variables.ui32_wh_x10_offset += 100;
if (configuration_variables.ui32_wh_x10_offset > 99900) { configuration_variables.ui32_wh_x10_offset = 99900; }
}
if (get_button_down_click_event ())
{
button_clear_events ();
if (configuration_variables.ui32_wh_x10_offset > 100)
{
configuration_variables.ui32_wh_x10_offset -= 100;
}
else if (configuration_variables.ui32_wh_x10_offset > 0)
{
configuration_variables.ui32_wh_x10_offset = 0;
}
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui32_wh_x10_offset, ODOMETER_FIELD, 0);
}
break;
}
lcd_print (ui8_lcd_menu_config_submenu_state, WHEEL_SPEED_FIELD, 1);
}
void lcd_execute_menu_config_submenu_assist_level (void)
{
advance_on_submenu (&ui8_lcd_menu_config_submenu_state, (configuration_variables.ui8_number_of_assist_levels + 1));
// number of assist levels: 0 to 9
if (ui8_lcd_menu_config_submenu_state == 0)
{
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
if (configuration_variables.ui8_number_of_assist_levels < 9) { configuration_variables.ui8_number_of_assist_levels++; }
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
if (configuration_variables.ui8_number_of_assist_levels > 1) { configuration_variables.ui8_number_of_assist_levels--; }
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui8_number_of_assist_levels, ODOMETER_FIELD, 1);
}
}
// value of each assist level
else
{
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
configuration_variables.ui8_assist_level_power [(ui8_lcd_menu_config_submenu_state - 1)]++;
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
configuration_variables.ui8_assist_level_power [(ui8_lcd_menu_config_submenu_state - 1)]--;
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui8_assist_level_power [ui8_lcd_menu_config_submenu_state - 1] * 25, ODOMETER_FIELD, 1);
}
}
lcd_print (ui8_lcd_menu_config_submenu_state, WHEEL_SPEED_FIELD, 1);
}
void lcd_execute_menu_config_submenu_motor_startup_power_boost (void)
{
advance_on_submenu (&ui8_lcd_menu_config_submenu_state, (configuration_variables.ui8_number_of_assist_levels + 4));
// enable or disable
if (ui8_lcd_menu_config_submenu_state == 0)
{
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
configuration_variables.ui8_startup_motor_power_boost_state |= 1;
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
configuration_variables.ui8_startup_motor_power_boost_state &= ~1;
}
if (ui8_lcd_menu_flash_state)
{
lcd_print ((configuration_variables.ui8_startup_motor_power_boost_state & 1) ? 1: 0, ODOMETER_FIELD, 1);
}
}
// limit to max power
else if (ui8_lcd_menu_config_submenu_state == 1)
{
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
configuration_variables.ui8_startup_motor_power_boost_state |= 2;
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
configuration_variables.ui8_startup_motor_power_boost_state &= ~2;
}
if (ui8_lcd_menu_flash_state)
{
lcd_print ((configuration_variables.ui8_startup_motor_power_boost_state & 2) ? 1: 0, ODOMETER_FIELD, 1);
}
}
// startup motor power boost time
else if (ui8_lcd_menu_config_submenu_state == 2)
{
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
configuration_variables.ui8_startup_motor_power_boost_time++;
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
configuration_variables.ui8_startup_motor_power_boost_time--;
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui8_startup_motor_power_boost_time, ODOMETER_FIELD, 0);
}
}
// startup motor power boost fade time
else if (ui8_lcd_menu_config_submenu_state == 3)
{
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
configuration_variables.ui8_startup_motor_power_boost_fade_time++;
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
configuration_variables.ui8_startup_motor_power_boost_fade_time--;
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui8_startup_motor_power_boost_fade_time, ODOMETER_FIELD, 0);
}
}
// value of each assist level power boost
else
{
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
// the BATTERY_POWER_FIELD can't show higher value
configuration_variables.ui8_startup_motor_power_boost [(ui8_lcd_menu_config_submenu_state - 4)]++;
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
configuration_variables.ui8_startup_motor_power_boost [(ui8_lcd_menu_config_submenu_state - 4)]--;
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui8_startup_motor_power_boost [ui8_lcd_menu_config_submenu_state - 4] * 25, ODOMETER_FIELD, 1);
}
}
lcd_print (ui8_lcd_menu_config_submenu_state, WHEEL_SPEED_FIELD, 1);
}
void lcd_execute_menu_config_submenu_motor_temperature (void)
{
advance_on_submenu (&ui8_lcd_menu_config_submenu_state, 3);
switch (ui8_lcd_menu_config_submenu_state)
{
// motor temperature enable
case 0:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
configuration_variables.ui8_throttle_adc_measures_motor_temperature = 1;
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
configuration_variables.ui8_throttle_adc_measures_motor_temperature = 0;
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui8_throttle_adc_measures_motor_temperature, ODOMETER_FIELD, 1);
}
break;
// motor temperature limit min
case 1:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
if (configuration_variables.ui8_motor_temperature_min_value_to_limit < 110)
{
configuration_variables.ui8_motor_temperature_min_value_to_limit++;
}
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
if (configuration_variables.ui8_motor_temperature_min_value_to_limit > 0)
{
configuration_variables.ui8_motor_temperature_min_value_to_limit--;
}
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui8_motor_temperature_min_value_to_limit, ODOMETER_FIELD, 1);
}
break;
// motor temperature limit max
case 2:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
if (configuration_variables.ui8_motor_temperature_max_value_to_limit < 110)
{
configuration_variables.ui8_motor_temperature_max_value_to_limit++;
}
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
if (configuration_variables.ui8_motor_temperature_max_value_to_limit > 0)
{
configuration_variables.ui8_motor_temperature_max_value_to_limit--;
}
}
if (ui8_lcd_menu_flash_state)
{
lcd_print (configuration_variables.ui8_motor_temperature_max_value_to_limit, ODOMETER_FIELD, 1);
}
break;
}
lcd_print (ui8_lcd_menu_config_submenu_state, WHEEL_SPEED_FIELD, 1);
}
void lcd_execute_menu_config_submenu_lcd (void)
{
advance_on_submenu (&ui8_lcd_menu_config_submenu_state, 4);
switch (ui8_lcd_menu_config_submenu_state)
{
// backlight off brightness
case 0:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
if (configuration_variables.ui8_lcd_backlight_off_brightness < 20)
{
configuration_variables.ui8_lcd_backlight_off_brightness++;
}
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
if (configuration_variables.ui8_lcd_backlight_off_brightness > 0)
{
configuration_variables.ui8_lcd_backlight_off_brightness--;
}
}
if (ui8_lcd_menu_flash_state)
{
// * 5 to show a value from 0 to 100% in steps of 5%
lcd_print (configuration_variables.ui8_lcd_backlight_off_brightness * 5, ODOMETER_FIELD, 1);
}
break;
// backlight on brightness
case 1:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
if (configuration_variables.ui8_lcd_backlight_on_brightness < 20)
{
configuration_variables.ui8_lcd_backlight_on_brightness++;
}
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
if (configuration_variables.ui8_lcd_backlight_on_brightness > 0)
{
configuration_variables.ui8_lcd_backlight_on_brightness--;
}
}
if (ui8_lcd_menu_flash_state)
{
// * 5 to show a value from 0 to 100% in steps of 5%
lcd_print (configuration_variables.ui8_lcd_backlight_on_brightness * 5, ODOMETER_FIELD, 1);
}
break;
// auto power off
case 2:
if (get_button_up_click_event ())
{
clear_button_up_click_event ();
configuration_variables.ui8_lcd_power_off_time_minutes++;
}
if (get_button_down_click_event ())
{
clear_button_down_click_event ();
configuration_variables.ui8_lcd_power_off_time_minutes--;
}