// CC0 1.0 Universal (CC0 1.0) // Public Domain Dedication // https://github.com/nmrr #include #include #include #include #include #include #include #define SCREEN_SIZE_X 128 #define SCREEN_SIZE_Y 64 typedef enum { EventTypeInput, ClockEventTypeTick, EventGPIO, } EventType; typedef struct { EventType type; InputEvent input; } EventApp; typedef struct { uint32_t cps, cpm; uint32_t line[SCREEN_SIZE_X/2]; float coef; } mutexStruct; static void draw_callback(Canvas* canvas, void* ctx) { UNUSED(ctx); mutexStruct displayStruct; mutexStruct* lfsrMutex = (mutexStruct*)acquire_mutex_block((ValueMutex*)ctx); memcpy(&displayStruct, lfsrMutex, sizeof(mutexStruct)); release_mutex((ValueMutex*)ctx, lfsrMutex); char buffer[32]; snprintf(buffer, sizeof(buffer), "%ld cps - %ld cpm", displayStruct.cps, displayStruct.cpm); for (int i=0;iline[SCREEN_SIZE_X/2-1-i] = lfsrMutex->line[SCREEN_SIZE_X/2-2-i]; lfsrMutex->line[0] = counter; lfsrMutex->cps = counter; counter = 0; lfsrMutex->cpm = lfsrMutex->line[0]; uint32_t max = lfsrMutex->line[0]; for (int i=1;icpm += lfsrMutex->line[i]; if (lfsrMutex->line[i] > max) max = lfsrMutex->line[i]; } if (max > 0) lfsrMutex->coef = ((float)(SCREEN_SIZE_Y-15))/((float)max); else lfsrMutex->coef = 1; screenRefresh = 1; release_mutex(&state_mutex, lfsrMutex); } else if (event.type == EventGPIO) { counter++; } } if (screenRefresh == 1) view_port_update(view_port); } furi_hal_gpio_disable_int_callback(&gpio_ext_pa7); furi_hal_gpio_remove_int_callback(&gpio_ext_pa7); furi_hal_pwm_stop(FuriHalPwmOutputIdLptim2PA4); furi_message_queue_free(event_queue); delete_mutex(&state_mutex); gui_remove_view_port(gui, view_port); view_port_free(view_port); furi_timer_free(timer); furi_record_close(RECORD_GUI); return 0; }