From 6ee86367e93bf2553ca2bc11a8bb6c5885f91b4a Mon Sep 17 00:00:00 2001 From: Mau Abata Date: Tue, 26 Mar 2024 11:58:26 -0500 Subject: [PATCH] Move denial counter to edging_stats state. --- include/orgasm_control.h | 1 - src/menus/edging_mode_menu.c | 11 +++++++++++ src/orgasm_control.c | 8 +------- src/pages/edging_stats.c | 31 +++++++++++++++++++++++++++---- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/include/orgasm_control.h b/include/orgasm_control.h index 96da3ac4..4cfda304 100644 --- a/include/orgasm_control.h +++ b/include/orgasm_control.h @@ -36,7 +36,6 @@ uint16_t orgasm_control_getLastPressure(void); uint16_t orgasm_control_getAveragePressure(void); oc_bool_t orgasm_control_updated(void); void orgasm_control_clear_update_flag(void); -int orgasm_control_getDenialCount(void); void orgasm_control_increment_arousal_threshold(int threshold); void orgasm_control_set_arousal_threshold(int threshold); int orgasm_control_get_arousal_threshold(void); diff --git a/src/menus/edging_mode_menu.c b/src/menus/edging_mode_menu.c index 0cdeffa4..299c8442 100644 --- a/src/menus/edging_mode_menu.c +++ b/src/menus/edging_mode_menu.c @@ -2,9 +2,12 @@ #include "orgasm_control.h" #include "ui/menu.h" #include "ui/page.h" +#include "ui/toast.h" #include "ui/ui.h" #include "util/i18n.h" +extern void edging_stats_page_reset_denial_count(void); + static void on_start_recording(const ui_menu_t* m, const ui_menu_item_t* item, UI_MENU_ARG_TYPE arg) { orgasm_control_startRecording(); @@ -17,6 +20,12 @@ on_stop_recording(const ui_menu_t* m, const ui_menu_item_t* item, UI_MENU_ARG_TY ui_reenter_menu(); } +static void +on_reset_denial_count(const ui_menu_t* m, const ui_menu_item_t* item, UI_MENU_ARG_TYPE arg) { + edging_stats_page_reset_denial_count(); + ui_toast("%s", _("Denial count reset.")); +} + static void on_open(const ui_menu_t* m, UI_MENU_ARG_TYPE arg) { ui_menu_add_page(m, &EDGING_CHART_PAGE); @@ -26,6 +35,8 @@ static void on_open(const ui_menu_t* m, UI_MENU_ARG_TYPE arg) { ui_menu_add_item(m, _("Start Recording"), on_start_recording, NULL); } + ui_menu_add_item(m, _("Reset Denial Count"), on_reset_denial_count, NULL); + #ifdef EOM_BETA ui_menu_add_item(m, _("Set Time Limit"), NULL, NULL); ui_menu_add_item(m, _("Set Edge Goal"), NULL, NULL); diff --git a/src/orgasm_control.c b/src/orgasm_control.c index d3fbdb14..6d73d36a 100644 --- a/src/orgasm_control.c +++ b/src/orgasm_control.c @@ -32,7 +32,6 @@ static struct { uint16_t peak_start; uint16_t arousal; uint8_t update_flag; - uint8_t denial_count; } arousal_state; static struct { @@ -255,10 +254,9 @@ static void orgasm_control_updateMotorSpeed() { output_state.motor_speed = controller->stop(); output_state.motor_stop_time = (esp_timer_get_time() / 1000UL); output_state.motor_start_time = 0; - arousal_state.denial_count++; arousal_state.update_flag = ocTRUE; - event_manager_dispatch(EVT_ORGASM_DENIAL, NULL, arousal_state.denial_count); + event_manager_dispatch(EVT_ORGASM_DENIAL, NULL, 0); // If Max Additional Delay is not disabled, caculate a new delay every time the motor is // stopped. @@ -512,10 +510,6 @@ void orgasm_control_clear_update_flag(void) { arousal_state.update_flag = ocFALSE; } -int orgasm_control_getDenialCount() { - return arousal_state.denial_count; -} - /** * Returns a normalized motor speed from 0..255 * @return normalized motor speed byte diff --git a/src/pages/edging_stats.c b/src/pages/edging_stats.c index 4355d76b..f0be97ee 100644 --- a/src/pages/edging_stats.c +++ b/src/pages/edging_stats.c @@ -16,13 +16,26 @@ static const char* TAG = "page:edging_stats"; -static struct { +volatile static struct { uint16_t arousal_peak; uint64_t arousal_peak_last_ms; uint64_t arousal_peak_update_ms; uint64_t speed_change_notice_ms; uint64_t arousal_change_notice_ms; -} state; + uint8_t denial_count; + event_handler_node_t* _h_denial; +} state = { 0 }; + +static void _evt_orgasm_denial( + const char* evt, EVENT_HANDLER_ARG_TYPE eap, int eai, EVENT_HANDLER_ARG_TYPE hap +) { + state.denial_count += 1; +} + +// This is exposed for external linkage. +void edging_stats_page_reset_denial_count(void) { + state.denial_count = 0; +} static void on_open(void* arg) { // ui_toast_multiline( @@ -36,6 +49,17 @@ static void on_open(void* arg) { // little pile of " "secrets. But enough talk... Have at you!\n\n" "Belmont: // alsdjf;lskdfj;alskdjf;laskdjf;alskdjf;alksdjflsdkf <3" // ); + + // Register the orgasm denial counter, and keep it registered. It'll keep ticking while we're in + // this page, until we can find a way to allow the edging_chart and edging_stats page to + // maintain a shared state between them. + // + // This requires a notion of page state, probably, which would be nice. + // + if (state._h_denial == NULL) { + state._h_denial = + event_manager_register_handler(EVT_ORGASM_DENIAL, &_evt_orgasm_denial, NULL); + } } static ui_render_flag_t on_loop(void* arg) { @@ -224,12 +248,11 @@ static void _draw_pressure_icon(u8g2_t* d) { } static void _draw_denial_count(u8g2_t* d) { - int denial = orgasm_control_getDenialCount(); const uint8_t MID_HEIGHT = 20; const uint8_t DENIAL_WIDTH = 41; char denial_str[4]; - snprintf(denial_str, 4, "%03d", denial); + snprintf(denial_str, 4, "%03d", state.denial_count); u8g2_SetDrawColor(d, 1); u8g2_DrawVLine(