Skip to content

Commit

Permalink
Merge pull request #3 from FreeSK8/0.1.2
Browse files Browse the repository at this point in the history
v0.1.2
  • Loading branch information
r3n33 authored Sep 19, 2021
2 parents 2797b0a + 89d9c9c commit 6faf9f9
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 37 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
v0.1.2

* Reset idle throttle timer while charging
* 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

* Reassign melodies
Expand Down
2 changes: 1 addition & 1 deletion main/lib/melody/melody_notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion main/lib/melody/melody_notes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
98 changes: 63 additions & 35 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

#include "lib/haptic/haptic.h"

const char * version = "0.1.1";
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;
Expand All @@ -38,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"
Expand Down Expand Up @@ -116,21 +119,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;

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)
{
melody_play(MELODY_GOTCHI_FAULT, false);
melody_play(MELODY_GOTCHI_FAULT, false); //NOTE: disregard user preference
//NOTE: No Haptics PLEASE
}

// 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
}

Expand All @@ -149,7 +154,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_BLE_FAIL, false);
}
}
}
Expand All @@ -158,7 +163,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
melody_step();

vTaskDelay(10/portTICK_PERIOD_MS);
}
Expand Down Expand Up @@ -213,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)
Expand Down Expand Up @@ -261,11 +273,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);
Expand All @@ -277,7 +289,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
Expand Down Expand Up @@ -326,7 +338,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
Expand All @@ -346,7 +358,9 @@ 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;

ADS1015_init();
while(1)
Expand All @@ -358,7 +372,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
Expand All @@ -377,30 +391,44 @@ 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 5 minutes
if ((xTaskGetTickCount() - startTickThrottleIdle)*portTICK_RATE_MS > 5 * 60 * 1000)
{
is_throttle_idle = true;
}
}
} 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
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 {
is_throttle_idle = false;
}
} 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);
Expand Down Expand Up @@ -487,7 +515,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);
Expand Down Expand Up @@ -711,7 +739,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
}
Expand All @@ -720,7 +748,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);
}
Expand Down

0 comments on commit 6faf9f9

Please sign in to comment.