|
|
@@ -9,10 +9,14 @@
|
|
|
#include <notification/notification_messages.h>
|
|
|
#include <furi_hal_random.h>
|
|
|
#include <furi_hal_pwm.h>
|
|
|
+#include <furi_hal_power.h>
|
|
|
|
|
|
#define SCREEN_SIZE_X 128
|
|
|
#define SCREEN_SIZE_Y 64
|
|
|
|
|
|
+// FOR J305 GEIGER TUBE
|
|
|
+#define CONVERSION_FACTOR 0.0081
|
|
|
+
|
|
|
typedef enum {
|
|
|
EventTypeInput,
|
|
|
ClockEventTypeTick,
|
|
|
@@ -28,6 +32,7 @@ typedef struct {
|
|
|
uint32_t cps, cpm;
|
|
|
uint32_t line[SCREEN_SIZE_X/2];
|
|
|
float coef;
|
|
|
+ uint8_t data;
|
|
|
} mutexStruct;
|
|
|
|
|
|
static void draw_callback(Canvas* canvas, void* ctx)
|
|
|
@@ -35,12 +40,14 @@ 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);
|
|
|
+ mutexStruct* geigerMutex = (mutexStruct*)acquire_mutex_block((ValueMutex*)ctx);
|
|
|
+ memcpy(&displayStruct, geigerMutex, sizeof(mutexStruct));
|
|
|
+ release_mutex((ValueMutex*)ctx, geigerMutex);
|
|
|
|
|
|
char buffer[32];
|
|
|
- snprintf(buffer, sizeof(buffer), "%ld cps - %ld cpm", displayStruct.cps, displayStruct.cpm);
|
|
|
+ if (displayStruct.data == 0) snprintf(buffer, sizeof(buffer), "%ld cps - %ld cpm", displayStruct.cps, displayStruct.cpm);
|
|
|
+ else if (displayStruct.data == 1) snprintf(buffer, sizeof(buffer), "%ld cps - %.2f uSv/h", displayStruct.cps, ((double)displayStruct.cpm*(double)CONVERSION_FACTOR));
|
|
|
+ else snprintf(buffer, sizeof(buffer), "%ld cps - %.2f mSv/y", displayStruct.cps, (((double)displayStruct.cpm*(double)CONVERSION_FACTOR))*(double)8.76);
|
|
|
|
|
|
for (int i=0;i<SCREEN_SIZE_X;i+=2)
|
|
|
{
|
|
|
@@ -83,20 +90,20 @@ static void gpiocallback(void* ctx) {
|
|
|
furi_message_queue_put(queue, &event, 0);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
int32_t flipper_geiger_app()
|
|
|
{
|
|
|
EventApp event;
|
|
|
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(EventApp));
|
|
|
|
|
|
furi_hal_gpio_init(&gpio_ext_pa7, GpioModeInterruptFall, GpioPullUp, GpioSpeedVeryHigh);
|
|
|
- furi_hal_pwm_start(FuriHalPwmOutputIdLptim2PA4, 5, 20);
|
|
|
+ furi_hal_pwm_start(FuriHalPwmOutputIdLptim2PA4, 5, 50);
|
|
|
|
|
|
mutexStruct mutexVal;
|
|
|
mutexVal.cps = 0;
|
|
|
mutexVal.cpm = 0;
|
|
|
for (int i=0;i<SCREEN_SIZE_X/2;i++) mutexVal.line[i] = 0;
|
|
|
mutexVal.coef = 1;
|
|
|
+ mutexVal.data = 0;
|
|
|
|
|
|
uint32_t counter = 0;
|
|
|
|
|
|
@@ -115,6 +122,9 @@ int32_t flipper_geiger_app()
|
|
|
FuriTimer* timer = furi_timer_alloc(clock_tick, FuriTimerTypePeriodic, event_queue);
|
|
|
furi_timer_start(timer, 1000);
|
|
|
|
|
|
+ // ENABLE 5V pin
|
|
|
+ furi_hal_power_enable_otg();
|
|
|
+
|
|
|
while(1)
|
|
|
{
|
|
|
FuriStatus event_status = furi_message_queue_get(event_queue, &event, FuriWaitForever);
|
|
|
@@ -132,39 +142,59 @@ int32_t flipper_geiger_app()
|
|
|
else if(event.input.key == InputKeyOk && event.input.type == InputTypeShort)
|
|
|
{
|
|
|
counter = 0;
|
|
|
- mutexStruct* lfsrMutex = (mutexStruct*)acquire_mutex_block(&state_mutex);
|
|
|
+ mutexStruct* geigerMutex = (mutexStruct*)acquire_mutex_block(&state_mutex);
|
|
|
+
|
|
|
+ geigerMutex->cps = 0;
|
|
|
+ geigerMutex->cpm = 0;
|
|
|
+ for (int i=0;i<SCREEN_SIZE_X/2;i++) geigerMutex->line[i] = 0;
|
|
|
+
|
|
|
+ screenRefresh = 1;
|
|
|
+ release_mutex(&state_mutex, geigerMutex);
|
|
|
+ }
|
|
|
+ else if((event.input.key == InputKeyLeft && event.input.type == InputTypeShort))
|
|
|
+ {
|
|
|
+ mutexStruct* geigerMutex = (mutexStruct*)acquire_mutex_block(&state_mutex);
|
|
|
|
|
|
- mutexVal.cps = 0;
|
|
|
- mutexVal.cpm = 0;
|
|
|
- for (int i=0;i<SCREEN_SIZE_X/2;i++) mutexVal.line[i] = 0;
|
|
|
+ if (geigerMutex->data != 0) geigerMutex->data--;
|
|
|
+ else geigerMutex->data = 2;
|
|
|
|
|
|
screenRefresh = 1;
|
|
|
- release_mutex(&state_mutex, lfsrMutex);
|
|
|
+ release_mutex(&state_mutex, geigerMutex);
|
|
|
+ }
|
|
|
+ else if((event.input.key == InputKeyRight && event.input.type == InputTypeShort))
|
|
|
+ {
|
|
|
+ mutexStruct* geigerMutex = (mutexStruct*)acquire_mutex_block(&state_mutex);
|
|
|
+
|
|
|
+ if (geigerMutex->data != 2) geigerMutex->data++;
|
|
|
+ else geigerMutex->data = 0;
|
|
|
+
|
|
|
+ screenRefresh = 1;
|
|
|
+ release_mutex(&state_mutex, geigerMutex);
|
|
|
}
|
|
|
}
|
|
|
else if (event.type == ClockEventTypeTick)
|
|
|
{
|
|
|
- mutexStruct* lfsrMutex = (mutexStruct*)acquire_mutex_block(&state_mutex);
|
|
|
+ mutexStruct* geigerMutex = (mutexStruct*)acquire_mutex_block(&state_mutex);
|
|
|
|
|
|
- for (int i=0;i<SCREEN_SIZE_X/2-1;i++) lfsrMutex->line[SCREEN_SIZE_X/2-1-i] = lfsrMutex->line[SCREEN_SIZE_X/2-2-i];
|
|
|
+ for (int i=0;i<SCREEN_SIZE_X/2-1;i++) geigerMutex->line[SCREEN_SIZE_X/2-1-i] = geigerMutex->line[SCREEN_SIZE_X/2-2-i];
|
|
|
|
|
|
- lfsrMutex->line[0] = counter;
|
|
|
- lfsrMutex->cps = counter;
|
|
|
+ geigerMutex->line[0] = counter;
|
|
|
+ geigerMutex->cps = counter;
|
|
|
counter = 0;
|
|
|
|
|
|
- lfsrMutex->cpm = lfsrMutex->line[0];
|
|
|
- uint32_t max = lfsrMutex->line[0];
|
|
|
+ geigerMutex->cpm = geigerMutex->line[0];
|
|
|
+ uint32_t max = geigerMutex->line[0];
|
|
|
for (int i=1;i<SCREEN_SIZE_X/2;i++)
|
|
|
{
|
|
|
- if (i < 60) lfsrMutex->cpm += lfsrMutex->line[i];
|
|
|
- if (lfsrMutex->line[i] > max) max = lfsrMutex->line[i];
|
|
|
+ if (i < 60) geigerMutex->cpm += geigerMutex->line[i];
|
|
|
+ if (geigerMutex->line[i] > max) max = geigerMutex->line[i];
|
|
|
}
|
|
|
|
|
|
- if (max > 0) lfsrMutex->coef = ((float)(SCREEN_SIZE_Y-15))/((float)max);
|
|
|
- else lfsrMutex->coef = 1;
|
|
|
+ if (max > 0) geigerMutex->coef = ((float)(SCREEN_SIZE_Y-15))/((float)max);
|
|
|
+ else geigerMutex->coef = 1;
|
|
|
|
|
|
screenRefresh = 1;
|
|
|
- release_mutex(&state_mutex, lfsrMutex);
|
|
|
+ release_mutex(&state_mutex, geigerMutex);
|
|
|
}
|
|
|
else if (event.type == EventGPIO)
|
|
|
{
|
|
|
@@ -175,6 +205,8 @@ int32_t flipper_geiger_app()
|
|
|
if (screenRefresh == 1) view_port_update(view_port);
|
|
|
}
|
|
|
|
|
|
+ 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);
|