Skip to content

Commit

Permalink
Fixed trip calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortlund committed Nov 30, 2020
1 parent cd60514 commit 0f81aba
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 34 deletions.
Binary file modified bin/firmware.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion src/gui/mainbar/fulldash_tile/fulldash_tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ int value2angle(int arcstart, int arcstop, float minvalue, float maxvalue, float
void fulldash_speed_update(float current_speed, float warn_speed, float tiltback_speed, float top_speed)
{
if (speed_arc == NULL || speed_max_bar == NULL || speed_avg_bar == NULL || speed_label == NULL) return;
if (top_speed < tiltback_speed + 5) top_speed = tiltback_speed + 5;
if (top_speed > tiltback_speed + 5) top_speed = tiltback_speed + 5;

if (current_speed >= tiltback_speed)
{
Expand Down
63 changes: 38 additions & 25 deletions src/gui/mainbar/simpledash_tile/simpledash_tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
#include "hardware/wheelctl.h"

//task declarations
lv_task_t *sd_dash_task = nullptr;
lv_task_t *overlay_task = nullptr;

// Function declarations
static void simpledash_overlay_task(lv_task_t *overlay_task);
void simpledash_overlay_task(lv_task_t *overlay_task);
static void sd_overlay_event_cb(lv_obj_t *obj, lv_event_t event);

/*
Expand All @@ -52,7 +51,6 @@ static lv_style_t sd_arc_style;
// Arc gauges and labels
//arc background styles
//Speed
static lv_obj_t *sd_speed_arc = nullptr;
static lv_obj_t *sd_speed_label = nullptr;
static lv_style_t sd_speed_label_style;
//Battery
Expand Down Expand Up @@ -185,7 +183,7 @@ void lv_sd_speed_arc_1(void)
}
lv_label_set_text(sd_speed_label, speedstring);
lv_label_set_align(sd_speed_label, LV_LABEL_ALIGN_CENTER);
lv_obj_align(sd_speed_label, sd_speed_arc, LV_ALIGN_CENTER, 0, 8);
lv_obj_align(sd_speed_label, NULL, LV_ALIGN_CENTER, 0, 8);
//mainbar_add_slide_element(sd_speed_label);
}

Expand Down Expand Up @@ -395,6 +393,7 @@ int sd_value2angle(int arcstart, int arcstop, float minvalue, float maxvalue, fl

void simpledash_speed_update(float current_speed, float warn_speed, float tiltback_speed, float top_speed)
{
Serial.println("updating speed");
if (sd_speed_label == NULL) return;
if (current_speed >= tiltback_speed)
{
Expand All @@ -416,7 +415,7 @@ void simpledash_speed_update(float current_speed, float warn_speed, float tiltba
{
converted_speed = current_speed / 1.6;
}
if (converted_speed > 10)
if (converted_speed >= 10)
{
dtostrf(converted_speed, 2, 0, speedstring);
}
Expand All @@ -426,7 +425,7 @@ void simpledash_speed_update(float current_speed, float warn_speed, float tiltba
}
lv_label_set_text(sd_speed_label, speedstring);
lv_label_set_align(sd_speed_label, LV_LABEL_ALIGN_CENTER);
lv_obj_align(sd_speed_label, sd_speed_arc, LV_ALIGN_CENTER, 0, 8);
lv_obj_align(sd_speed_label, NULL, LV_ALIGN_CENTER, 0, 8);
}

void simpledash_batt_update(float current_battpct, float min_battpct, float max_battpct)
Expand Down Expand Up @@ -473,8 +472,10 @@ void simpledash_batt_update(float current_battpct, float min_battpct, float max_

void simpledash_current_update(float current_current, byte maxcurrent, float min_current, float max_current)
{

if (dashboard_get_config(DASHBOARD_CURRENT))
{
Serial.println("updating current");
if (sd_current_arc == NULL) return;
// Set warning and alert colour
float amps = current_current;
Expand All @@ -497,34 +498,38 @@ void simpledash_current_update(float current_current, byte maxcurrent, float min
lv_style_set_line_color(&sd_current_indic_style, LV_STATE_DEFAULT, sd_current_fg_clr);
}
lv_obj_add_style(sd_current_arc, LV_ARC_PART_INDIC, &sd_current_indic_style);

if (sd_rev_current_arc)
{
lv_arc_set_value(sd_current_arc, (maxcurrent - amps));
}
else
{
lv_arc_set_value(sd_current_arc, amps);
}
lv_arc_set_value(sd_current_arc, (maxcurrent - amps));

if (dashboard_get_config(DASHBOARD_BARS))
{
if (sd_current_max_bar ==NULL || sd_current_regen_bar == NULL) return;
int ang_max = sd_value2angle(sd_current_arc_start, sd_current_arc_end, 0, maxcurrent, max_current, sd_rev_current_arc);
Serial.println("updating current bars");
if (sd_current_max_bar == NULL || sd_current_regen_bar == NULL) return;
int ang_max = sd_value2angle(sd_current_arc_start, sd_current_arc_end, 0, maxcurrent, max_current, true);
int ang_max2 = ang_max + 3;
if (ang_max2 >= 360)
{
ang_max2 = ang_max2 - 360;
}
if (ang_max2 < 0)
{
ang_max2 = ang_max2 + 360;
}
lv_arc_set_angles(sd_current_max_bar, ang_max, ang_max2);

int ang_regen = sd_value2angle(sd_current_arc_start, sd_current_arc_end, 0, maxcurrent, min_current, sd_rev_current_arc);
int ang_regen = sd_value2angle(sd_current_arc_start, sd_current_arc_end, 0, maxcurrent, min_current, true);
int ang_regen2 = ang_regen + 3;
if (ang_regen2 >= 360)
{
ang_regen2 = ang_regen2 - 360;
}
if (ang_regen2 < 0)
{
ang_regen2 = ang_regen2 + 360;
}
lv_arc_set_angles(sd_current_regen_bar, ang_regen, ang_regen2);
Serial.println("current bars updated");
}
Serial.println("current updated");
}
}

Expand All @@ -536,16 +541,18 @@ void simpledash_overlay_update()
lv_style_set_bg_opa(&sd_overlay_style, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_obj_add_style(sd_overlay_bar, LV_OBJ_PART_MAIN, &sd_overlay_style);
lv_obj_set_hidden(sd_overlay_label, true);
Serial.println("overlay disabled");
}
else
{
lv_style_set_bg_opa(&sd_overlay_style, LV_STATE_DEFAULT, LV_OPA_30);
lv_obj_add_style(sd_overlay_bar, LV_OBJ_PART_MAIN, &sd_overlay_style);
lv_obj_set_hidden(sd_overlay_label, false);
Serial.println("overlay enabled");
}
}

static void simpledash_overlay_task(lv_task_t *overlay_task)
void simpledash_overlay_task(lv_task_t *overlay_task)
{
simpledash_overlay_update();
}
Expand All @@ -557,16 +564,22 @@ uint32_t simpledash_get_tile(void)

void simpledash_activate_cb(void)
{
overlay_task = lv_task_create(simpledash_overlay_task, 2000, LV_TASK_PRIO_LOWEST, NULL);
lv_task_ready(overlay_task);
simpledash_active = true;
wheelctl_update_values();
if (!simpledash_active) {
overlay_task = lv_task_create(simpledash_overlay_task, 2000, LV_TASK_PRIO_LOWEST, NULL);
lv_task_ready(overlay_task);
simpledash_active = true;
wheelctl_update_values();
Serial.println("overlay task created");
}
}

void simpledash_hibernate_cb(void)
{
lv_task_del(overlay_task);
simpledash_active = false;
if (simpledash_active && overlay_task != nullptr) {
lv_task_del(overlay_task);
simpledash_active = false;
Serial.println("overlay task deleted");
}
}

void simpledash_tile_reload(void)
Expand Down
20 changes: 15 additions & 5 deletions src/hardware/wheelctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void wheelctl_calc_power(float value);
void wheelctl_update_ridetime(lv_task_t *ride_tick);
void wheelctl_update_powercons( void );
void wheelctl_update_avgspeed(float value);
void wheelctl_update_watch_trip(float value);

bool shakeoff[3] = {true, true, true};
bool lightsoff = true;
Expand Down Expand Up @@ -171,6 +172,7 @@ void wheelctl_set_data(int entry, float value)
wheelctl_update_max_min(entry, value, false);
break;
case WHEELCTL_TRIP:
wheelctl_update_watch_trip(value);
wheelctl_update_avgspeed(value);
break;
case WHEELCTL_FANSTATE:
Expand All @@ -191,13 +193,21 @@ void wheelctl_update_ridetime(lv_task_t *ride_tick)
wheelctl_update_powercons();
}

void wheelctl_update_watch_trip(float value)
{
static bool last_value_set = false;
static float last_value;
if (!last_value_set || value < last_value) {
last_value = value;
last_value_set = true;
}
wheelctl_data[WHEELCTL_TRIP].max_value += (value - last_value);
last_value = value;
}

void wheelctl_update_avgspeed(float value)
{
if (newtrip) {
old_trip = value;
newtrip = false;
}
float trip_distance = value - old_trip;
float trip_distance = wheelctl_data[WHEELCTL_TRIP].max_value;
if (wheelctl_data[WHEELCTL_RIDETIME].value != 0) {
wheelctl_data[WHEELCTL_SPEED].min_value = trip_distance / (wheelctl_data[WHEELCTL_RIDETIME].value / 3600);
}
Expand Down
6 changes: 3 additions & 3 deletions src/hardware/wheelctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@
WHEELCTL_RMODE, //Wheel ride mode
WHEELCTL_BATTPCT, //Calculated percentage of remaining battery
WHEELCTL_POWER, //Wheel power output
WHEELCTL_TRIP, //Ride distance since power on
WHEELCTL_TRIP, //Value = Ride distance since wheel power on, max_value = trip1, min_value=trip2 managed by watch
WHEELCTL_UPTIME, //Time since power on in seconds
WHEELCTL_TOPSPEED, //max speed reached in kmh since power on
WHEELCTL_FANSTATE, //Internal fan run state
WHEELCTL_ALARM1, //Speed when first alarm is triggered
WHEELCTL_ALARM2, //Speed when second alarm is triggered
WHEELCTL_ALARM3, //Speed when third alarm is triggered
WHEELCTL_TILTBACK, //Speed when tiltback is triggered -required
WHEELCTL_RIDETIME, //Total time in motion since power on
WHEELCTL_POWERCONS, //Power cunsumed
WHEELCTL_RIDETIME, //Total time in motion since trip reset
WHEELCTL_POWERCONS, //Power cunsumed
WHEELCTL_ECONOMY, //Wh/km(mi)
WHEELCTL_DATA_NUM //number of data entries
};
Expand Down

0 comments on commit 0f81aba

Please sign in to comment.