|
|
@@ -46,8 +46,7 @@ typedef struct {
|
|
|
uint8_t version;
|
|
|
} mutexStruct;
|
|
|
|
|
|
-static void draw_callback(Canvas* canvas, void* ctx)
|
|
|
-{
|
|
|
+static void draw_callback(Canvas* canvas, void* ctx) {
|
|
|
furi_assert(ctx);
|
|
|
|
|
|
mutexStruct* mutexVal = ctx;
|
|
|
@@ -56,68 +55,96 @@ static void draw_callback(Canvas* canvas, void* ctx)
|
|
|
memcpy(&mutexDraw, mutexVal, sizeof(mutexStruct));
|
|
|
furi_mutex_release(mutexVal->mutex);
|
|
|
|
|
|
- if (mutexDraw.version == 0)
|
|
|
- {
|
|
|
+ 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);
|
|
|
+ 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<SCREEN_SIZE_X;i+=8)
|
|
|
- {
|
|
|
- if (linePosition != 0) linePosition--;
|
|
|
- else linePosition = SCREEN_SIZE_X - 1;
|
|
|
+ if(mutexDraw.zoom == 0) {
|
|
|
+ for(int i = 0; i < SCREEN_SIZE_X; i += 8) {
|
|
|
+ if(linePosition != 0)
|
|
|
+ linePosition--;
|
|
|
+ else
|
|
|
+ linePosition = SCREEN_SIZE_X - 1;
|
|
|
|
|
|
- float Y = SCREEN_SIZE_Y-(mutexDraw.line[linePosition]*mutexDraw.coef);
|
|
|
- for (int j=0;j<8;j++)canvas_draw_line(canvas, i+j, Y, i+j, SCREEN_SIZE_Y);
|
|
|
+ float Y = SCREEN_SIZE_Y - (mutexDraw.line[linePosition] * mutexDraw.coef);
|
|
|
+ for(int j = 0; j < 8; j++)
|
|
|
+ canvas_draw_line(canvas, i + j, Y, i + j, SCREEN_SIZE_Y);
|
|
|
}
|
|
|
- }
|
|
|
- else if (mutexDraw.zoom == 1)
|
|
|
- {
|
|
|
- for (int i=0;i<SCREEN_SIZE_X;i+=4)
|
|
|
- {
|
|
|
- if (linePosition != 0) linePosition--;
|
|
|
- else linePosition = SCREEN_SIZE_X - 1;
|
|
|
-
|
|
|
- float Y = SCREEN_SIZE_Y-(mutexDraw.line[linePosition]*mutexDraw.coef);
|
|
|
- for (int j=0;j<4;j++)canvas_draw_line(canvas, i+j, Y, i+j, SCREEN_SIZE_Y);
|
|
|
+ } else if(mutexDraw.zoom == 1) {
|
|
|
+ for(int i = 0; i < SCREEN_SIZE_X; i += 4) {
|
|
|
+ if(linePosition != 0)
|
|
|
+ linePosition--;
|
|
|
+ else
|
|
|
+ linePosition = SCREEN_SIZE_X - 1;
|
|
|
+
|
|
|
+ float Y = SCREEN_SIZE_Y - (mutexDraw.line[linePosition] * mutexDraw.coef);
|
|
|
+ for(int j = 0; j < 4; j++)
|
|
|
+ canvas_draw_line(canvas, i + j, Y, i + j, SCREEN_SIZE_Y);
|
|
|
}
|
|
|
- }
|
|
|
- else if (mutexDraw.zoom == 2)
|
|
|
- {
|
|
|
- for (int i=0;i<SCREEN_SIZE_X;i+=2)
|
|
|
- {
|
|
|
- if (linePosition != 0) linePosition--;
|
|
|
- else linePosition = SCREEN_SIZE_X - 1;
|
|
|
-
|
|
|
- float Y = SCREEN_SIZE_Y-(mutexDraw.line[linePosition]*mutexDraw.coef);
|
|
|
- for (int j=0;j<2;j++)canvas_draw_line(canvas, i+j, Y, i+j, SCREEN_SIZE_Y);
|
|
|
+ } else if(mutexDraw.zoom == 2) {
|
|
|
+ for(int i = 0; i < SCREEN_SIZE_X; i += 2) {
|
|
|
+ if(linePosition != 0)
|
|
|
+ linePosition--;
|
|
|
+ else
|
|
|
+ linePosition = SCREEN_SIZE_X - 1;
|
|
|
+
|
|
|
+ float Y = SCREEN_SIZE_Y - (mutexDraw.line[linePosition] * mutexDraw.coef);
|
|
|
+ for(int j = 0; j < 2; j++)
|
|
|
+ canvas_draw_line(canvas, i + j, Y, i + j, SCREEN_SIZE_Y);
|
|
|
}
|
|
|
- }
|
|
|
- else if (mutexDraw.zoom == 3)
|
|
|
- {
|
|
|
- for (int i=0;i<SCREEN_SIZE_X;i++)
|
|
|
- {
|
|
|
- if (linePosition != 0) linePosition--;
|
|
|
- else linePosition = SCREEN_SIZE_X - 1;
|
|
|
-
|
|
|
- float Y = SCREEN_SIZE_Y-(mutexDraw.line[linePosition]*mutexDraw.coef);
|
|
|
+ } else if(mutexDraw.zoom == 3) {
|
|
|
+ for(int i = 0; i < SCREEN_SIZE_X; i++) {
|
|
|
+ if(linePosition != 0)
|
|
|
+ linePosition--;
|
|
|
+ else
|
|
|
+ linePosition = SCREEN_SIZE_X - 1;
|
|
|
+
|
|
|
+ float Y = SCREEN_SIZE_Y - (mutexDraw.line[linePosition] * mutexDraw.coef);
|
|
|
canvas_draw_line(canvas, i, Y, i, SCREEN_SIZE_Y);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
canvas_set_font(canvas, FontPrimary);
|
|
|
canvas_draw_str_aligned(canvas, 64, 10, AlignCenter, AlignBottom, "Geiger Counter");
|
|
|
canvas_draw_str_aligned(canvas, 64, 20, AlignCenter, AlignBottom, "Version 20230806");
|
|
|
@@ -125,8 +152,7 @@ static void draw_callback(Canvas* canvas, void* ctx)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static void input_callback(InputEvent* input_event, void* ctx)
|
|
|
-{
|
|
|
+static void input_callback(InputEvent* input_event, void* ctx) {
|
|
|
furi_assert(ctx);
|
|
|
FuriMessageQueue* event_queue = ctx;
|
|
|
EventApp event = {.type = EventTypeInput, .input = *input_event};
|
|
|
@@ -138,7 +164,7 @@ static void clock_tick(void* ctx) {
|
|
|
|
|
|
uint32_t randomNumber = furi_hal_random_get();
|
|
|
randomNumber &= 0xFFF;
|
|
|
- if (randomNumber == 0) randomNumber = 1;
|
|
|
+ if(randomNumber == 0) randomNumber = 1;
|
|
|
|
|
|
furi_hal_pwm_set_params(FuriHalPwmOutputIdLptim2PA4, randomNumber, 50);
|
|
|
|
|
|
@@ -154,8 +180,10 @@ static void gpiocallback(void* ctx) {
|
|
|
furi_message_queue_put(queue, &event, 0);
|
|
|
}
|
|
|
|
|
|
-int32_t flipper_geiger_app()
|
|
|
-{
|
|
|
+int32_t flipper_geiger_app() {
|
|
|
+ Expansion* expansion = furi_record_open(RECORD_EXPANSION);
|
|
|
+ expansion_disable(expansion);
|
|
|
+
|
|
|
EventApp event;
|
|
|
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(EventApp));
|
|
|
|
|
|
@@ -165,7 +193,7 @@ int32_t flipper_geiger_app()
|
|
|
mutexStruct mutexVal;
|
|
|
mutexVal.cps = 0;
|
|
|
mutexVal.cpm = 0;
|
|
|
- for (int i=0;i<SCREEN_SIZE_X;i++) mutexVal.line[i] = 0;
|
|
|
+ for(int i = 0; i < SCREEN_SIZE_X; i++) mutexVal.line[i] = 0;
|
|
|
mutexVal.coef = 1;
|
|
|
mutexVal.data = 0;
|
|
|
mutexVal.zoom = 2;
|
|
|
@@ -174,7 +202,7 @@ int32_t flipper_geiger_app()
|
|
|
|
|
|
uint32_t counter = 0;
|
|
|
|
|
|
- mutexVal.mutex= furi_mutex_alloc(FuriMutexTypeNormal);
|
|
|
+ mutexVal.mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
|
|
if(!mutexVal.mutex) {
|
|
|
furi_message_queue_free(event_queue);
|
|
|
expansion_enable(expansion);
|
|
|
@@ -211,109 +239,104 @@ int32_t flipper_geiger_app()
|
|
|
|
|
|
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
|
|
|
|
|
- while(1)
|
|
|
- {
|
|
|
+ while(1) {
|
|
|
FuriStatus event_status = furi_message_queue_get(event_queue, &event, FuriWaitForever);
|
|
|
-
|
|
|
+
|
|
|
uint8_t screenRefresh = 0;
|
|
|
|
|
|
- if (event_status == FuriStatusOk)
|
|
|
- {
|
|
|
- if(event.type == EventTypeInput)
|
|
|
- {
|
|
|
- if(event.input.key == InputKeyBack && event.input.type == InputTypeLong)
|
|
|
- {
|
|
|
+ if(event_status == FuriStatusOk) {
|
|
|
+ if(event.type == EventTypeInput) {
|
|
|
+ if(event.input.key == InputKeyBack && event.input.type == InputTypeLong) {
|
|
|
break;
|
|
|
- }
|
|
|
- else if(event.input.key == InputKeyOk && event.input.type == InputTypeLong)
|
|
|
- {
|
|
|
+ } else if(event.input.key == InputKeyOk && event.input.type == InputTypeLong) {
|
|
|
counter = 0;
|
|
|
furi_mutex_acquire(mutexVal.mutex, FuriWaitForever);
|
|
|
|
|
|
mutexVal.cps = 0;
|
|
|
mutexVal.cpm = 0;
|
|
|
- for (uint8_t i=0;i<SCREEN_SIZE_X;i++) mutexVal.line[i] = 0;
|
|
|
+ for(uint8_t i = 0; i < SCREEN_SIZE_X; i++) mutexVal.line[i] = 0;
|
|
|
mutexVal.newLinePosition = 0;
|
|
|
|
|
|
screenRefresh = 1;
|
|
|
furi_mutex_release(mutexVal.mutex);
|
|
|
- }
|
|
|
- else if(event.input.key == InputKeyUp && event.input.type == InputTypeLong)
|
|
|
- {
|
|
|
- if (recordData == 0)
|
|
|
- {
|
|
|
+ } else if(event.input.key == InputKeyUp && event.input.type == InputTypeLong) {
|
|
|
+ if(recordData == 0) {
|
|
|
notification_message(notification, &sequence_set_only_red_255);
|
|
|
|
|
|
FuriHalRtcDateTime datetime;
|
|
|
furi_hal_rtc_get_datetime(&datetime);
|
|
|
|
|
|
char path[64];
|
|
|
- snprintf(path, sizeof(path), EXT_PATH("/geiger-%.4d-%.2d-%.2d--%.2d-%.2d-%.2d.csv"), datetime.year, datetime.month, datetime.day, datetime.hour, datetime.minute, datetime.second);
|
|
|
-
|
|
|
- buffered_file_stream_open(file_stream, path, FSAM_WRITE, FSOM_CREATE_ALWAYS);
|
|
|
+ snprintf(
|
|
|
+ path,
|
|
|
+ sizeof(path),
|
|
|
+ EXT_PATH("/geiger-%.4d-%.2d-%.2d--%.2d-%.2d-%.2d.csv"),
|
|
|
+ datetime.year,
|
|
|
+ datetime.month,
|
|
|
+ datetime.day,
|
|
|
+ datetime.hour,
|
|
|
+ datetime.minute,
|
|
|
+ datetime.second);
|
|
|
+
|
|
|
+ buffered_file_stream_open(
|
|
|
+ file_stream, path, FSAM_WRITE, FSOM_CREATE_ALWAYS);
|
|
|
furi_string_printf(dataString, "epoch,cps\n");
|
|
|
stream_write_string(file_stream, dataString);
|
|
|
epoch = 0;
|
|
|
recordData = 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
buffered_file_stream_close(file_stream);
|
|
|
notification_message(notification, &sequence_reset_red);
|
|
|
recordData = 0;
|
|
|
}
|
|
|
- }
|
|
|
- else if((event.input.key == InputKeyLeft && event.input.type == InputTypeShort))
|
|
|
- {
|
|
|
+ } else if((event.input.key == InputKeyLeft &&
|
|
|
+ event.input.type == InputTypeShort)) {
|
|
|
furi_mutex_acquire(mutexVal.mutex, FuriWaitForever);
|
|
|
|
|
|
- if (mutexVal.data != 0) mutexVal.data--;
|
|
|
- else mutexVal.data = 5;
|
|
|
+ if(mutexVal.data != 0)
|
|
|
+ mutexVal.data--;
|
|
|
+ else
|
|
|
+ mutexVal.data = 5;
|
|
|
|
|
|
screenRefresh = 1;
|
|
|
furi_mutex_release(mutexVal.mutex);
|
|
|
- }
|
|
|
- else if((event.input.key == InputKeyRight && event.input.type == InputTypeShort))
|
|
|
- {
|
|
|
+ } else if((event.input.key == InputKeyRight &&
|
|
|
+ event.input.type == InputTypeShort)) {
|
|
|
furi_mutex_acquire(mutexVal.mutex, FuriWaitForever);
|
|
|
|
|
|
- if (mutexVal.data != 5) mutexVal.data++;
|
|
|
- else mutexVal.data = 0;
|
|
|
+ if(mutexVal.data != 5)
|
|
|
+ mutexVal.data++;
|
|
|
+ else
|
|
|
+ mutexVal.data = 0;
|
|
|
|
|
|
screenRefresh = 1;
|
|
|
furi_mutex_release(mutexVal.mutex);
|
|
|
- }
|
|
|
- else if((event.input.key == InputKeyUp && event.input.type == InputTypeShort))
|
|
|
- {
|
|
|
+ } else if((event.input.key == InputKeyUp && event.input.type == InputTypeShort)) {
|
|
|
furi_mutex_acquire(mutexVal.mutex, FuriWaitForever);
|
|
|
- if (mutexVal.zoom != 0) mutexVal.zoom--;
|
|
|
+ if(mutexVal.zoom != 0) mutexVal.zoom--;
|
|
|
|
|
|
screenRefresh = 1;
|
|
|
furi_mutex_release(mutexVal.mutex);
|
|
|
|
|
|
- }
|
|
|
- else if((event.input.key == InputKeyDown && event.input.type == InputTypeShort))
|
|
|
- {
|
|
|
+ } else if((event.input.key == InputKeyDown &&
|
|
|
+ event.input.type == InputTypeShort)) {
|
|
|
furi_mutex_acquire(mutexVal.mutex, FuriWaitForever);
|
|
|
- if (mutexVal.zoom != 3) mutexVal.zoom++;
|
|
|
+ if(mutexVal.zoom != 3) mutexVal.zoom++;
|
|
|
|
|
|
screenRefresh = 1;
|
|
|
furi_mutex_release(mutexVal.mutex);
|
|
|
- }
|
|
|
- else if((event.input.key == InputKeyDown && event.input.type == InputTypeLong))
|
|
|
- {
|
|
|
+ } else if((event.input.key == InputKeyDown && event.input.type == InputTypeLong)) {
|
|
|
furi_mutex_acquire(mutexVal.mutex, FuriWaitForever);
|
|
|
- if (mutexVal.version == 0) mutexVal.version = 1;
|
|
|
- else mutexVal.version = 0;
|
|
|
+ if(mutexVal.version == 0)
|
|
|
+ mutexVal.version = 1;
|
|
|
+ else
|
|
|
+ mutexVal.version = 0;
|
|
|
|
|
|
screenRefresh = 1;
|
|
|
furi_mutex_release(mutexVal.mutex);
|
|
|
}
|
|
|
- }
|
|
|
- else if (event.type == ClockEventTypeTick)
|
|
|
- {
|
|
|
- if (recordData == 1)
|
|
|
- {
|
|
|
+ } else if(event.type == ClockEventTypeTick) {
|
|
|
+ if(recordData == 1) {
|
|
|
furi_string_printf(dataString, "%lu,%lu\n", epoch++, counter);
|
|
|
stream_write_string(file_stream, dataString);
|
|
|
}
|
|
|
@@ -328,35 +351,37 @@ int32_t flipper_geiger_app()
|
|
|
uint32_t max = mutexVal.line[mutexVal.newLinePosition];
|
|
|
uint8_t linePosition = mutexVal.newLinePosition;
|
|
|
|
|
|
- for (int i=1;i<SCREEN_SIZE_X;i++)
|
|
|
- {
|
|
|
- if (linePosition != 0) linePosition--;
|
|
|
- else linePosition = SCREEN_SIZE_X - 1;
|
|
|
+ for(int i = 1; i < SCREEN_SIZE_X; i++) {
|
|
|
+ if(linePosition != 0)
|
|
|
+ linePosition--;
|
|
|
+ else
|
|
|
+ linePosition = SCREEN_SIZE_X - 1;
|
|
|
|
|
|
- if (i < 60) mutexVal.cpm += mutexVal.line[linePosition];
|
|
|
- if (mutexVal.line[linePosition] > max) max = mutexVal.line[linePosition];
|
|
|
+ if(i < 60) mutexVal.cpm += mutexVal.line[linePosition];
|
|
|
+ if(mutexVal.line[linePosition] > max) max = mutexVal.line[linePosition];
|
|
|
}
|
|
|
|
|
|
- if (max > 0) mutexVal.coef = ((float)(SCREEN_SIZE_Y-15))/((float)max);
|
|
|
- else mutexVal.coef = 1;
|
|
|
+ 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;
|
|
|
+ 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)
|
|
|
- {
|
|
|
+ } else if(event.type == EventGPIO) {
|
|
|
counter++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (screenRefresh == 1) view_port_update(view_port);
|
|
|
+ if(screenRefresh == 1) view_port_update(view_port);
|
|
|
}
|
|
|
|
|
|
- if (recordData == 1)
|
|
|
- {
|
|
|
+ if(recordData == 1) {
|
|
|
buffered_file_stream_close(file_stream);
|
|
|
notification_message(notification, &sequence_reset_red);
|
|
|
}
|