Skip to content

Commit

Permalink
Solved Makefile bugs, refactoring and solving integer overflow on KT-…
Browse files Browse the repository at this point in the history
…LCD3
  • Loading branch information
leon927 committed Sep 16, 2019
1 parent d9b57e0 commit 1d1a736
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 48 deletions.
14 changes: 7 additions & 7 deletions src/controller/Makefile_linux
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ MAINSRC = $(PNAME).c
ELF_SECTIONS_TO_REMOVE = -R DATA -R INITIALIZED -R SSEG -R .debug_line -R .debug_loc -R .debug_abbrev -R .debug_info -R .debug_pubnames -R .debug_frame

# These are the sources that must be compiled to .rel files:
EXTRASRCS = \
$(SDIR)/stm8s_iwdg.c \
EXTRASRCS = \
$(SDIR)/stm8s_iwdg.c \
$(SDIR)/stm8s_itc.c \
$(SDIR)/stm8s_clk.c \
$(SDIR)/stm8s_gpio.c \
$(SDIR)/stm8s_uart2.c \
$(SDIR)/stm8s_tim1.c \
$(SDIR)/stm8s_tim2.c \
$(SDIR)/stm8s_tim2.c \
$(SDIR)/stm8s_tim3.c \
$(SDIR)/stm8s_exti.c \
$(SDIR)/stm8s_adc1.c \
Expand All @@ -63,9 +63,9 @@ ebike_app.h pins.h eeprom.h lights.h
RELS = $(EXTRASRCS:.c=.rel)

INCLUDES = -I$(IDIR) -I$(IDIR1) -I. -I../
CFLAGS = -m$(PLATFORM) -Ddouble=float --std-c99 --nolospre
CFLAGS = -m$(PLATFORM) -Ddouble=float --std-c99 --nolospre
ELF_FLAGS = --out-fmt-elf --debug
LIBS =
LIBS =

# This just provides the conventional target name "all"; it is optional
# Note: I assume you set PNAME via some means not exhibited in your original file
Expand All @@ -81,7 +81,7 @@ $(PNAME): $(MAINSRC) $(RELS)
# How to build any .rel file from its corresponding .c file
# GNU would have you use a pattern rule for this, but that's GNU-specific
%.rel: %.c $(HEADERS)
$(CC) -c $(INCLUDES) $(CFLAGS) $(ELF_FLAGS) $(LIBS) -o$< $<
$(CC) -c $(INCLUDES) $(CFLAGS) $(ELF_FLAGS) $(LIBS) -o$< $<

# Suffixes appearing in suffix rules we care about.
# Necessary because .rel is not one of the standard suffixes.
Expand Down Expand Up @@ -130,4 +130,4 @@ clean:
@rm -rf main.bin
@rm -rf *.ihx
@rm -rf *.hex
@echo "Done."
@echo "Done."
12 changes: 6 additions & 6 deletions src/controller/Makefile_windows
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ MAINSRC = $(PNAME).c
ELF_SECTIONS_TO_REMOVE = -R DATA -R INITIALIZED -R SSEG -R .debug_line -R .debug_loc -R .debug_abbrev -R .debug_info -R .debug_pubnames -R .debug_frame

# These are the sources that must be compiled to .rel files:
EXTRASRCS = \
$(SDIR)/stm8s_iwdg.c \
EXTRASRCS = \
$(SDIR)/stm8s_iwdg.c \
$(SDIR)/stm8s_itc.c \
$(SDIR)/stm8s_clk.c \
$(SDIR)/stm8s_gpio.c \
$(SDIR)/stm8s_uart2.c \
$(SDIR)/stm8s_tim1.c \
$(SDIR)/stm8s_tim2.c \
$(SDIR)/stm8s_tim2.c \
$(SDIR)/stm8s_tim3.c \
$(SDIR)/stm8s_exti.c \
$(SDIR)/stm8s_adc1.c \
Expand All @@ -63,9 +63,9 @@ ebike_app.h pins.h eeprom.h lights.h
RELS = $(EXTRASRCS:.c=.rel)

INCLUDES = -I$(IDIR) -I$(IDIR1) -I. -I../
CFLAGS = -m$(PLATFORM) -Ddouble=float --std-c99 --nolospre
CFLAGS = -m$(PLATFORM) -Ddouble=float --std-c99 --nolospre
ELF_FLAGS = --out-fmt-ihx --debug
LIBS =
LIBS =

