From b428a19b9477a94fed04683ec2a9eb65ab98d211 Mon Sep 17 00:00:00 2001 From: Mau Abata Date: Fri, 29 Sep 2023 14:00:23 -0500 Subject: [PATCH] Bug corrections with encoder color, arousal bar, etc. --- include/ui/graphics.h | 1 + include/ui/ui.h | 1 + lib/eom-hal | 2 +- src/config_defs.c | 2 ++ src/main.c | 24 ++++++++++++++++++++---- src/menus/ui_settings_menu.c | 10 +++++++--- src/orgasm_control.c | 13 +++++++++++++ src/pages/edging_chart.c | 2 +- src/pages/edging_stats.c | 17 ++++++++++++++++- src/ui/graphics.c | 6 ++++++ src/ui/ui.c | 5 +++-- 11 files changed, 71 insertions(+), 12 deletions(-) diff --git a/include/ui/graphics.h b/include/ui/graphics.h index c8bf991b..6f2e96d1 100644 --- a/include/ui/graphics.h +++ b/include/ui/graphics.h @@ -27,6 +27,7 @@ typedef enum ui_icon { } ui_icon_t; uint8_t ui_draw_str_center(u8g2_t* d, uint8_t cx, uint8_t y, const char* str); +uint8_t ui_draw_str_right(u8g2_t* d, uint8_t rx, uint8_t y, const char* str); void ui_draw_button_labels( u8g2_t* d, const char* left_str, const char* mid_str, const char* right_str ); diff --git a/include/ui/ui.h b/include/ui/ui.h index 7d3af0df..3c887884 100644 --- a/include/ui/ui.h +++ b/include/ui/ui.h @@ -29,6 +29,7 @@ void ui_close_input(void); void ui_close_all(void); void ui_reset_idle_timer(void); +void ui_fade_to(uint8_t color); #ifdef __cplusplus } diff --git a/lib/eom-hal b/lib/eom-hal index d4e6f446..84f7b270 160000 --- a/lib/eom-hal +++ b/lib/eom-hal @@ -1 +1 @@ -Subproject commit d4e6f446a8709f5ea7acdec02e8fc363a454fceb +Subproject commit 84f7b27098bf7f3e02eb09c2728e50282f1ecce1 diff --git a/src/config_defs.c b/src/config_defs.c index 49cbc9c4..bfd630fd 100644 --- a/src/config_defs.c +++ b/src/config_defs.c @@ -258,6 +258,8 @@ esp_err_t config_load_from_sd(const char* path, config_t* cfg) { } esp_err_t config_save_to_sd(const char* path, config_t* cfg) { + if (eom_hal_get_sd_size_bytes() > 0) return ESP_ERR_NO_MEM; + cJSON* root = cJSON_CreateObject(); struct stat st; diff --git a/src/main.c b/src/main.c index 3fe0a40b..0a801554 100644 --- a/src/main.c +++ b/src/main.c @@ -101,9 +101,9 @@ static void accessory_driver_task(void* args) { static void main_task(void* args) { console_ready(); - vTaskDelay(3000UL / portTICK_RATE_MS); ui_open_page(&PAGE_EDGING_STATS, NULL); ui_reset_idle_timer(); + orgasm_control_set_output_mode(OC_MANUAL_CONTROL); for (;;) { loop_task(NULL); @@ -114,6 +114,8 @@ static void main_task(void* args) { } void app_main() { + TickType_t boot_tick = xTaskGetTickCount(); + eom_hal_init(); ui_init(); resetSD(); // TODO: Make this storage_init(); @@ -125,6 +127,12 @@ void app_main() { orgasm_control_init(); i18n_init(); + // Red = preboot + eom_hal_set_sensor_sensitivity(Config.sensor_sensitivity); + eom_hal_set_encoder_brightness(Config.led_brightness); + eom_hal_set_encoder_rgb(255, 0, 0); + + // Welcome Preamble printf("Maus-Tec presents: Edge-o-Matic 3000\n"); printf("Version: %s\n", EOM_VERSION); printf("EOM-HAL Version: %s\n", eom_hal_get_version()); @@ -132,9 +140,9 @@ void app_main() { // Go to the splash page: ui_open_page(&SPLASH_PAGE, NULL); - eom_hal_set_sensor_sensitivity(Config.sensor_sensitivity); - eom_hal_set_encoder_brightness(Config.led_brightness); - eom_hal_set_encoder_rgb(255, 0, 0); + // Green = prepare Networking + vTaskDelayUntil(&boot_tick, 1000UL / portTICK_PERIOD_MS); + eom_hal_set_encoder_rgb(0, 255, 0); // Initialize WiFi if (Config.wifi_on) { @@ -145,6 +153,10 @@ void app_main() { } } + // Blue = prepare Bluetooth + vTaskDelayUntil(&boot_tick, 1000UL / portTICK_PERIOD_MS); + eom_hal_set_encoder_rgb(0, 0, 255); + // Initialize Bluetooth if (Config.bt_on) { bluetooth_manager_init(); @@ -153,6 +165,10 @@ void app_main() { ui_set_icon(UI_ICON_BT, -1); } + // Final delay on encoder colors. + vTaskDelayUntil(&boot_tick, 1000UL / portTICK_PERIOD_MS); + ui_fade_to(0x00); + xTaskCreate(accessory_driver_task, "ACCESSORY", 1024 * 4, NULL, tskIDLE_PRIORITY, NULL); xTaskCreate(main_task, "MAIN", 1024 * 8, NULL, tskIDLE_PRIORITY + 1, NULL); } \ No newline at end of file diff --git a/src/menus/ui_settings_menu.c b/src/menus/ui_settings_menu.c index a1ffe9fb..dfc07ab2 100644 --- a/src/menus/ui_settings_menu.c +++ b/src/menus/ui_settings_menu.c @@ -44,9 +44,13 @@ DYNAMIC_MENU(UI_LANGUAGE_MENU, "Language", on_language_open); void on_config_save(int value, int final, UI_INPUT_ARG_TYPE arg) { if (final) { - ui_toast_blocking(_("Saving...")); - config_enqueue_save(0); - ui_toast(_("Saved!")); + if (eom_hal_get_sd_size_bytes() > 0) { + ui_toast_blocking(_("Saving...")); + config_enqueue_save(0); + ui_toast(_("Saved!")); + } else { + ui_toast(_("Temporary Change, no SD card inserted.")); + } } } diff --git a/src/orgasm_control.c b/src/orgasm_control.c index 4dfb5713..3a9f24bc 100644 --- a/src/orgasm_control.c +++ b/src/orgasm_control.c @@ -192,6 +192,13 @@ static void orgasm_control_updateArousal() { accessory_driver_broadcast_arousal(arousal_state.arousal); bluetooth_driver_broadcast_arousal(arousal_state.arousal); // websocket_driver_broadcast_arousal(arousal_state.arousal); + + // Update LED for Arousal Color + if (output_state.output_mode == OC_AUTOMAITC_CONTROL) { + float arousal_perc = orgasm_control_getArousalPercent() * 255.0f; + if (arousal_perc > 255.0f) arousal_perc = 255.0f; + eom_hal_set_encoder_rgb(arousal_perc, 255 - arousal_perc, 0); + } } } @@ -528,6 +535,12 @@ void orgasm_control_set_output_mode(orgasm_output_mode_t control) { const vibration_mode_controller_t* controller = orgasm_control_getVibrationMode(); output_state.motor_speed = controller->stop(); } + + eom_hal_set_encoder_rgb( + (control + 1) & 0x04 ? 0xFF : 0x00, + (control + 1) & 0x02 ? 0xFF : 0x00, + (control + 1) & 0x01 ? 0xFF : 0x00 + ); } void orgasm_control_pauseControl() { diff --git a/src/pages/edging_chart.c b/src/pages/edging_chart.c index 2af20d7e..53739ed8 100644 --- a/src/pages/edging_chart.c +++ b/src/pages/edging_chart.c @@ -97,7 +97,7 @@ static void on_close(void* arg) { static ui_render_flag_t on_button(eom_hal_button_t button, eom_hal_button_event_t event, void* arg) { - if (event != EOM_HAL_BUTTON_PRESS && button != EOM_HAL_BUTTON_BACK) return PASS; + if (event != EOM_HAL_BUTTON_PRESS || button != EOM_HAL_BUTTON_BACK) return PASS; ui_open_page(&PAGE_EDGING_STATS, NULL); return NORENDER; } diff --git a/src/pages/edging_stats.c b/src/pages/edging_stats.c index 03626672..db935d1c 100644 --- a/src/pages/edging_stats.c +++ b/src/pages/edging_stats.c @@ -107,6 +107,20 @@ static void _draw_status(u8g2_t* d, orgasm_output_mode_t mode) { } } +float _get_arousal_bar_max(void) { + static int last_sens_thresh = 0; + static float last_arousal_max = 0; + + // Memoize to prevent recalculating on renders. + if (Config.sensitivity_threshold != last_sens_thresh) { + last_sens_thresh = Config.sensitivity_threshold; + last_arousal_max = + pow10f(ceilf(log10f(Config.sensitivity_threshold * 1.10f) * 4.0f) / 4.0f); + } + + return last_arousal_max; +} + static void _draw_meters(u8g2_t* d, orgasm_output_mode_t mode) { if (mode == OC_MANUAL_CONTROL) { ui_draw_bar_graph(d, 10, 'S', eom_hal_get_motor_speed(), 255); @@ -116,12 +130,13 @@ static void _draw_meters(u8g2_t* d, orgasm_output_mode_t mode) { ); } + // Arousal Bar ui_draw_shaded_bar_graph_with_peak( d, EOM_DISPLAY_HEIGHT - 18, 'A', orgasm_control_getArousal(), - Config.sensitivity_threshold * 1.5, + _get_arousal_bar_max(), Config.sensitivity_threshold, state.arousal_peak ); diff --git a/src/ui/graphics.c b/src/ui/graphics.c index 11f3d8c8..495fb0bd 100644 --- a/src/ui/graphics.c +++ b/src/ui/graphics.c @@ -39,6 +39,12 @@ uint8_t ui_draw_str_center(u8g2_t* d, uint8_t cx, uint8_t y, const char* str) { return width; } +uint8_t ui_draw_str_right(u8g2_t* d, uint8_t rx, uint8_t y, const char* str) { + u8g2_uint_t width = u8g2_GetUTF8Width(d, str); + u8g2_DrawUTF8(d, rx - (width), y, str); + return width; +} + void ui_draw_shaded_rect(u8g2_t* d, uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color) { u8g2_SetDrawColor(d, color); diff --git a/src/ui/ui.c b/src/ui/ui.c index 09c11bb9..3f00cf58 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -306,7 +306,8 @@ static void render_screensaver_frame() { } } -void ui_fade_to(u8g2_t* d, uint8_t color) { +void ui_fade_to(uint8_t color) { + u8g2_t* d = eom_hal_get_display_ptr(); for (int i = 4; i > 0; i--) { ui_draw_pattern_fill(d, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, i); ui_send_buffer(); @@ -330,7 +331,7 @@ void ui_tick(void) { millis - UI.last_input_ms > ((uint32_t)Config.screen_timeout_seconds * 1000UL)) { UI.idle_state = UI_SCREENSAVER; u8g2_SetContrast(display, 0); - ui_fade_to(display, 0); + ui_fade_to(0); } if (UI.idle_state == UI_SCREENSAVER) {