|
|
@@ -10,6 +10,10 @@
|
|
|
#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>
|
|
|
+
|
|
|
+#include <locale/locale.h>
|
|
|
|
|
|
#define SCREEN_SIZE_X 128
|
|
|
#define SCREEN_SIZE_Y 64
|
|
|
@@ -147,6 +151,14 @@ int32_t flipper_geiger_app(void* p) {
|
|
|
furi_delay_ms(10);
|
|
|
}
|
|
|
|
|
|
+ Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
+ Stream* file_stream = buffered_file_stream_alloc(storage);
|
|
|
+ FuriString* dataString = furi_string_alloc();
|
|
|
+ uint32_t epoch = 0;
|
|
|
+ uint8_t recordData = 0;
|
|
|
+
|
|
|
+ NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
|
|
+
|
|
|
while(1) {
|
|
|
FuriStatus event_status = furi_message_queue_get(event_queue, &event, FuriWaitForever);
|
|
|
|
|
|
@@ -166,6 +178,36 @@ int32_t flipper_geiger_app(void* p) {
|
|
|
|
|
|
screenRefresh = 1;
|
|
|
furi_mutex_release(mutexVal.mutex);
|
|
|
+ } 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);
|
|
|
+ furi_string_printf(dataString, "epoch,cps\n");
|
|
|
+ stream_write_string(file_stream, dataString);
|
|
|
+ epoch = 0;
|
|
|
+ recordData = 1;
|
|
|
+ } 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)) {
|
|
|
furi_mutex_acquire(mutexVal.mutex, FuriWaitForever);
|
|
|
@@ -192,6 +234,11 @@ int32_t flipper_geiger_app(void* p) {
|
|
|
} 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];
|
|
|
@@ -222,6 +269,16 @@ int32_t flipper_geiger_app(void* p) {
|
|
|
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();
|
|
|
@@ -230,6 +287,7 @@ int32_t flipper_geiger_app(void* p) {
|
|
|
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);
|