Skip to content

Commit

Permalink
Merge pull request #81 from MausTec/denial-reset
Browse files Browse the repository at this point in the history
Move denial counter to edging_stats state.
  • Loading branch information
MauAbata authored Mar 27, 2024
2 parents 35ccd7f + 6ee8636 commit 4497b3e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
1 change: 0 additions & 1 deletion include/orgasm_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/menus/edging_mode_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand All @@ -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);
Expand Down
8 changes: 1 addition & 7 deletions src/orgasm_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
31 changes: 27 additions & 4 deletions src/pages/edging_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4497b3e

Please sign in to comment.