// CC0 1.0 Universal (CC0 1.0) // Public Domain Dedication // https://github.com/nmrr #include #include #include #include #include #include #include #include #include #include #include #define SCREEN_SIZE_X 128 #define SCREEN_SIZE_Y 64 // FOR J305 GEIGER TUBE #define CONVERSION_FACTOR 0.0081 typedef enum { EventTypeInput, ClockEventTypeTick, EventGPIO, } EventType; typedef struct { EventType type; InputEvent input; } EventApp; typedef struct { FuriMutex* mutex; uint32_t cps, cpm; uint32_t line[SCREEN_SIZE_X]; float coef; uint8_t data; uint8_t zoom; uint8_t newLinePosition; uint8_t version; } mutexStruct; static void draw_callback(Canvas* canvas, void* ctx) { furi_assert(ctx); mutexStruct* mutexVal = ctx; mutexStruct mutexDraw; furi_mutex_acquire(mutexVal->mutex, FuriWaitForever); memcpy(&mutexDraw, mutexVal, sizeof(mutexStruct)); furi_mutex_release(mutexVal->mutex); if (mutexDraw.version == 0) { char buffer[32]; if (mutexDraw.data == 0) snprintf(buffer, sizeof(buffer), "%ld cps - %ld cpm", mutexDraw.cps, mutexDraw.cpm); else if (mutexDraw.data == 1) snprintf(buffer, sizeof(buffer), "%ld cps - %.2f uSv/h", mutexDraw.cps, ((double)mutexDraw.cpm*(double)CONVERSION_FACTOR)); else if (mutexDraw.data == 2) snprintf(buffer, sizeof(buffer), "%ld cps - %.2f mSv/y", mutexDraw.cps, (((double)mutexDraw.cpm*(double)CONVERSION_FACTOR))*(double)8.76); else if (mutexDraw.data == 3) snprintf(buffer, sizeof(buffer), "%ld cps - %.4f Rad/h", mutexDraw.cps, ((double)mutexDraw.cpm*(double)CONVERSION_FACTOR)/(double)10000); else if (mutexDraw.data == 4) snprintf(buffer, sizeof(buffer), "%ld cps - %.2f mR/h", mutexDraw.cps, ((double)mutexDraw.cpm*(double)CONVERSION_FACTOR)/(double)10); else snprintf(buffer, sizeof(buffer), "%ld cps - %.2f uR/h", mutexDraw.cps, ((double)mutexDraw.cpm*(double)CONVERSION_FACTOR)*(double)100); canvas_set_font(canvas, FontPrimary); canvas_draw_str_aligned(canvas, 64, 10, AlignCenter, AlignBottom, buffer); uint8_t linePosition = mutexDraw.newLinePosition; if (mutexDraw.zoom == 0) { for (int i=0;i max) max = mutexVal.line[linePosition]; } if (max > 0) mutexVal.coef = ((float)(SCREEN_SIZE_Y-15))/((float)max); else mutexVal.coef = 1; if (mutexVal.newLinePosition != SCREEN_SIZE_X - 1) mutexVal.newLinePosition++; else mutexVal.newLinePosition = 0; screenRefresh = 1; furi_mutex_release(mutexVal.mutex); } else if (event.type == EventGPIO) { counter++; } } if (screenRefresh == 1) view_port_update(view_port); } if (recordData == 1) { buffered_file_stream_close(file_stream); notification_message(notification, &sequence_reset_red); } furi_string_free(dataString); furi_record_close(RECORD_NOTIFICATION); stream_free(file_stream); furi_record_close(RECORD_STORAGE); // Disable 5v power if(furi_hal_power_is_otg_enabled()) { furi_hal_power_disable_otg(); } furi_hal_gpio_disable_int_callback(&gpio_ext_pa7); furi_hal_gpio_remove_int_callback(&gpio_ext_pa7); furi_hal_pwm_stop(FuriHalPwmOutputIdLptim2PA4); furi_hal_gpio_init(&gpio_ext_pa7, GpioModeAnalog, GpioPullNo, GpioSpeedLow); furi_message_queue_free(event_queue); furi_mutex_free(mutexVal.mutex); gui_remove_view_port(gui, view_port); view_port_free(view_port); furi_timer_free(timer); furi_record_close(RECORD_GUI); return 0; }