|
|
@ -16,12 +16,6 @@ typedef struct {
|
|
|
|
InputEvent input;
|
|
|
|
InputEvent input;
|
|
|
|
} PluginEvent;
|
|
|
|
} PluginEvent;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
|
|
|
int taps;
|
|
|
|
|
|
|
|
double bpm;
|
|
|
|
|
|
|
|
uint32_t last_stamp;
|
|
|
|
|
|
|
|
uint32_t interval;
|
|
|
|
|
|
|
|
} BPMTapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//QUEUE
|
|
|
|
//QUEUE
|
|
|
|
|
|
|
|
|
|
|
@ -59,16 +53,15 @@ static void queue_add(queue *q, int value) {
|
|
|
|
tmp->next = NULL;
|
|
|
|
tmp->next = NULL;
|
|
|
|
if (q->size == q->max_size) {
|
|
|
|
if (q->size == q->max_size) {
|
|
|
|
queue_remove(q);
|
|
|
|
queue_remove(q);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if empty
|
|
|
|
|
|
|
|
if (q->rear == NULL) {
|
|
|
|
|
|
|
|
q->front = tmp;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// check if empty
|
|
|
|
q->rear->next = tmp;
|
|
|
|
if (q->rear == NULL) {
|
|
|
|
|
|
|
|
q->front = tmp;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
q->rear->next = tmp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
q->rear = tmp;
|
|
|
|
|
|
|
|
q->size++;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
q->rear = tmp;
|
|
|
|
|
|
|
|
q->size++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static float queue_avg(queue *q) {
|
|
|
|
static float queue_avg(queue *q) {
|
|
|
@ -95,6 +88,14 @@ static float queue_avg(queue *q) {
|
|
|
|
// furi_hal_rtc_get_datetime(&datetime);
|
|
|
|
// furi_hal_rtc_get_datetime(&datetime);
|
|
|
|
// return furi_hal_rtc_datetime_to_timestamp(&datetime);
|
|
|
|
// return furi_hal_rtc_datetime_to_timestamp(&datetime);
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
|
|
|
int taps;
|
|
|
|
|
|
|
|
double bpm;
|
|
|
|
|
|
|
|
uint32_t last_stamp;
|
|
|
|
|
|
|
|
uint32_t interval;
|
|
|
|
|
|
|
|
queue *tap_queue;
|
|
|
|
|
|
|
|
} BPMTapper;
|
|
|
|
|
|
|
|
|
|
|
|
static void show_hello() {
|
|
|
|
static void show_hello() {
|
|
|
|
|
|
|
|
|
|
|
@ -162,6 +163,10 @@ static void bpm_state_init(BPMTapper* const plugin_state) {
|
|
|
|
plugin_state->bpm = 120.0;
|
|
|
|
plugin_state->bpm = 120.0;
|
|
|
|
plugin_state->last_stamp = 0;
|
|
|
|
plugin_state->last_stamp = 0;
|
|
|
|
plugin_state->interval = 500;
|
|
|
|
plugin_state->interval = 500;
|
|
|
|
|
|
|
|
queue *q;
|
|
|
|
|
|
|
|
q = malloc(sizeof(queue));
|
|
|
|
|
|
|
|
init_queue(q);
|
|
|
|
|
|
|
|
plugin_state->tap_queue = q;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t bpm_tapper_app(void* p) {
|
|
|
|
int32_t bpm_tapper_app(void* p) {
|
|
|
@ -209,8 +214,10 @@ int32_t bpm_tapper_app(void* p) {
|
|
|
|
bpm_state->taps++;
|
|
|
|
bpm_state->taps++;
|
|
|
|
uint32_t new_stamp = furi_get_tick();
|
|
|
|
uint32_t new_stamp = furi_get_tick();
|
|
|
|
bpm_state->interval = new_stamp - bpm_state->last_stamp;
|
|
|
|
bpm_state->interval = new_stamp - bpm_state->last_stamp;
|
|
|
|
|
|
|
|
queue_add(bpm_state->tap_queue, bpm_state->interval);
|
|
|
|
bpm_state->last_stamp = new_stamp;
|
|
|
|
bpm_state->last_stamp = new_stamp;
|
|
|
|
float bps = 1.0 / (bpm_state->interval / 1000.0);
|
|
|
|
float avg = queue_avg(bpm_state->tap_queue);
|
|
|
|
|
|
|
|
float bps = 1.0 / (avg / 1000.0);
|
|
|
|
bpm_state->bpm = bps * 60.0;
|
|
|
|
bpm_state->bpm = bps * 60.0;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case InputKeyBack:
|
|
|
|
case InputKeyBack:
|
|
|
@ -233,7 +240,9 @@ int32_t bpm_tapper_app(void* p) {
|
|
|
|
view_port_free(view_port);
|
|
|
|
view_port_free(view_port);
|
|
|
|
furi_message_queue_free(event_queue);
|
|
|
|
furi_message_queue_free(event_queue);
|
|
|
|
delete_mutex(&state_mutex);
|
|
|
|
delete_mutex(&state_mutex);
|
|
|
|
//free(bpm_state);
|
|
|
|
queue *q = bpm_state->tap_queue;
|
|
|
|
|
|
|
|
free(q);
|
|
|
|
|
|
|
|
free(bpm_state);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|