# This just provides the conventional target name "all"; it is optional
# Note: I assume you set PNAME via some means not exhibited in your original file
Expand Down Expand Up @@ -96,4 +96,4 @@ hex:
clean:
@echo "Cleaning files..."
@cmd /C clean.bat
@echo "Done."
@echo "Done."
12 changes: 6 additions & 6 deletions src/display/KT-LCD3/Makefile_linux
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ MAINSRC = $(PNAME).c
ELF_SECTIONS_TO_REMOVE = -R DATA -R INITIALIZED -R SSEG -R .debug_line -R .debug_loc -R .debug_abbrev -R .debug_info -R .debug_pubnames -R .debug_frame

# These are the sources that must be compiled to .rel files:
EXTRASRCS = \
$(SDIR)/stm8s_iwdg.c \
EXTRASRCS = \
$(SDIR)/stm8s_iwdg.c \
$(SDIR)/stm8s_clk.c \
$(SDIR)/stm8s_gpio.c \
$(SDIR)/stm8s_adc1.c \
$(SDIR)/stm8s_tim1.c \
$(SDIR)/stm8s_tim3.c \
$(SDIR)/stm8s_uart2.c \
$(SDIR)/stm8s_flash.c \
$(SDIR1)/common.c \
$(SDIR1)/common.c \
gpio.c \
ht162.c \
adc.c \
Expand All @@ -54,9 +54,9 @@ HEADERS = gpio.h main.h adc.h timers.h lcd.h uart.h eeprom.h ht162.h buttons.h p
RELS = $(EXTRASRCS:.c=.rel)

INCLUDES = -I$(IDIR) -I$(IDIR1) -I. -I../../
CFLAGS = -m$(PLATFORM) -Ddouble=float --std-c99 --nolospre --opt-code-size
CFLAGS = -m$(PLATFORM) -Ddouble=float --std-c99 --nolospre --opt-code-size
ELF_FLAGS = --out-fmt-elf --debug
LIBS =
LIBS =

# This just provides the conventional target name "all"; it is optional
# Note: I assume you set PNAME via some means not exhibited in your original file
Expand Down Expand Up @@ -121,4 +121,4 @@ clean:
@rm -rf main.bin
@rm -rf *.ihx
@rm -rf *.hex
@echo "Done."
@echo "Done."
8 changes: 4 additions & 4 deletions src/display/KT-LCD3/Makefile_windows
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ MAINSRC = $(PNAME).c
ELF_SECTIONS_TO_REMOVE = -R DATA -R INITIALIZED -R SSEG -R .debug_line -R .debug_loc -R .debug_abbrev -R .debug_info -R .debug_pubnames -R .debug_frame

# These are the sources that must be compiled to .rel files:
EXTRASRCS = \
$(SDIR)/stm8s_iwdg.c \
EXTRASRCS = \
$(SDIR)/stm8s_iwdg.c \
$(SDIR)/stm8s_clk.c \
$(SDIR)/stm8s_gpio.c \
$(SDIR)/stm8s_adc1.c \
Expand All @@ -54,9 +54,9 @@ HEADERS = gpio.h main.h adc.h timers.h lcd.h uart.h eeprom.h ht162.h buttons.h p
RELS = $(EXTRASRCS:.c=.rel)

INCLUDES = -I$(IDIR) -I$(IDIR1) -I. -I../../
CFLAGS = -m$(PLATFORM) -Ddouble=float --std-c99 --nolospre
CFLAGS = -m$(PLATFORM) -Ddouble=float --std-c99 --nolospre
ELF_FLAGS = --out-fmt-ihx --debug
LIBS =
LIBS =

# This just provides the conventional target name "all"; it is optional
# Note: I assume you set PNAME via some means not exhibited in your original file
Expand Down
43 changes: 18 additions & 25 deletions src/display/KT-LCD3/lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ static uint16_t ui16_estimated_range_since_power_on_x10 = 0;


// wheel measurement variables
static uint8_t ui8_average_measured_wheel_speed_x10 = 0;
static uint8_t ui8_max_measured_wheel_speed_x10 = 0;
static uint16_t ui16_average_measured_wheel_speed_x10 = 0;
static uint16_t ui16_max_measured_wheel_speed_x10 = 0;


// system functions
Expand Down Expand Up @@ -753,8 +753,8 @@ void lcd_execute_menu_config_submenu_basic_setup(void)
lcd_set_backlight_intensity(configuration_variables.ui8_lcd_backlight_off_brightness);

break;


case 8:

// backlight night time brightness
Expand Down Expand Up @@ -2036,12 +2036,12 @@ void temperature_field(void)
if (configuration_variables.ui8_units_type)
{
// imperial
lcd_print (((float) ui8_average_measured_wheel_speed_x10/16), TEMPERATURE_FIELD, 1);
lcd_print (((float) ui16_average_measured_wheel_speed_x10/16), TEMPERATURE_FIELD, 1);
}
else
{
// metric
lcd_print (ui8_average_measured_wheel_speed_x10/10, TEMPERATURE_FIELD, 1);
lcd_print (ui16_average_measured_wheel_speed_x10/10, TEMPERATURE_FIELD, 1);
}
break;

