Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit fd0f373

Browse files
committed
Improved imperial units. Decreased buttons reponse time. Enabled USB charging.
1 parent 11ee64b commit fd0f373

5 files changed

Lines changed: 32 additions & 18 deletions

File tree

Bafang_color_LCD_850C/Bafang_LCD_850C_firmware/src/buttons.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
#include "buttons.h"
1414
#include "lcd.h"
1515

16+
#define TIME_1 2000
17+
#define TIME_2 200
18+
#define TIME_3 300
19+
#define TIME_4 1000
20+
1621
#define BUTTONS_CLOCK_MS 20
1722
#define MS_TO_TICKS(a) ((a) / (BUTTONS_CLOCK_MS))
1823

@@ -183,9 +188,6 @@ void buttons_clear_all_events(void)
183188
// assuming call every 20ms
184189
void buttons_clock(void)
185190
{
186-
// needed if the event is not cleared anywhere else
187-
buttons_clear_onoff_click_long_click_event();
188-
189191
// exit if any button is pressed after clear event
190192
if((ui32_m_clear_event) &&
191193
(buttons_get_up_state() ||
@@ -213,7 +215,7 @@ void buttons_clock(void)
213215
ui32_onoff_button_state_counter++;
214216

215217
// event long click
216-
if(ui32_onoff_button_state_counter > MS_TO_TICKS(2000))
218+
if(ui32_onoff_button_state_counter > MS_TO_TICKS(TIME_1))
217219
{
218220
buttons_set_events(ONOFF_LONG_CLICK);
219221
ui32_onoff_button_state = 2;
@@ -224,7 +226,7 @@ void buttons_clock(void)
224226
if(!buttons_get_onoff_state())
225227
{
226228
// let's validade if will be a quick click + long click
227-
if(ui32_onoff_button_state_counter <= MS_TO_TICKS(300))
229+
if(ui32_onoff_button_state_counter <= MS_TO_TICKS(TIME_2))
228230
{
229231
ui32_onoff_button_state_counter = 0;
230232
ui32_onoff_button_state = 3;
@@ -261,7 +263,7 @@ void buttons_clock(void)
261263
}
262264

263265
// event click
264-
if(ui32_onoff_button_state_counter > MS_TO_TICKS(400))
266+
if(ui32_onoff_button_state_counter > MS_TO_TICKS(TIME_3))
265267
{
266268
buttons_set_events(ONOFF_CLICK);
267269
ui32_onoff_button_state = 0;
@@ -273,7 +275,7 @@ void buttons_clock(void)
273275
ui32_onoff_button_state_counter++;
274276

275277
// event click, but this time it is: click + long click
276-
if(ui32_onoff_button_state_counter > MS_TO_TICKS(1000))
278+
if(ui32_onoff_button_state_counter > MS_TO_TICKS(TIME_4))
277279
{
278280
buttons_set_events(ONOFF_CLICK_LONG_CLICK);
279281
ui32_onoff_button_state = 2;
@@ -308,7 +310,7 @@ void buttons_clock(void)
308310
ui32_up_button_state_counter++;
309311

310312
// event long click
311-
if(ui32_up_button_state_counter > MS_TO_TICKS(2000))
313+
if(ui32_up_button_state_counter > MS_TO_TICKS(TIME_1))
312314
{
313315
// up and down button click
314316
if(ui32_down_button_state == 1)
@@ -330,7 +332,7 @@ void buttons_clock(void)
330332
if(!buttons_get_up_state())
331333
{
332334
// let's validade if will be a quick click + long click
333-
if(ui32_up_button_state_counter <= MS_TO_TICKS(300))
335+
if(ui32_up_button_state_counter <= MS_TO_TICKS(TIME_2))
334336
{
335337
ui32_up_button_state_counter = 0;
336338
ui32_up_button_state = 3;
@@ -367,7 +369,7 @@ void buttons_clock(void)
367369
}
368370

369371
// event click
370-
if(ui32_up_button_state_counter > MS_TO_TICKS(400))
372+
if(ui32_up_button_state_counter > MS_TO_TICKS(TIME_3))
371373
{
372374
buttons_set_events(UP_CLICK);
373375
ui32_up_button_state = 0;
@@ -379,7 +381,7 @@ void buttons_clock(void)
379381
ui32_up_button_state_counter++;
380382

381383
// event click, but this time it is: click + long click
382-
if(ui32_up_button_state_counter > MS_TO_TICKS(1000))
384+
if(ui32_up_button_state_counter > MS_TO_TICKS(TIME_4))
383385
{
384386
buttons_set_events(UP_CLICK_LONG_CLICK);
385387
ui32_up_button_state = 2;
@@ -414,7 +416,7 @@ void buttons_clock(void)
414416
ui32_down_button_state_counter++;
415417

416418
// event long click
417-
if(ui32_down_button_state_counter > MS_TO_TICKS(2000))
419+
if(ui32_down_button_state_counter > MS_TO_TICKS(TIME_1))
418420
{
419421
// up and down button click
420422
if (ui32_up_button_state == 1)
@@ -436,7 +438,7 @@ void buttons_clock(void)
436438
if(!buttons_get_down_state())
437439
{
438440
// let's validade if will be a quick click + long click
439-
if(ui32_down_button_state_counter <= MS_TO_TICKS(300))
441+
if(ui32_down_button_state_counter <= MS_TO_TICKS(TIME_2))
440442
{
441443
ui32_down_button_state_counter = 0;
442444
ui32_down_button_state = 3;
@@ -473,7 +475,7 @@ void buttons_clock(void)
473475
}
474476

475477
// event click
476-
if(ui32_down_button_state_counter > MS_TO_TICKS(400))
478+
if(ui32_down_button_state_counter > MS_TO_TICKS(TIME_3))
477479
{
478480
buttons_set_events(DOWN_CLICK);
479481
ui32_down_button_state = 0;
@@ -485,7 +487,7 @@ void buttons_clock(void)
485487
ui32_down_button_state_counter++;
486488

487489
// event click, but this time it is: click + long click
488-
if(ui32_down_button_state_counter > MS_TO_TICKS(1000))
490+
if(ui32_down_button_state_counter > MS_TO_TICKS(TIME_4))
489491
{
490492
buttons_set_events(DOWN_CLICK_LONG_CLICK);
491493
ui32_down_button_state = 2;

Bafang_color_LCD_850C/Bafang_LCD_850C_firmware/src/lcd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ void lcd_clock(void)
159159

160160
// enter in menu set power: ONOFF + UP click event
161161
if(m_lcd_vars.lcd_screen_state == LCD_SCREEN_MAIN &&
162-
buttons_get_onoff_long_click_event() &&
163-
buttons_get_up_long_click_event())
162+
buttons_get_onoff_click_event() &&
163+
buttons_get_up_click_event())
164164
{
165165
buttons_clear_all_events();
166166
m_lcd_vars.main_screen_state = MAIN_SCREEN_STATE_POWER;

Bafang_color_LCD_850C/Bafang_LCD_850C_firmware/src/lcd_configurations.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,7 @@ void motor_temperature_min_limit(struct_menu_data *p_menu_data)
15251525
lcd_var_number.ui8_number_digits = 3;
15261526
lcd_var_number.ui8_decimal_digit = 0;
15271527
lcd_var_number.ui32_increment_step = 1;
1528+
lcd_var_number.ui8_need_update = 0;
15281529

15291530
if(p_m_l3_vars->ui8_units_type == 0)
15301531
{
@@ -1559,6 +1560,7 @@ void motor_temperature_max_limit(struct_menu_data *p_menu_data)
15591560
lcd_var_number.ui8_number_digits = 3;
15601561
lcd_var_number.ui8_decimal_digit = 0;
15611562
lcd_var_number.ui32_increment_step = 1;
1563+
lcd_var_number.ui8_need_update = 0;
15621564

15631565
if(p_m_l3_vars->ui8_units_type == 0)
15641566
{

Bafang_color_LCD_850C/Bafang_LCD_850C_firmware/src/pins.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,23 @@ void pins_init (void)
4747
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
4848
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
4949
GPIO_Init(LCD_BACKLIGHT__PORT, &GPIO_InitStructure);
50+
51+
GPIO_InitStructure.GPIO_Pin = USB_CHARGE__PIN;
52+
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
53+
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
54+
GPIO_Init(USB_CHARGE__PORT, &GPIO_InitStructure);
5055
}
5156

52-
void system_power (uint32_t ui32_state)
57+
void system_power(uint32_t ui32_state)
5358
{
5459
if(ui32_state)
5560
{
5661
GPIO_SetBits(SYSTEM_POWER_ON_OFF__PORT, SYSTEM_POWER_ON_OFF__PIN);
62+
GPIO_SetBits(USB_CHARGE__PORT, USB_CHARGE__PIN);
5763
}
5864
else
5965
{
6066
GPIO_ResetBits(SYSTEM_POWER_ON_OFF__PORT, SYSTEM_POWER_ON_OFF__PIN);
67+
GPIO_ResetBits(USB_CHARGE__PORT, USB_CHARGE__PIN);
6168
}
6269
}

Bafang_color_LCD_850C/Bafang_LCD_850C_firmware/src/pins.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
#define EEPROM_SPI_SDA_PIN GPIO_Pin_8
5050
#define EEPROM_SPI_SCL_PIN GPIO_Pin_9
5151

52+
#define USB_CHARGE__PORT GPIOA
53+
#define USB_CHARGE__PIN GPIO_Pin_3
54+
5255
void pins_init(void);
5356
void system_power(uint32_t ui32_state);
5457

0 commit comments

Comments
 (0)