Skip to content

Commit

Permalink
Merge pull request teamfinalmouse#10 from teamfinalmouse/auto-trigger…
Browse files Browse the repository at this point in the history
…-random-start
  • Loading branch information
maximevince authored Apr 29, 2024
2 parents 84a8216 + 627ff2b commit 01be21f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/gfx_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static size_t chart_point_count = 0;
static lv_coord_t chart_y_range = 0;

static lv_timer_t * trigger_timer = NULL;
static lv_timer_t * trigger_timer_turn_off = NULL;

static void chart_reset(void);

Expand Down Expand Up @@ -114,12 +115,20 @@ static void auto_trigger_clear_timer(void)
trigger_timer = NULL;
}

void auto_trigger_turn_off_callback(lv_timer_t * timer)
{
(void)timer;
xlat_auto_trigger_turn_off_action();
}

void auto_trigger_callback(lv_timer_t * timer)
{
char label[20];
size_t * count = timer->user_data;

xlat_auto_trigger_action();
trigger_timer_turn_off = lv_timer_create(auto_trigger_turn_off_callback, AUTO_TRIGGER_PRESSED_PERIOD_MS, NULL);
lv_timer_set_repeat_count(trigger_timer_turn_off, 1);

*count = (*count) - 1;
if (*count) {
Expand Down
11 changes: 10 additions & 1 deletion src/xlat.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,17 @@ enum xlat_mode xlat_get_mode(void)

void xlat_auto_trigger_action(void)
{
// random delay, such that we do not always perfectly align with USB timing
srand(xTaskGetTickCount());
int val = rand() & 0xFFF;
for (volatile int i = 0; i < val; i++) {
__NOP();
}
HAL_GPIO_WritePin(ARDUINO_D11_GPIO_Port, ARDUINO_D11_Pin, auto_trigger_level_high ? GPIO_PIN_SET : GPIO_PIN_RESET);
HAL_Delay(20);
}

void xlat_auto_trigger_turn_off_action(void)
{
HAL_GPIO_WritePin(ARDUINO_D11_GPIO_Port, ARDUINO_D11_Pin, auto_trigger_level_high ? GPIO_PIN_RESET : GPIO_PIN_SET);
}

Expand Down
2 changes: 2 additions & 0 deletions src/xlat.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "src/usb/usbh_def.h"

#define AUTO_TRIGGER_PERIOD_MS (150)
#define AUTO_TRIGGER_PRESSED_PERIOD_MS (30)

typedef struct hid_event {
USBH_HandleTypeDef *phost;
Expand Down Expand Up @@ -86,6 +87,7 @@ hid_data_location_t * xlat_get_y_location(void);
void xlat_clear_locations(void);

void xlat_auto_trigger_action(void);
void xlat_auto_trigger_turn_off_action(void);
void xlat_auto_trigger_level_set(bool high);
bool xlat_auto_trigger_level_is_high(void);

Expand Down

0 comments on commit 01be21f

Please sign in to comment.