Expand Down Expand Up @@ -3034,12 +3034,12 @@ void odometer_field(void)
if (configuration_variables.ui8_units_type)
{
// imperial
lcd_print(((float) ui8_average_measured_wheel_speed_x10 / 1.6), ODOMETER_FIELD, 1);
lcd_print(((float) ui16_average_measured_wheel_speed_x10 / 1.6), ODOMETER_FIELD, 1);
}
else
{
// metric
lcd_print(ui8_average_measured_wheel_speed_x10, ODOMETER_FIELD, 1);
lcd_print(ui16_average_measured_wheel_speed_x10, ODOMETER_FIELD, 1);
}
break;

Expand All @@ -3056,18 +3056,18 @@ void odometer_field(void)
if (configuration_variables.ui8_units_type)
{
// imperial
lcd_print(((float) ui8_max_measured_wheel_speed_x10 / 1.6), ODOMETER_FIELD, 1);
lcd_print((float) ui16_max_measured_wheel_speed_x10 / 1.6, ODOMETER_FIELD, 1);
}
else
{
// metric
lcd_print(ui8_max_measured_wheel_speed_x10, ODOMETER_FIELD, 1);
lcd_print(ui16_max_measured_wheel_speed_x10, ODOMETER_FIELD, 1);
}
break;

// reset maximum measured wheel speed since power on
case 1:
ui8_max_measured_wheel_speed_x10 = 0;
ui16_max_measured_wheel_speed_x10 = 0;
break;

// display nothing
Expand Down Expand Up @@ -3152,21 +3152,14 @@ void odometer_field(void)
void wheel_speed_field(void)
{
// check if wheel speed is higher than maximum measured wheel speed
if (motor_controller_data.ui16_wheel_speed_x10 > ui8_max_measured_wheel_speed_x10)
if (motor_controller_data.ui16_wheel_speed_x10 > ui16_max_measured_wheel_speed_x10)
{
// wheel speed is higher than maximum measured wheel speed so update variable
ui8_max_measured_wheel_speed_x10 = motor_controller_data.ui16_wheel_speed_x10;
ui16_max_measured_wheel_speed_x10 = motor_controller_data.ui16_wheel_speed_x10;
}

// calculate average wheel speed since power on in km/s
float average_measured_wheel_speed_x10_temp = (float) configuration_variables.ui16_distance_since_power_on_x10 / (float) ui16_seconds_since_power_on;

// convert to km/h
average_measured_wheel_speed_x10_temp = average_measured_wheel_speed_x10_temp * 3600;

// set calculated value to average wheel speed variable
ui8_average_measured_wheel_speed_x10 = average_measured_wheel_speed_x10_temp;

ui16_average_measured_wheel_speed_x10 = ((uint32_t) configuration_variables.ui16_distance_since_power_on_x10 * 3600) / ui16_seconds_since_power_on;

// show wheel speed only when we should not show odometer field number
if (ui8_start_odometer_show_field_number == 0)
Expand Down Expand Up @@ -3194,12 +3187,12 @@ void wheel_speed_field(void)

if (configuration_variables.ui8_units_type)
{
lcd_print(((float) ui8_average_measured_wheel_speed_x10 / 1.6), WHEEL_SPEED_FIELD, 1);
lcd_print(((float) ui16_average_measured_wheel_speed_x10 / 1.6), WHEEL_SPEED_FIELD, 1);
lcd_enable_mph_symbol(1);
}
else
{
lcd_print(ui8_average_measured_wheel_speed_x10, WHEEL_SPEED_FIELD, 1);
lcd_print(ui16_average_measured_wheel_speed_x10, WHEEL_SPEED_FIELD, 1);
lcd_enable_kmh_symbol(1);
}

Expand All @@ -3212,12 +3205,12 @@ void wheel_speed_field(void)

if (configuration_variables.ui8_units_type)
{
lcd_print(((float) ui8_max_measured_wheel_speed_x10 / 1.6), WHEEL_SPEED_FIELD, 1);
lcd_print(((float) ui16_max_measured_wheel_speed_x10 / 1.6), WHEEL_SPEED_FIELD, 1);
lcd_enable_mph_symbol(1);
}
else
{
lcd_print(ui8_max_measured_wheel_speed_x10, WHEEL_SPEED_FIELD, 1);
lcd_print(ui16_max_measured_wheel_speed_x10, WHEEL_SPEED_FIELD, 1);
lcd_enable_kmh_symbol(1);
}

Expand Down

0 comments on commit 1d1a736

Please sign in to comment.