mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 02:28:36 -07:00
Update apps
This commit is contained in:
207
applications/external/geiger/flipper_geiger.c
vendored
207
applications/external/geiger/flipper_geiger.c
vendored
@@ -10,6 +10,7 @@
|
||||
#include <furi_hal_random.h>
|
||||
#include <furi_hal_pwm.h>
|
||||
#include <furi_hal_power.h>
|
||||
|
||||
#include <storage/storage.h>
|
||||
#include <stream/buffered_file_stream.h>
|
||||
|
||||
@@ -35,48 +36,118 @@ typedef struct {
|
||||
typedef struct {
|
||||
FuriMutex* mutex;
|
||||
uint32_t cps, cpm;
|
||||
uint32_t line[SCREEN_SIZE_X / 2];
|
||||
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 displayStruct;
|
||||
mutexStruct* geigerMutex = ctx;
|
||||
furi_mutex_acquire(geigerMutex->mutex, FuriWaitForever);
|
||||
memcpy(&displayStruct, geigerMutex, sizeof(mutexStruct));
|
||||
furi_mutex_release(geigerMutex->mutex);
|
||||
mutexStruct* mutexVal = ctx;
|
||||
mutexStruct mutexDraw;
|
||||
furi_mutex_acquire(mutexVal->mutex, FuriWaitForever);
|
||||
memcpy(&mutexDraw, mutexVal, sizeof(mutexStruct));
|
||||
furi_mutex_release(mutexVal->mutex);
|
||||
|
||||
char buffer[32];
|
||||
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);
|
||||
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);
|
||||
|
||||
for(int i = 0; i < SCREEN_SIZE_X; i += 2) {
|
||||
float Y = SCREEN_SIZE_Y - (displayStruct.line[i / 2] * displayStruct.coef);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str_aligned(canvas, 64, 10, AlignCenter, AlignBottom, buffer);
|
||||
|
||||
canvas_draw_line(canvas, i, Y, i, SCREEN_SIZE_Y);
|
||||
canvas_draw_line(canvas, i + 1, Y, i + 1, SCREEN_SIZE_Y);
|
||||
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;
|
||||
|
||||
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 == 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);
|
||||
canvas_draw_line(canvas, i, Y, i, SCREEN_SIZE_Y);
|
||||
}
|
||||
}
|
||||
} 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");
|
||||
canvas_draw_str_aligned(canvas, 64, 40, AlignCenter, AlignBottom, "github.com/nmrr");
|
||||
}
|
||||
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str_aligned(canvas, 64, 10, AlignCenter, AlignBottom, buffer);
|
||||
}
|
||||
|
||||
static void input_callback(InputEvent* input_event, void* ctx) {
|
||||
@@ -107,8 +178,7 @@ static void gpiocallback(void* ctx) {
|
||||
furi_message_queue_put(queue, &event, 0);
|
||||
}
|
||||
|
||||
int32_t flipper_geiger_app(void* p) {
|
||||
UNUSED(p);
|
||||
int32_t flipper_geiger_app() {
|
||||
EventApp event;
|
||||
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(EventApp));
|
||||
|
||||
@@ -118,9 +188,12 @@ int32_t flipper_geiger_app(void* p) {
|
||||
mutexStruct mutexVal;
|
||||
mutexVal.cps = 0;
|
||||
mutexVal.cpm = 0;
|
||||
for(int i = 0; i < SCREEN_SIZE_X / 2; 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;
|
||||
mutexVal.newLinePosition = 0;
|
||||
mutexVal.version = 0;
|
||||
|
||||
uint32_t counter = 0;
|
||||
|
||||
@@ -131,7 +204,7 @@ int32_t flipper_geiger_app(void* p) {
|
||||
}
|
||||
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
view_port_draw_callback_set(view_port, draw_callback, &mutexVal);
|
||||
view_port_draw_callback_set(view_port, draw_callback, &mutexVal.mutex);
|
||||
view_port_input_callback_set(view_port, input_callback, event_queue);
|
||||
|
||||
furi_hal_gpio_add_int_callback(&gpio_ext_pa7, gpiocallback, event_queue);
|
||||
@@ -166,15 +239,16 @@ int32_t flipper_geiger_app(void* p) {
|
||||
|
||||
if(event_status == FuriStatusOk) {
|
||||
if(event.type == EventTypeInput) {
|
||||
if(event.input.key == InputKeyBack) {
|
||||
if(event.input.key == InputKeyBack && event.input.type == InputTypeLong) {
|
||||
break;
|
||||
} else if(event.input.key == InputKeyOk && event.input.type == InputTypeShort) {
|
||||
} 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(int i = 0; i < SCREEN_SIZE_X / 2; 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);
|
||||
@@ -215,7 +289,7 @@ int32_t flipper_geiger_app(void* p) {
|
||||
if(mutexVal.data != 0)
|
||||
mutexVal.data--;
|
||||
else
|
||||
mutexVal.data = 2;
|
||||
mutexVal.data = 5;
|
||||
|
||||
screenRefresh = 1;
|
||||
furi_mutex_release(mutexVal.mutex);
|
||||
@@ -223,35 +297,61 @@ int32_t flipper_geiger_app(void* p) {
|
||||
event.input.type == InputTypeShort)) {
|
||||
furi_mutex_acquire(mutexVal.mutex, FuriWaitForever);
|
||||
|
||||
if(mutexVal.data != 2)
|
||||
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)) {
|
||||
furi_mutex_acquire(mutexVal.mutex, FuriWaitForever);
|
||||
if(mutexVal.zoom != 0) mutexVal.zoom--;
|
||||
|
||||
screenRefresh = 1;
|
||||
furi_mutex_release(mutexVal.mutex);
|
||||
|
||||
} else if((event.input.key == InputKeyDown &&
|
||||
event.input.type == InputTypeShort)) {
|
||||
furi_mutex_acquire(mutexVal.mutex, FuriWaitForever);
|
||||
if(mutexVal.zoom != 3) mutexVal.zoom++;
|
||||
|
||||
screenRefresh = 1;
|
||||
furi_mutex_release(mutexVal.mutex);
|
||||
} 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;
|
||||
|
||||
screenRefresh = 1;
|
||||
furi_mutex_release(mutexVal.mutex);
|
||||
}
|
||||
} else if(event.type == ClockEventTypeTick) {
|
||||
furi_mutex_acquire(mutexVal.mutex, FuriWaitForever);
|
||||
|
||||
if(recordData == 1) {
|
||||
furi_string_printf(dataString, "%lu,%lu\n", epoch++, counter);
|
||||
stream_write_string(file_stream, dataString);
|
||||
}
|
||||
|
||||
for(int i = 0; i < SCREEN_SIZE_X / 2 - 1; i++)
|
||||
mutexVal.line[SCREEN_SIZE_X / 2 - 1 - i] =
|
||||
mutexVal.line[SCREEN_SIZE_X / 2 - 2 - i];
|
||||
furi_mutex_acquire(mutexVal.mutex, FuriWaitForever);
|
||||
|
||||
mutexVal.line[0] = counter;
|
||||
mutexVal.line[mutexVal.newLinePosition] = counter;
|
||||
mutexVal.cps = counter;
|
||||
counter = 0;
|
||||
|
||||
mutexVal.cpm = mutexVal.line[0];
|
||||
uint32_t max = mutexVal.line[0];
|
||||
for(int i = 1; i < SCREEN_SIZE_X / 2; i++) {
|
||||
if(i < 60) mutexVal.cpm += mutexVal.line[i];
|
||||
if(mutexVal.line[i] > max) max = mutexVal.line[i];
|
||||
mutexVal.cpm = mutexVal.line[mutexVal.newLinePosition];
|
||||
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;
|
||||
|
||||
if(i < 60) mutexVal.cpm += mutexVal.line[linePosition];
|
||||
if(mutexVal.line[linePosition] > max) max = mutexVal.line[linePosition];
|
||||
}
|
||||
|
||||
if(max > 0)
|
||||
@@ -259,6 +359,11 @@ int32_t flipper_geiger_app(void* p) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user