From 0235de9a830bf3c7887a7a4d4f7ecb4dd0598ebe Mon Sep 17 00:00:00 2001 From: r3n33 Date: Fri, 17 Sep 2021 10:29:29 -0500 Subject: [PATCH 01/10] Reset idle throttle time while charging/locked --- main/main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main/main.c b/main/main.c index 8a68aea..12b0c65 100644 --- a/main/main.c +++ b/main/main.c @@ -23,7 +23,7 @@ #include "lib/haptic/haptic.h" -const char * version = "0.1.1"; +const char * version = "0.1.2"; int gyro_x, gyro_y, gyro_z; float accel_g_x, accel_g_x_delta; @@ -387,11 +387,14 @@ static void i2c_task(void *arg) } if (!gpio_usb_detect) { - // Check if throttle has been idle for more than 5 minutes - if ((xTaskGetTickCount() - startTickThrottleIdle)*portTICK_RATE_MS > 5 * 60 * 1000) + // Check if throttle has been idle for more than 10 minutes + if ((xTaskGetTickCount() - startTickThrottleIdle)*portTICK_RATE_MS > 10 * 60 * 1000) { is_throttle_idle = true; } + } else { + // OSRR is charging + startTickThrottleIdle = xTaskGetTickCount(); // Reset idle throttle time } } else { was_throttle_idle = false; @@ -400,7 +403,9 @@ static void i2c_task(void *arg) } else { + // Throttle is locked joystick_value_mapped = CENTER_JOYSTICK; //NOTE: Zero input if is_throttle_locked + startTickThrottleIdle = xTaskGetTickCount(); // Reset idle throttle time } adc_raw_battery_level = ADS1015_readADC_SingleEnded(2); From 133cf98905b74e5d24ac78f4b00c9be3f25ef327 Mon Sep 17 00:00:00 2001 From: r3n33 Date: Fri, 17 Sep 2021 16:19:51 -0500 Subject: [PATCH 02/10] Fix throttle mapping value range --- main/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/main.c b/main/main.c index 12b0c65..19aa759 100644 --- a/main/main.c +++ b/main/main.c @@ -358,7 +358,7 @@ static void i2c_task(void *arg) if (!is_throttle_locked && adc_raw_joystick != ADS1015_ERROR) { // Map throttle, checking for reversed user setting - if (my_user_settings.throttle_reverse) joystick_value_mapped = 255 - map(adc_raw_joystick, 2, 1632, 0, 255); + if (my_user_settings.throttle_reverse) joystick_value_mapped = 255 - map(adc_raw_joystick, 0, 1700, 0, 255); else joystick_value_mapped = map(adc_raw_joystick, 0, 1700, 0, 255); // On first read only From d645e1d6b27440a44f1df4770c4b4116e3e3c38a Mon Sep 17 00:00:00 2001 From: r3n33 Date: Fri, 17 Sep 2021 16:21:34 -0500 Subject: [PATCH 03/10] Update CHANGELOG --- CHANGELOG | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index fc2df40..b0f4597 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +v0.1.2 + +* Reset idle throttle timer while charging + v0.1.1 * Reassign melodies From 7d7fe1b0952172f3ecd40fb4d6fd023091733e28 Mon Sep 17 00:00:00 2001 From: r3n33 Date: Fri, 17 Sep 2021 16:50:13 -0500 Subject: [PATCH 04/10] Override pizeo disable for battery and idle alerts --- main/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main/main.c b/main/main.c index 19aa759..2670b40 100644 --- a/main/main.c +++ b/main/main.c @@ -121,12 +121,16 @@ static void piezo_test(void *arg) TickType_t startTick = xTaskGetTickCount(); TickType_t endTick, diffTick; bool was_remote_idle = false; + bool alert_low_battery = false; while (1) { // Low Battery Alert if (adc_raw_battery_level < 525 || adc_raw_battery_level == ADS1015_ERROR) //TODO: Don't hardcode 525 as minimum battery value { + alert_low_battery = true; // Override user preference to be sure alert is played melody_play(MELODY_GOTCHI_FAULT, false); //NOTE: No Haptics PLEASE + } else { + alert_low_battery = false; // Clear override } // Idle Throttle Alert if (is_throttle_idle) { @@ -158,7 +162,10 @@ static void piezo_test(void *arg) was_remote_idle = false; } - if (!my_user_settings.disable_piezo) melody_step(); + // Play melody if enabled + // or when battery is low + // or when remote is left unattended + if (!my_user_settings.disable_piezo || alert_low_battery || is_remote_idle) melody_step(); vTaskDelay(10/portTICK_PERIOD_MS); } From e8eb3c1f0a6009549f1d8ca992e92a27b0604c8c Mon Sep 17 00:00:00 2001 From: r3n33 Date: Fri, 17 Sep 2021 16:51:27 -0500 Subject: [PATCH 05/10] Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index b0f4597..e9b2072 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ v0.1.2 * Reset idle throttle timer while charging +* Low battery and idle remote alerts always play v0.1.1 From b41b284491e60ca5d6d40d603470320d97f424d2 Mon Sep 17 00:00:00 2001 From: r3n33 Date: Fri, 17 Sep 2021 20:17:53 -0500 Subject: [PATCH 06/10] Rework disabled piezo override logic --- main/main.c | 89 +++++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/main/main.c b/main/main.c index 2670b40..1f5b6c6 100644 --- a/main/main.c +++ b/main/main.c @@ -25,6 +25,8 @@ const char * version = "0.1.2"; +#define ADC_BATTERY_MIN 525 + int gyro_x, gyro_y, gyro_z; float accel_g_x, accel_g_x_delta; float accel_g_y, accel_g_y_delta; @@ -116,25 +118,23 @@ static void piezo_test(void *arg) // Initialize fade service. ledc_fade_func_install(0); - melody_play(MELODY_LOG_START, true); + if (!my_user_settings.disable_piezo) melody_play(MELODY_LOG_START, true); haptic_play(MELODY_LOG_START, true); TickType_t startTick = xTaskGetTickCount(); TickType_t endTick, diffTick; bool was_remote_idle = false; - bool alert_low_battery = false; + while (1) { // Low Battery Alert - if (adc_raw_battery_level < 525 || adc_raw_battery_level == ADS1015_ERROR) //TODO: Don't hardcode 525 as minimum battery value + if (adc_raw_battery_level < ADC_BATTERY_MIN || adc_raw_battery_level == ADS1015_ERROR) { - alert_low_battery = true; // Override user preference to be sure alert is played - melody_play(MELODY_GOTCHI_FAULT, false); + melody_play(MELODY_GOTCHI_FAULT, false); //NOTE: disregard user preference //NOTE: No Haptics PLEASE - } else { - alert_low_battery = false; // Clear override } + // Idle Throttle Alert if (is_throttle_idle) { - melody_play(MELODY_ESC_FAULT, false); + melody_play(MELODY_BLE_FAIL, false); //NOTE: disregard user preference //NOTE: No Haptics } @@ -153,7 +153,7 @@ static void piezo_test(void *arg) diffTick = endTick - startTick; if (diffTick*portTICK_RATE_MS > 5 * 60 * 1000) { - melody_play(MELODY_ESC_FAULT, false); + if (!my_user_settings.disable_piezo) melody_play(MELODY_ESC_FAULT, false); } } } @@ -165,7 +165,7 @@ static void piezo_test(void *arg) // Play melody if enabled // or when battery is low // or when remote is left unattended - if (!my_user_settings.disable_piezo || alert_low_battery || is_remote_idle) melody_step(); + melody_step(); vTaskDelay(10/portTICK_PERIOD_MS); } @@ -268,11 +268,11 @@ static void gpio_input_task(void* arg) { display_blank_now = true; // Clear display display_second_screen = false; // Request primary screen with throttle locked - melody_play(MELODY_GPS_LOST, true); + if (!my_user_settings.disable_piezo) melody_play(MELODY_GPS_LOST, true); haptic_play(MELODY_GPS_LOST, true); } else { display_blank_now = true; // Clear the display if we turn off throttle lock - melody_play(MELODY_GPS_LOCK, true); + if (!my_user_settings.disable_piezo) melody_play(MELODY_GPS_LOCK, true); haptic_play(MELODY_GPS_LOCK, true); } ESP_LOGI(__FUNCTION__, "Throttle lock is %d", is_throttle_locked); @@ -284,7 +284,7 @@ static void gpio_input_task(void* arg) // SW2 on HW v1.2 PCB } if ((ev.pin == GPIO_INPUT_IO_3) && (ev.event == BUTTON_HELD)) { - melody_play(MELODY_LOG_STOP, true); + if (!my_user_settings.disable_piezo) melody_play(MELODY_LOG_STOP, true); haptic_play(MELODY_LOG_STOP, true); ESP_LOGI(__FUNCTION__, "Setting MCU_LATCH to 0"); /// Turn Power switch LED off @@ -333,7 +333,7 @@ static void gpio_init_remote() uint16_t adc_raw_joystick; uint16_t adc_raw_joystick_2; -uint16_t adc_raw_battery_level; +uint16_t adc_raw_battery_level = ADC_BATTERY_MIN; uint16_t adc_raw_rssi; #define JOYSTICK_OFF_CENTER 7 #define CENTER_JOYSTICK 127 @@ -355,6 +355,8 @@ static void i2c_task(void *arg) bool was_throttle_idle = false; TickType_t startTickThrottleIdle = xTaskGetTickCount(); + bool was_throttle_locked = false; + ADS1015_init(); while(1) { @@ -384,35 +386,42 @@ static void i2c_task(void *arg) is_throttle_locked = true; } } - // Check if joystick is center to determine if it's in use - if (joystick_value_mapped > CENTER_JOYSTICK - JOYSTICK_OFF_CENTER && joystick_value_mapped < CENTER_JOYSTICK + JOYSTICK_OFF_CENTER) - { - if (!was_throttle_idle) - { - was_throttle_idle = true; - startTickThrottleIdle = xTaskGetTickCount(); - } - if (!gpio_usb_detect) - { - // Check if throttle has been idle for more than 10 minutes - if ((xTaskGetTickCount() - startTickThrottleIdle)*portTICK_RATE_MS > 10 * 60 * 1000) - { - is_throttle_idle = true; - } - } else { - // OSRR is charging - startTickThrottleIdle = xTaskGetTickCount(); // Reset idle throttle time - } - } else { - was_throttle_idle = false; - is_throttle_idle = false; + + // Check if throttle was locked so we can reset the idle throttle time + if (was_throttle_locked) { + was_throttle_locked = false; + startTickThrottleIdle = xTaskGetTickCount(); // Reset idle throttle time } } else { // Throttle is locked joystick_value_mapped = CENTER_JOYSTICK; //NOTE: Zero input if is_throttle_locked - startTickThrottleIdle = xTaskGetTickCount(); // Reset idle throttle time + was_throttle_locked = true; + } + + // Check if joystick is center to determine if it's in use + if (joystick_value_mapped > CENTER_JOYSTICK - JOYSTICK_OFF_CENTER && joystick_value_mapped < CENTER_JOYSTICK + JOYSTICK_OFF_CENTER) + { + if (!was_throttle_idle) + { + was_throttle_idle = true; + startTickThrottleIdle = xTaskGetTickCount(); + } + if (!gpio_usb_detect) + { + // Check if throttle has been idle for more than 10 minutes + if ((xTaskGetTickCount() - startTickThrottleIdle)*portTICK_RATE_MS > 10 * 60 * 1000) + { + is_throttle_idle = true; + } + } else { + // OSRR is charging + startTickThrottleIdle = xTaskGetTickCount(); // Reset idle throttle time + } + } else { + was_throttle_idle = false; + is_throttle_idle = false; } adc_raw_battery_level = ADS1015_readADC_SingleEnded(2); @@ -499,7 +508,7 @@ void process_packet_vesc(unsigned char *data, unsigned int len) { display_blank_now = true; display_second_screen = false; } - melody_play(MELODY_ESC_FAULT, false); + if (!my_user_settings.disable_piezo) melody_play(MELODY_ESC_FAULT, false); haptic_play(MELODY_ESC_FAULT, false); } ESP_LOGI(__FUNCTION__, "Temp ESC %f Motor %f, Current In %f Out %f, Speed %f, Voltage %f Fault %d ESCs %d", esc_telemetry.temp_mos, esc_telemetry.temp_motor, esc_telemetry.current_in, esc_telemetry.current_motor, esc_telemetry.speed, esc_telemetry.v_in, esc_telemetry.fault_code, esc_telemetry.num_vescs); @@ -723,7 +732,7 @@ static void xbee_task(void *arg) display_blank_now = true; sprintf(str_pairing_3, "Pairing was"); sprintf(str_pairing_4, "Successful"); - melody_play(MELODY_BLE_SUCCESS, true); + if (!my_user_settings.disable_piezo) melody_play(MELODY_BLE_SUCCESS, true); haptic_play(MELODY_BLE_SUCCESS, true); vTaskDelay(3000/portTICK_PERIOD_MS); // Wait a few seconds } @@ -732,7 +741,7 @@ static void xbee_task(void *arg) display_blank_now = true; sprintf(str_pairing_3, "Pairing"); sprintf(str_pairing_4, "FAILED"); - melody_play(MELODY_BLE_FAIL, true); + if (!my_user_settings.disable_piezo) melody_play(MELODY_BLE_FAIL, true); haptic_play(MELODY_BLE_FAIL, true); vTaskDelay(10000/portTICK_PERIOD_MS); } From d7b3d9c1a30935a95e64a72a4a68e3f683d2f992 Mon Sep 17 00:00:00 2001 From: r3n33 Date: Fri, 17 Sep 2021 20:19:02 -0500 Subject: [PATCH 07/10] Adjust melody for idle throttle --- main/lib/melody/melody_notes.c | 2 +- main/lib/melody/melody_notes.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main/lib/melody/melody_notes.c b/main/lib/melody/melody_notes.c index 625ac7c..988040f 100644 --- a/main/lib/melody/melody_notes.c +++ b/main/lib/melody/melody_notes.c @@ -36,7 +36,7 @@ const int melody_esc_fault[] = { const int tempo_esc_fault = 100; const int melody_ble_fail[] = { - NOTE_C2,4, NOTE_C2,4, NOTE_B2,4 + NOTE_C2,4, NOTE_C2,4, NOTE_B2,4, REST,2, REST,2, REST,2 }; const int tempo_ble_fail = 360; diff --git a/main/lib/melody/melody_notes.h b/main/lib/melody/melody_notes.h index bb2b9c0..9ca7d5c 100644 --- a/main/lib/melody/melody_notes.h +++ b/main/lib/melody/melody_notes.h @@ -113,7 +113,7 @@ extern const int melody_gotchi_fault[226]; extern const int tempo_gotchi_fault; extern const int melody_esc_fault[10]; extern const int tempo_esc_fault; -extern const int melody_ble_fail[6]; +extern const int melody_ble_fail[12]; extern const int tempo_ble_fail; extern const int melody_ble_success[6]; extern const int tempo_ble_success; From 673d6959d8b96eb882c62142eadb3b0c46781538 Mon Sep 17 00:00:00 2001 From: r3n33 Date: Fri, 17 Sep 2021 20:19:14 -0500 Subject: [PATCH 08/10] Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index e9b2072..4b1ef0f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ v0.1.2 * Reset idle throttle timer while charging * Low battery and idle remote alerts always play +* Increased idle throttle alert to 10 minutes v0.1.1 From f8f8516c4451c8c3640a61a85a8ec72fae7f44a2 Mon Sep 17 00:00:00 2001 From: r3n33 Date: Sun, 19 Sep 2021 13:24:31 -0500 Subject: [PATCH 09/10] Idle Throttle timer reset with button press --- main/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main/main.c b/main/main.c index 1f5b6c6..b575345 100644 --- a/main/main.c +++ b/main/main.c @@ -40,6 +40,7 @@ bool is_throttle_idle = false; bool is_throttle_locked = false; TickType_t esc_last_responded = 0; +TickType_t startTickThrottleIdle = 0; /* User Settings */ #include "user-settings.h" @@ -153,7 +154,7 @@ static void piezo_test(void *arg) diffTick = endTick - startTick; if (diffTick*portTICK_RATE_MS > 5 * 60 * 1000) { - if (!my_user_settings.disable_piezo) melody_play(MELODY_ESC_FAULT, false); + if (!my_user_settings.disable_piezo) melody_play(MELODY_BLE_FAIL, false); } } } @@ -220,6 +221,10 @@ static void gpio_input_task(void* arg) while (true) { if (xQueueReceive(button_events, &ev, 1000/portTICK_PERIOD_MS)) { + if ((ev.pin == GPIO_INPUT_IO_0)) { + // Reset idle throttle time with user button + startTickThrottleIdle = xTaskGetTickCount(); + } if ((ev.pin == GPIO_INPUT_IO_0) && (ev.event == BUTTON_DOWN)) { // User Button (SW3 on HW v1.2 PCB) if (remote_in_setup_mode) @@ -353,7 +358,7 @@ static void i2c_task(void *arg) float accel_res = mpu6050_get_accel_res(range); bool was_throttle_idle = false; - TickType_t startTickThrottleIdle = xTaskGetTickCount(); + startTickThrottleIdle = xTaskGetTickCount(); bool was_throttle_locked = false; @@ -414,6 +419,8 @@ static void i2c_task(void *arg) if ((xTaskGetTickCount() - startTickThrottleIdle)*portTICK_RATE_MS > 10 * 60 * 1000) { is_throttle_idle = true; + } else { + is_throttle_idle = false; } } else { // OSRR is charging From 89d9c9c2bb8d5cb624f5a789941d60adf443aaa2 Mon Sep 17 00:00:00 2001 From: r3n33 Date: Sun, 19 Sep 2021 13:38:54 -0500 Subject: [PATCH 10/10] Update CHANGELOG --- CHANGELOG | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 4b1ef0f..144cc08 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,10 @@ v0.1.2 * Reset idle throttle timer while charging -* Low battery and idle remote alerts always play +* User button resets idle throttle timer * Increased idle throttle alert to 10 minutes +* Change melody for idle remote alerts +* Low battery and idle remote alerts always play v0.1.1