mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 21:28:36 -07:00
fmt
This commit is contained in:
@@ -4,134 +4,130 @@
|
|||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
EventTypeTick,
|
||||||
EventTypeTick,
|
EventTypeKey,
|
||||||
EventTypeKey,
|
|
||||||
} EventType;
|
} EventType;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
EventType type;
|
||||||
EventType type;
|
InputEvent input;
|
||||||
InputEvent input;
|
|
||||||
} PluginEvent;
|
} PluginEvent;
|
||||||
|
|
||||||
static void render_callback(Canvas* const canvas, void* context)
|
static void render_callback(Canvas* const canvas, void* context) {
|
||||||
{
|
const GpsUart* gps_uart = acquire_mutex((ValueMutex*)context, 25);
|
||||||
const GpsUart* gps_uart = acquire_mutex((ValueMutex*)context, 25);
|
if(gps_uart == NULL) {
|
||||||
if (gps_uart == NULL)
|
return;
|
||||||
{
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
canvas_draw_str_aligned(canvas, 32, 8, AlignCenter, AlignBottom, "Latitude");
|
canvas_draw_str_aligned(canvas, 32, 8, AlignCenter, AlignBottom, "Latitude");
|
||||||
canvas_draw_str_aligned(canvas, 96, 8, AlignCenter, AlignBottom, "Longitude");
|
canvas_draw_str_aligned(canvas, 96, 8, AlignCenter, AlignBottom, "Longitude");
|
||||||
canvas_draw_str_aligned(canvas, 21, 30, AlignCenter, AlignBottom, "Course");
|
canvas_draw_str_aligned(canvas, 21, 30, AlignCenter, AlignBottom, "Course");
|
||||||
canvas_draw_str_aligned(canvas, 64, 30, AlignCenter, AlignBottom, "Speed");
|
canvas_draw_str_aligned(canvas, 64, 30, AlignCenter, AlignBottom, "Speed");
|
||||||
canvas_draw_str_aligned(canvas, 107, 30, AlignCenter, AlignBottom, "Altitude");
|
canvas_draw_str_aligned(canvas, 107, 30, AlignCenter, AlignBottom, "Altitude");
|
||||||
canvas_draw_str_aligned(canvas, 32, 52, AlignCenter, AlignBottom, "Satellites");
|
canvas_draw_str_aligned(canvas, 32, 52, AlignCenter, AlignBottom, "Satellites");
|
||||||
canvas_draw_str_aligned(canvas, 96, 52, AlignCenter, AlignBottom, "Last Fix");
|
canvas_draw_str_aligned(canvas, 96, 52, AlignCenter, AlignBottom, "Last Fix");
|
||||||
|
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
snprintf(buffer, 64, "%f", (double)gps_uart->status.latitude);
|
snprintf(buffer, 64, "%f", (double)gps_uart->status.latitude);
|
||||||
canvas_draw_str_aligned(canvas, 32, 18, AlignCenter, AlignBottom, buffer);
|
canvas_draw_str_aligned(canvas, 32, 18, AlignCenter, AlignBottom, buffer);
|
||||||
snprintf(buffer, 64, "%f", (double)gps_uart->status.longitude);
|
snprintf(buffer, 64, "%f", (double)gps_uart->status.longitude);
|
||||||
canvas_draw_str_aligned(canvas, 96, 18, AlignCenter, AlignBottom, buffer);
|
canvas_draw_str_aligned(canvas, 96, 18, AlignCenter, AlignBottom, buffer);
|
||||||
snprintf(buffer, 64, "%.1f", (double)gps_uart->status.course);
|
snprintf(buffer, 64, "%.1f", (double)gps_uart->status.course);
|
||||||
canvas_draw_str_aligned(canvas, 21, 40, AlignCenter, AlignBottom, buffer);
|
canvas_draw_str_aligned(canvas, 21, 40, AlignCenter, AlignBottom, buffer);
|
||||||
snprintf(buffer, 64, "%.2f kn", (double)gps_uart->status.speed);
|
snprintf(buffer, 64, "%.2f kn", (double)gps_uart->status.speed);
|
||||||
canvas_draw_str_aligned(canvas, 64, 40, AlignCenter, AlignBottom, buffer);
|
canvas_draw_str_aligned(canvas, 64, 40, AlignCenter, AlignBottom, buffer);
|
||||||
snprintf(buffer, 64, "%.1f %c", (double)gps_uart->status.altitude, tolower(gps_uart->status.altitude_units));
|
snprintf(
|
||||||
canvas_draw_str_aligned(canvas, 107, 40, AlignCenter, AlignBottom, buffer);
|
buffer,
|
||||||
snprintf(buffer, 64, "%d", gps_uart->status.satellites_tracked);
|
64,
|
||||||
canvas_draw_str_aligned(canvas, 32, 62, AlignCenter, AlignBottom, buffer);
|
"%.1f %c",
|
||||||
snprintf(buffer, 64, "%02d:%02d:%02d UTC", gps_uart->status.time_hours, gps_uart->status.time_minutes,
|
(double)gps_uart->status.altitude,
|
||||||
gps_uart->status.time_seconds);
|
tolower(gps_uart->status.altitude_units));
|
||||||
canvas_draw_str_aligned(canvas, 96, 62, AlignCenter, AlignBottom, buffer);
|
canvas_draw_str_aligned(canvas, 107, 40, AlignCenter, AlignBottom, buffer);
|
||||||
|
snprintf(buffer, 64, "%d", gps_uart->status.satellites_tracked);
|
||||||
|
canvas_draw_str_aligned(canvas, 32, 62, AlignCenter, AlignBottom, buffer);
|
||||||
|
snprintf(
|
||||||
|
buffer,
|
||||||
|
64,
|
||||||
|
"%02d:%02d:%02d UTC",
|
||||||
|
gps_uart->status.time_hours,
|
||||||
|
gps_uart->status.time_minutes,
|
||||||
|
gps_uart->status.time_seconds);
|
||||||
|
canvas_draw_str_aligned(canvas, 96, 62, AlignCenter, AlignBottom, buffer);
|
||||||
|
|
||||||
release_mutex((ValueMutex*)context, gps_uart);
|
release_mutex((ValueMutex*)context, gps_uart);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue)
|
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
|
||||||
{
|
furi_assert(event_queue);
|
||||||
furi_assert(event_queue);
|
|
||||||
|
|
||||||
PluginEvent event = {.type = EventTypeKey, .input = *input_event};
|
PluginEvent event = {.type = EventTypeKey, .input = *input_event};
|
||||||
furi_message_queue_put(event_queue, &event, FuriWaitForever);
|
furi_message_queue_put(event_queue, &event, FuriWaitForever);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t gps_app(void* p)
|
int32_t gps_app(void* p) {
|
||||||
{
|
UNUSED(p);
|
||||||
UNUSED(p);
|
|
||||||
|
|
||||||
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
|
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
|
||||||
|
|
||||||
GpsUart* gps_uart = gps_uart_enable();
|
GpsUart* gps_uart = gps_uart_enable();
|
||||||
|
|
||||||
ValueMutex gps_uart_mutex;
|
ValueMutex gps_uart_mutex;
|
||||||
if (!init_mutex(&gps_uart_mutex, gps_uart, sizeof(GpsUart)))
|
if(!init_mutex(&gps_uart_mutex, gps_uart, sizeof(GpsUart))) {
|
||||||
{
|
FURI_LOG_E("GPS", "cannot create mutex\r\n");
|
||||||
FURI_LOG_E("GPS", "cannot create mutex\r\n");
|
free(gps_uart);
|
||||||
free(gps_uart);
|
return 255;
|
||||||
return 255;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// set system callbacks
|
// set system callbacks
|
||||||
ViewPort* view_port = view_port_alloc();
|
ViewPort* view_port = view_port_alloc();
|
||||||
view_port_draw_callback_set(view_port, render_callback, &gps_uart_mutex);
|
view_port_draw_callback_set(view_port, render_callback, &gps_uart_mutex);
|
||||||
view_port_input_callback_set(view_port, input_callback, event_queue);
|
view_port_input_callback_set(view_port, input_callback, event_queue);
|
||||||
|
|
||||||
// open GUI and register view_port
|
// open GUI and register view_port
|
||||||
Gui* gui = furi_record_open("gui");
|
Gui* gui = furi_record_open("gui");
|
||||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||||
|
|
||||||
PluginEvent event;
|
PluginEvent event;
|
||||||
for (bool processing = true; processing;)
|
for(bool processing = true; processing;) {
|
||||||
{
|
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
||||||
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
|
||||||
|
|
||||||
GpsUart* gps_uart = (GpsUart*)acquire_mutex_block(&gps_uart_mutex);
|
GpsUart* gps_uart = (GpsUart*)acquire_mutex_block(&gps_uart_mutex);
|
||||||
|
|
||||||
if (event_status == FuriStatusOk)
|
if(event_status == FuriStatusOk) {
|
||||||
{
|
// press events
|
||||||
// press events
|
if(event.type == EventTypeKey) {
|
||||||
if (event.type == EventTypeKey)
|
if(event.input.type == InputTypePress) {
|
||||||
{
|
switch(event.input.key) {
|
||||||
if (event.input.type == InputTypePress)
|
case InputKeyUp:
|
||||||
{
|
case InputKeyDown:
|
||||||
switch (event.input.key)
|
case InputKeyRight:
|
||||||
{
|
case InputKeyLeft:
|
||||||
case InputKeyUp:
|
case InputKeyOk:
|
||||||
case InputKeyDown:
|
break;
|
||||||
case InputKeyRight:
|
case InputKeyBack:
|
||||||
case InputKeyLeft:
|
processing = false;
|
||||||
case InputKeyOk:
|
break;
|
||||||
break;
|
}
|
||||||
case InputKeyBack:
|
}
|
||||||
processing = false;
|
}
|
||||||
break;
|
} else {
|
||||||
}
|
FURI_LOG_D("GPS", "FuriMessageQueue: event timeout");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
view_port_update(view_port);
|
||||||
else
|
release_mutex(&gps_uart_mutex, gps_uart);
|
||||||
{
|
|
||||||
FURI_LOG_D("GPS", "FuriMessageQueue: event timeout");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
view_port_update(view_port);
|
view_port_enabled_set(view_port, false);
|
||||||
release_mutex(&gps_uart_mutex, gps_uart);
|
gui_remove_view_port(gui, view_port);
|
||||||
}
|
furi_record_close("gui");
|
||||||
|
view_port_free(view_port);
|
||||||
|
furi_message_queue_free(event_queue);
|
||||||
|
delete_mutex(&gps_uart_mutex);
|
||||||
|
gps_uart_disable(gps_uart);
|
||||||
|
|
||||||
view_port_enabled_set(view_port, false);
|
return 0;
|
||||||
gui_remove_view_port(gui, view_port);
|
|
||||||
furi_record_close("gui");
|
|
||||||
view_port_free(view_port);
|
|
||||||
furi_message_queue_free(event_queue);
|
|
||||||
delete_mutex(&gps_uart_mutex);
|
|
||||||
gps_uart_disable(gps_uart);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,194 +3,171 @@
|
|||||||
#include "minmea.h"
|
#include "minmea.h"
|
||||||
#include "gps_uart.h"
|
#include "gps_uart.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
WorkerEvtStop = (1 << 0),
|
||||||
WorkerEvtStop = (1 << 0),
|
WorkerEvtRxDone = (1 << 1),
|
||||||
WorkerEvtRxDone = (1 << 1),
|
|
||||||
} WorkerEvtFlags;
|
} WorkerEvtFlags;
|
||||||
|
|
||||||
#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
|
#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
|
||||||
|
|
||||||
static void gps_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context)
|
static void gps_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
|
||||||
{
|
GpsUart* gps_uart = (GpsUart*)context;
|
||||||
GpsUart* gps_uart = (GpsUart*)context;
|
|
||||||
|
|
||||||
if (ev == UartIrqEventRXNE)
|
if(ev == UartIrqEventRXNE) {
|
||||||
{
|
furi_stream_buffer_send(gps_uart->rx_stream, &data, 1, 0);
|
||||||
furi_stream_buffer_send(gps_uart->rx_stream, &data, 1, 0);
|
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtRxDone);
|
||||||
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtRxDone);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gps_uart_serial_init(GpsUart* gps_uart)
|
static void gps_uart_serial_init(GpsUart* gps_uart) {
|
||||||
{
|
furi_hal_console_disable();
|
||||||
furi_hal_console_disable();
|
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, gps_uart_on_irq_cb, gps_uart);
|
||||||
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, gps_uart_on_irq_cb, gps_uart);
|
furi_hal_uart_set_br(FuriHalUartIdUSART1, GPS_BAUDRATE);
|
||||||
furi_hal_uart_set_br(FuriHalUartIdUSART1, GPS_BAUDRATE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gps_uart_serial_deinit(GpsUart* gps_uart)
|
static void gps_uart_serial_deinit(GpsUart* gps_uart) {
|
||||||
{
|
UNUSED(gps_uart);
|
||||||
UNUSED(gps_uart);
|
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
|
||||||
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
|
furi_hal_console_enable();
|
||||||
furi_hal_console_enable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line)
|
static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line) {
|
||||||
{
|
switch(minmea_sentence_id(line, false)) {
|
||||||
switch (minmea_sentence_id(line, false))
|
case MINMEA_SENTENCE_RMC: {
|
||||||
{
|
struct minmea_sentence_rmc frame;
|
||||||
case MINMEA_SENTENCE_RMC:
|
if(minmea_parse_rmc(&frame, line)) {
|
||||||
{
|
gps_uart->status.valid = frame.valid;
|
||||||
struct minmea_sentence_rmc frame;
|
gps_uart->status.latitude = minmea_tocoord(&frame.latitude);
|
||||||
if (minmea_parse_rmc(&frame, line))
|
gps_uart->status.longitude = minmea_tocoord(&frame.longitude);
|
||||||
{
|
gps_uart->status.speed = minmea_tofloat(&frame.speed);
|
||||||
gps_uart->status.valid = frame.valid;
|
gps_uart->status.course = minmea_tofloat(&frame.course);
|
||||||
gps_uart->status.latitude = minmea_tocoord(&frame.latitude);
|
gps_uart->status.time_hours = frame.time.hours;
|
||||||
gps_uart->status.longitude = minmea_tocoord(&frame.longitude);
|
gps_uart->status.time_minutes = frame.time.minutes;
|
||||||
gps_uart->status.speed = minmea_tofloat(&frame.speed);
|
gps_uart->status.time_seconds = frame.time.seconds;
|
||||||
gps_uart->status.course = minmea_tofloat(&frame.course);
|
|
||||||
gps_uart->status.time_hours = frame.time.hours;
|
|
||||||
gps_uart->status.time_minutes = frame.time.minutes;
|
|
||||||
gps_uart->status.time_seconds = frame.time.seconds;
|
|
||||||
|
|
||||||
notification_message_block(gps_uart->notifications, &sequence_blink_green_10);
|
notification_message_block(gps_uart->notifications, &sequence_blink_green_10);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case MINMEA_SENTENCE_GGA:
|
case MINMEA_SENTENCE_GGA: {
|
||||||
{
|
struct minmea_sentence_gga frame;
|
||||||
struct minmea_sentence_gga frame;
|
if(minmea_parse_gga(&frame, line)) {
|
||||||
if (minmea_parse_gga(&frame, line))
|
gps_uart->status.latitude = minmea_tocoord(&frame.latitude);
|
||||||
{
|
gps_uart->status.longitude = minmea_tocoord(&frame.longitude);
|
||||||
gps_uart->status.latitude = minmea_tocoord(&frame.latitude);
|
gps_uart->status.altitude = minmea_tofloat(&frame.altitude);
|
||||||
gps_uart->status.longitude = minmea_tocoord(&frame.longitude);
|
gps_uart->status.altitude_units = frame.altitude_units;
|
||||||
gps_uart->status.altitude = minmea_tofloat(&frame.altitude);
|
gps_uart->status.fix_quality = frame.fix_quality;
|
||||||
gps_uart->status.altitude_units = frame.altitude_units;
|
gps_uart->status.satellites_tracked = frame.satellites_tracked;
|
||||||
gps_uart->status.fix_quality = frame.fix_quality;
|
gps_uart->status.time_hours = frame.time.hours;
|
||||||
gps_uart->status.satellites_tracked = frame.satellites_tracked;
|
gps_uart->status.time_minutes = frame.time.minutes;
|
||||||
gps_uart->status.time_hours = frame.time.hours;
|
gps_uart->status.time_seconds = frame.time.seconds;
|
||||||
gps_uart->status.time_minutes = frame.time.minutes;
|
|
||||||
gps_uart->status.time_seconds = frame.time.seconds;
|
|
||||||
|
|
||||||
notification_message_block(gps_uart->notifications, &sequence_blink_magenta_10);
|
notification_message_block(gps_uart->notifications, &sequence_blink_magenta_10);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t gps_uart_worker(void* context)
|
static int32_t gps_uart_worker(void* context) {
|
||||||
{
|
GpsUart* gps_uart = (GpsUart*)context;
|
||||||
GpsUart* gps_uart = (GpsUart*)context;
|
|
||||||
|
|
||||||
gps_uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE * 5, 1);
|
gps_uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE * 5, 1);
|
||||||
size_t rx_offset = 0;
|
size_t rx_offset = 0;
|
||||||
|
|
||||||
gps_uart_serial_init(gps_uart);
|
gps_uart_serial_init(gps_uart);
|
||||||
|
|
||||||
while (1)
|
while(1) {
|
||||||
{
|
uint32_t events =
|
||||||
uint32_t events =
|
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
|
||||||
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
|
furi_check((events & FuriFlagError) == 0);
|
||||||
furi_check((events & FuriFlagError) == 0);
|
|
||||||
|
|
||||||
if (events & WorkerEvtStop)
|
if(events & WorkerEvtStop) {
|
||||||
{
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
if(events & WorkerEvtRxDone) {
|
||||||
if (events & WorkerEvtRxDone)
|
size_t len = 0;
|
||||||
{
|
do {
|
||||||
size_t len = 0;
|
len = furi_stream_buffer_receive(
|
||||||
do
|
gps_uart->rx_stream,
|
||||||
{
|
gps_uart->rx_buf + rx_offset,
|
||||||
len = furi_stream_buffer_receive(gps_uart->rx_stream, gps_uart->rx_buf + rx_offset, RX_BUF_SIZE - 1 - rx_offset,
|
RX_BUF_SIZE - 1 - rx_offset,
|
||||||
0);
|
0);
|
||||||
if (len > 0)
|
if(len > 0) {
|
||||||
{
|
rx_offset += len;
|
||||||
rx_offset += len;
|
gps_uart->rx_buf[rx_offset] = '\0';
|
||||||
gps_uart->rx_buf[rx_offset] = '\0';
|
|
||||||
|
char* line_current = (char*)gps_uart->rx_buf;
|
||||||
char * line_current = (char *)gps_uart->rx_buf;
|
while(1) {
|
||||||
while (1)
|
while(*line_current == '\0' &&
|
||||||
{
|
line_current < (char*)gps_uart->rx_buf + rx_offset - 1) {
|
||||||
while (*line_current == '\0' && line_current < (char *)gps_uart->rx_buf + rx_offset - 1)
|
line_current++;
|
||||||
{
|
}
|
||||||
line_current++;
|
|
||||||
}
|
char* newline = strchr(line_current, '\n');
|
||||||
|
if(newline) {
|
||||||
char * newline = strchr(line_current, '\n');
|
*newline = '\0';
|
||||||
if (newline)
|
gps_uart_parse_nmea(gps_uart, line_current);
|
||||||
{
|
line_current = newline + 1;
|
||||||
*newline = '\0';
|
} else {
|
||||||
gps_uart_parse_nmea(gps_uart, line_current);
|
if(line_current > (char*)gps_uart->rx_buf) {
|
||||||
line_current = newline + 1;
|
rx_offset = 0;
|
||||||
}
|
while(*line_current) {
|
||||||
else
|
gps_uart->rx_buf[rx_offset++] = *(line_current++);
|
||||||
{
|
}
|
||||||
if (line_current > (char *)gps_uart->rx_buf)
|
}
|
||||||
{
|
break;
|
||||||
rx_offset = 0;
|
}
|
||||||
while (*line_current)
|
}
|
||||||
{
|
}
|
||||||
gps_uart->rx_buf[rx_offset++] = *(line_current++);
|
} while(len > 0);
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
while (len > 0);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
gps_uart_serial_deinit(gps_uart);
|
gps_uart_serial_deinit(gps_uart);
|
||||||
furi_stream_buffer_free(gps_uart->rx_stream);
|
furi_stream_buffer_free(gps_uart->rx_stream);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GpsUart* gps_uart_enable()
|
GpsUart* gps_uart_enable() {
|
||||||
{
|
GpsUart* gps_uart = malloc(sizeof(GpsUart));
|
||||||
GpsUart* gps_uart = malloc(sizeof(GpsUart));
|
|
||||||
|
|
||||||
gps_uart->status.valid = false;
|
gps_uart->status.valid = false;
|
||||||
gps_uart->status.latitude = 0.0;
|
gps_uart->status.latitude = 0.0;
|
||||||
gps_uart->status.longitude = 0.0;
|
gps_uart->status.longitude = 0.0;
|
||||||
gps_uart->status.speed = 0.0;
|
gps_uart->status.speed = 0.0;
|
||||||
gps_uart->status.course = 0.0;
|
gps_uart->status.course = 0.0;
|
||||||
gps_uart->status.altitude = 0.0;
|
gps_uart->status.altitude = 0.0;
|
||||||
gps_uart->status.altitude_units = ' ';
|
gps_uart->status.altitude_units = ' ';
|
||||||
gps_uart->status.fix_quality = 0;
|
gps_uart->status.fix_quality = 0;
|
||||||
gps_uart->status.satellites_tracked = 0;
|
gps_uart->status.satellites_tracked = 0;
|
||||||
gps_uart->status.time_hours = 0;
|
gps_uart->status.time_hours = 0;
|
||||||
gps_uart->status.time_minutes = 0;
|
gps_uart->status.time_minutes = 0;
|
||||||
gps_uart->status.time_seconds = 0;
|
gps_uart->status.time_seconds = 0;
|
||||||
|
|
||||||
gps_uart->notifications = furi_record_open(RECORD_NOTIFICATION);
|
gps_uart->notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||||
|
|
||||||
gps_uart->thread = furi_thread_alloc();
|
gps_uart->thread = furi_thread_alloc();
|
||||||
furi_thread_set_name(gps_uart->thread, "GpsUartWorker");
|
furi_thread_set_name(gps_uart->thread, "GpsUartWorker");
|
||||||
furi_thread_set_stack_size(gps_uart->thread, 1024);
|
furi_thread_set_stack_size(gps_uart->thread, 1024);
|
||||||
furi_thread_set_context(gps_uart->thread, gps_uart);
|
furi_thread_set_context(gps_uart->thread, gps_uart);
|
||||||
furi_thread_set_callback(gps_uart->thread, gps_uart_worker);
|
furi_thread_set_callback(gps_uart->thread, gps_uart_worker);
|
||||||
|
|
||||||
furi_thread_start(gps_uart->thread);
|
furi_thread_start(gps_uart->thread);
|
||||||
return gps_uart;
|
return gps_uart;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gps_uart_disable(GpsUart* gps_uart)
|
void gps_uart_disable(GpsUart* gps_uart) {
|
||||||
{
|
furi_assert(gps_uart);
|
||||||
furi_assert(gps_uart);
|
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtStop);
|
||||||
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtStop);
|
furi_thread_join(gps_uart->thread);
|
||||||
furi_thread_join(gps_uart->thread);
|
furi_thread_free(gps_uart->thread);
|
||||||
furi_thread_free(gps_uart->thread);
|
|
||||||
|
|
||||||
furi_record_close(RECORD_NOTIFICATION);
|
furi_record_close(RECORD_NOTIFICATION);
|
||||||
|
|
||||||
free(gps_uart);
|
free(gps_uart);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,31 +6,29 @@
|
|||||||
#define GPS_BAUDRATE 9600
|
#define GPS_BAUDRATE 9600
|
||||||
#define RX_BUF_SIZE 1024
|
#define RX_BUF_SIZE 1024
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
bool valid;
|
||||||
bool valid;
|
float latitude;
|
||||||
float latitude;
|
float longitude;
|
||||||
float longitude;
|
float speed;
|
||||||
float speed;
|
float course;
|
||||||
float course;
|
float altitude;
|
||||||
float altitude;
|
char altitude_units;
|
||||||
char altitude_units;
|
int fix_quality;
|
||||||
int fix_quality;
|
int satellites_tracked;
|
||||||
int satellites_tracked;
|
int time_hours;
|
||||||
int time_hours;
|
int time_minutes;
|
||||||
int time_minutes;
|
int time_seconds;
|
||||||
int time_seconds;
|
|
||||||
} GpsStatus;
|
} GpsStatus;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
FuriThread* thread;
|
||||||
FuriThread* thread;
|
FuriStreamBuffer* rx_stream;
|
||||||
FuriStreamBuffer* rx_stream;
|
uint8_t rx_buf[RX_BUF_SIZE];
|
||||||
uint8_t rx_buf[RX_BUF_SIZE];
|
|
||||||
|
|
||||||
NotificationApp* notifications;
|
NotificationApp* notifications;
|
||||||
|
|
||||||
GpsStatus status;
|
GpsStatus status;
|
||||||
} GpsUart;
|
} GpsUart;
|
||||||
|
|
||||||
GpsUart* gps_uart_enable();
|
GpsUart* gps_uart_enable();
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -87,8 +87,10 @@ struct minmea_sentence_gga {
|
|||||||
int fix_quality;
|
int fix_quality;
|
||||||
int satellites_tracked;
|
int satellites_tracked;
|
||||||
struct minmea_float hdop;
|
struct minmea_float hdop;
|
||||||
struct minmea_float altitude; char altitude_units;
|
struct minmea_float altitude;
|
||||||
struct minmea_float height; char height_units;
|
char altitude_units;
|
||||||
|
struct minmea_float height;
|
||||||
|
char height_units;
|
||||||
struct minmea_float dgps_age;
|
struct minmea_float dgps_age;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -179,22 +181,22 @@ struct minmea_sentence_zda {
|
|||||||
/**
|
/**
|
||||||
* Calculate raw sentence checksum. Does not check sentence integrity.
|
* Calculate raw sentence checksum. Does not check sentence integrity.
|
||||||
*/
|
*/
|
||||||
uint8_t minmea_checksum(const char *sentence);
|
uint8_t minmea_checksum(const char* sentence);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check sentence validity and checksum. Returns true for valid sentences.
|
* Check sentence validity and checksum. Returns true for valid sentences.
|
||||||
*/
|
*/
|
||||||
bool minmea_check(const char *sentence, bool strict);
|
bool minmea_check(const char* sentence, bool strict);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine talker identifier.
|
* Determine talker identifier.
|
||||||
*/
|
*/
|
||||||
bool minmea_talker_id(char talker[3], const char *sentence);
|
bool minmea_talker_id(char talker[3], const char* sentence);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine sentence identifier.
|
* Determine sentence identifier.
|
||||||
*/
|
*/
|
||||||
enum minmea_sentence_id minmea_sentence_id(const char *sentence, bool strict);
|
enum minmea_sentence_id minmea_sentence_id(const char* sentence, bool strict);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scanf-like processor for NMEA sentences. Supports the following formats:
|
* Scanf-like processor for NMEA sentences. Supports the following formats:
|
||||||
@@ -210,72 +212,70 @@ enum minmea_sentence_id minmea_sentence_id(const char *sentence, bool strict);
|
|||||||
* ; - following fields are optional
|
* ; - following fields are optional
|
||||||
* Returns true on success. See library source code for details.
|
* Returns true on success. See library source code for details.
|
||||||
*/
|
*/
|
||||||
bool minmea_scan(const char *sentence, const char *format, ...);
|
bool minmea_scan(const char* sentence, const char* format, ...);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse a specific type of sentence. Return true on success.
|
* Parse a specific type of sentence. Return true on success.
|
||||||
*/
|
*/
|
||||||
bool minmea_parse_gbs(struct minmea_sentence_gbs *frame, const char *sentence);
|
bool minmea_parse_gbs(struct minmea_sentence_gbs* frame, const char* sentence);
|
||||||
bool minmea_parse_rmc(struct minmea_sentence_rmc *frame, const char *sentence);
|
bool minmea_parse_rmc(struct minmea_sentence_rmc* frame, const char* sentence);
|
||||||
bool minmea_parse_gga(struct minmea_sentence_gga *frame, const char *sentence);
|
bool minmea_parse_gga(struct minmea_sentence_gga* frame, const char* sentence);
|
||||||
bool minmea_parse_gsa(struct minmea_sentence_gsa *frame, const char *sentence);
|
bool minmea_parse_gsa(struct minmea_sentence_gsa* frame, const char* sentence);
|
||||||
bool minmea_parse_gll(struct minmea_sentence_gll *frame, const char *sentence);
|
bool minmea_parse_gll(struct minmea_sentence_gll* frame, const char* sentence);
|
||||||
bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence);
|
bool minmea_parse_gst(struct minmea_sentence_gst* frame, const char* sentence);
|
||||||
bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence);
|
bool minmea_parse_gsv(struct minmea_sentence_gsv* frame, const char* sentence);
|
||||||
bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence);
|
bool minmea_parse_vtg(struct minmea_sentence_vtg* frame, const char* sentence);
|
||||||
bool minmea_parse_zda(struct minmea_sentence_zda *frame, const char *sentence);
|
bool minmea_parse_zda(struct minmea_sentence_zda* frame, const char* sentence);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert GPS UTC date/time representation to a UNIX calendar time.
|
* Convert GPS UTC date/time representation to a UNIX calendar time.
|
||||||
*/
|
*/
|
||||||
int minmea_getdatetime(struct tm *tm, const struct minmea_date *date, const struct minmea_time *time_);
|
int minmea_getdatetime(
|
||||||
|
struct tm* tm,
|
||||||
|
const struct minmea_date* date,
|
||||||
|
const struct minmea_time* time_);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert GPS UTC date/time representation to a UNIX timestamp.
|
* Convert GPS UTC date/time representation to a UNIX timestamp.
|
||||||
*/
|
*/
|
||||||
int minmea_gettime(struct timespec *ts, const struct minmea_date *date, const struct minmea_time *time_);
|
int minmea_gettime(
|
||||||
|
struct timespec* ts,
|
||||||
|
const struct minmea_date* date,
|
||||||
|
const struct minmea_time* time_);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rescale a fixed-point value to a different scale. Rounds towards zero.
|
* Rescale a fixed-point value to a different scale. Rounds towards zero.
|
||||||
*/
|
*/
|
||||||
static inline int_least32_t minmea_rescale(const struct minmea_float *f, int_least32_t new_scale)
|
static inline int_least32_t minmea_rescale(const struct minmea_float* f, int_least32_t new_scale) {
|
||||||
{
|
if(f->scale == 0) return 0;
|
||||||
if (f->scale == 0)
|
if(f->scale == new_scale) return f->value;
|
||||||
return 0;
|
if(f->scale > new_scale)
|
||||||
if (f->scale == new_scale)
|
return (f->value + ((f->value > 0) - (f->value < 0)) * f->scale / new_scale / 2) /
|
||||||
return f->value;
|
(f->scale / new_scale);
|
||||||
if (f->scale > new_scale)
|
|
||||||
return (f->value + ((f->value > 0) - (f->value < 0)) * f->scale/new_scale/2) / (f->scale/new_scale);
|
|
||||||
else
|
else
|
||||||
return f->value * (new_scale/f->scale);
|
return f->value * (new_scale / f->scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a fixed-point value to a floating-point value.
|
* Convert a fixed-point value to a floating-point value.
|
||||||
* Returns NaN for "unknown" values.
|
* Returns NaN for "unknown" values.
|
||||||
*/
|
*/
|
||||||
static inline float minmea_tofloat(const struct minmea_float *f)
|
static inline float minmea_tofloat(const struct minmea_float* f) {
|
||||||
{
|
if(f->scale == 0) return NAN;
|
||||||
if (f->scale == 0)
|
return (float)f->value / (float)f->scale;
|
||||||
return NAN;
|
|
||||||
return (float) f->value / (float) f->scale;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a raw coordinate to a floating point DD.DDD... value.
|
* Convert a raw coordinate to a floating point DD.DDD... value.
|
||||||
* Returns NaN for "unknown" values.
|
* Returns NaN for "unknown" values.
|
||||||
*/
|
*/
|
||||||
static inline float minmea_tocoord(const struct minmea_float *f)
|
static inline float minmea_tocoord(const struct minmea_float* f) {
|
||||||
{
|
if(f->scale == 0) return NAN;
|
||||||
if (f->scale == 0)
|
if(f->scale > (INT_LEAST32_MAX / 100)) return NAN;
|
||||||
return NAN;
|
if(f->scale < (INT_LEAST32_MIN / 100)) return NAN;
|
||||||
if (f->scale > (INT_LEAST32_MAX / 100))
|
|
||||||
return NAN;
|
|
||||||
if (f->scale < (INT_LEAST32_MIN / 100))
|
|
||||||
return NAN;
|
|
||||||
int_least32_t degrees = f->value / (f->scale * 100);
|
int_least32_t degrees = f->value / (f->scale * 100);
|
||||||
int_least32_t minutes = f->value % (f->scale * 100);
|
int_least32_t minutes = f->value % (f->scale * 100);
|
||||||
return (float) degrees + (float) minutes / (60 * f->scale);
|
return (float)degrees + (float)minutes / (60 * f->scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -283,7 +283,7 @@ static inline float minmea_tocoord(const struct minmea_float *f)
|
|||||||
* sentence data field.
|
* sentence data field.
|
||||||
*/
|
*/
|
||||||
static inline bool minmea_isfield(char c) {
|
static inline bool minmea_isfield(char c) {
|
||||||
return isprint((unsigned char) c) && c != ',' && c != '*';
|
return isprint((unsigned char)c) && c != ',' && c != '*';
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ static FlipperFormat* snake_game_open_file() {
|
|||||||
void snake_game_save_score_to_file(int16_t highscore) {
|
void snake_game_save_score_to_file(int16_t highscore) {
|
||||||
FlipperFormat* file = snake_game_open_file();
|
FlipperFormat* file = snake_game_open_file();
|
||||||
uint32_t temp = highscore;
|
uint32_t temp = highscore;
|
||||||
if(!flipper_format_insert_or_update_uint32(file, SNAKE_GAME_CONFIG_HIGHSCORE,&temp, 1)){
|
if(!flipper_format_insert_or_update_uint32(file, SNAKE_GAME_CONFIG_HIGHSCORE, &temp, 1)) {
|
||||||
snake_game_close_file(file);
|
snake_game_close_file(file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -105,12 +105,12 @@ bool snake_game_init_game_from_file(SnakeState* const snake_state) {
|
|||||||
}
|
}
|
||||||
furi_string_free(file_type);
|
furi_string_free(file_type);
|
||||||
|
|
||||||
|
|
||||||
uint32_t temp;
|
uint32_t temp;
|
||||||
snake_state->highscore = (flipper_format_read_uint32(file, SNAKE_GAME_CONFIG_HIGHSCORE, &temp, 1)) ? temp : 0;
|
snake_state->highscore =
|
||||||
|
(flipper_format_read_uint32(file, SNAKE_GAME_CONFIG_HIGHSCORE, &temp, 1)) ? temp : 0;
|
||||||
flipper_format_rewind(file);
|
flipper_format_rewind(file);
|
||||||
|
|
||||||
if(!flipper_format_read_uint32(file, SNAKE_GAME_CONFIG_KEY_LEN, &temp, 1)){
|
if(!flipper_format_read_uint32(file, SNAKE_GAME_CONFIG_KEY_LEN, &temp, 1)) {
|
||||||
snake_game_close_file(file);
|
snake_game_close_file(file);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,14 +235,13 @@ static void snake_game_move_snake(SnakeState* const snake_state, Point const nex
|
|||||||
|
|
||||||
static void snake_game_game_over(SnakeState* const snake_state, NotificationApp* notification) {
|
static void snake_game_game_over(SnakeState* const snake_state, NotificationApp* notification) {
|
||||||
snake_state->state = GameStateGameOver;
|
snake_state->state = GameStateGameOver;
|
||||||
snake_state->len = snake_state->len -7;
|
snake_state->len = snake_state->len - 7;
|
||||||
if(snake_state->len > snake_state->highscore){
|
if(snake_state->len > snake_state->highscore) {
|
||||||
snake_state->isNewHighscore = true;
|
snake_state->isNewHighscore = true;
|
||||||
snake_state->highscore = snake_state->len;
|
snake_state->highscore = snake_state->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
notification_message_block(notification, &sequence_fail);
|
notification_message_block(notification, &sequence_fail);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -302,8 +301,7 @@ int32_t snake_game_app(void* p) {
|
|||||||
SnakeState* snake_state = malloc(sizeof(SnakeState));
|
SnakeState* snake_state = malloc(sizeof(SnakeState));
|
||||||
snake_state->isNewHighscore = false;
|
snake_state->isNewHighscore = false;
|
||||||
snake_state->highscore = 0;
|
snake_state->highscore = 0;
|
||||||
if(!snake_game_init_game_from_file(snake_state))
|
if(!snake_game_init_game_from_file(snake_state)) snake_game_init_game(snake_state);
|
||||||
snake_game_init_game(snake_state);
|
|
||||||
|
|
||||||
ValueMutex state_mutex;
|
ValueMutex state_mutex;
|
||||||
if(!init_mutex(&state_mutex, snake_state, sizeof(SnakeState))) {
|
if(!init_mutex(&state_mutex, snake_state, sizeof(SnakeState))) {
|
||||||
@@ -376,8 +374,7 @@ int32_t snake_game_app(void* p) {
|
|||||||
release_mutex(&state_mutex, snake_state);
|
release_mutex(&state_mutex, snake_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(snake_state->isNewHighscore)
|
if(snake_state->isNewHighscore) snake_game_save_score_to_file(snake_state->highscore);
|
||||||
snake_game_save_score_to_file(snake_state->highscore);
|
|
||||||
// Wait for all notifications to be played and return backlight to normal state
|
// Wait for all notifications to be played and return backlight to normal state
|
||||||
notification_message_block(notification, &sequence_display_backlight_enforce_auto);
|
notification_message_block(notification, &sequence_display_backlight_enforce_auto);
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
static void render_callback(Canvas* const canvas, void* ctx) {
|
static void render_callback(Canvas* const canvas, void* ctx) {
|
||||||
PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25);
|
PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25);
|
||||||
if (plugin_state != NULL && !plugin_state->changing_scene) {
|
if(plugin_state != NULL && !plugin_state->changing_scene) {
|
||||||
totp_scene_director_render(canvas, plugin_state);
|
totp_scene_director_render(canvas, plugin_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,29 +49,43 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
|
|||||||
|
|
||||||
totp_scene_director_init_scenes(plugin_state);
|
totp_scene_director_init_scenes(plugin_state);
|
||||||
|
|
||||||
if (plugin_state->crypto_verify_data == NULL) {
|
if(plugin_state->crypto_verify_data == NULL) {
|
||||||
DialogMessage* message = dialog_message_alloc();
|
DialogMessage* message = dialog_message_alloc();
|
||||||
dialog_message_set_buttons(message, "No", NULL, "Yes");
|
dialog_message_set_buttons(message, "No", NULL, "Yes");
|
||||||
dialog_message_set_text(message, "Would you like to setup PIN?", SCREEN_WIDTH_CENTER, SCREEN_HEIGHT_CENTER, AlignCenter, AlignCenter);
|
dialog_message_set_text(
|
||||||
|
message,
|
||||||
|
"Would you like to setup PIN?",
|
||||||
|
SCREEN_WIDTH_CENTER,
|
||||||
|
SCREEN_HEIGHT_CENTER,
|
||||||
|
AlignCenter,
|
||||||
|
AlignCenter);
|
||||||
DialogMessageButton dialog_result = dialog_message_show(plugin_state->dialogs, message);
|
DialogMessageButton dialog_result = dialog_message_show(plugin_state->dialogs, message);
|
||||||
dialog_message_free(message);
|
dialog_message_free(message);
|
||||||
if (dialog_result == DialogMessageButtonRight) {
|
if(dialog_result == DialogMessageButtonRight) {
|
||||||
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
|
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
|
||||||
} else {
|
} else {
|
||||||
totp_crypto_seed_iv(plugin_state, NULL, 0);
|
totp_crypto_seed_iv(plugin_state, NULL, 0);
|
||||||
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
|
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
|
||||||
}
|
}
|
||||||
} else if (plugin_state->pin_set) {
|
} else if(plugin_state->pin_set) {
|
||||||
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
|
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
|
||||||
} else {
|
} else {
|
||||||
totp_crypto_seed_iv(plugin_state, NULL, 0);
|
totp_crypto_seed_iv(plugin_state, NULL, 0);
|
||||||
if (totp_crypto_verify_key(plugin_state)) {
|
if(totp_crypto_verify_key(plugin_state)) {
|
||||||
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
|
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
|
||||||
} else {
|
} else {
|
||||||
FURI_LOG_E(LOGGING_TAG, "Digital signature verification failed. Looks like conf file was created on another flipper and can't be used on any other");
|
FURI_LOG_E(
|
||||||
|
LOGGING_TAG,
|
||||||
|
"Digital signature verification failed. Looks like conf file was created on another flipper and can't be used on any other");
|
||||||
DialogMessage* message = dialog_message_alloc();
|
DialogMessage* message = dialog_message_alloc();
|
||||||
dialog_message_set_buttons(message, "Exit", NULL, NULL);
|
dialog_message_set_buttons(message, "Exit", NULL, NULL);
|
||||||
dialog_message_set_text(message, "Digital signature verification failed", SCREEN_WIDTH_CENTER, SCREEN_HEIGHT_CENTER, AlignCenter, AlignCenter);
|
dialog_message_set_text(
|
||||||
|
message,
|
||||||
|
"Digital signature verification failed",
|
||||||
|
SCREEN_WIDTH_CENTER,
|
||||||
|
SCREEN_HEIGHT_CENTER,
|
||||||
|
AlignCenter,
|
||||||
|
AlignCenter);
|
||||||
dialog_message_show(plugin_state->dialogs, message);
|
dialog_message_show(plugin_state->dialogs, message);
|
||||||
dialog_message_free(message);
|
dialog_message_free(message);
|
||||||
return false;
|
return false;
|
||||||
@@ -94,7 +108,7 @@ static void totp_plugin_state_free(PluginState* plugin_state) {
|
|||||||
|
|
||||||
ListNode* node = plugin_state->tokens_list;
|
ListNode* node = plugin_state->tokens_list;
|
||||||
ListNode* tmp;
|
ListNode* tmp;
|
||||||
while (node != NULL) {
|
while(node != NULL) {
|
||||||
tmp = node->next;
|
tmp = node->next;
|
||||||
TokenInfo* tokenInfo = node->data;
|
TokenInfo* tokenInfo = node->data;
|
||||||
token_info_free(tokenInfo);
|
token_info_free(tokenInfo);
|
||||||
@@ -102,7 +116,7 @@ static void totp_plugin_state_free(PluginState* plugin_state) {
|
|||||||
node = tmp;
|
node = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin_state->crypto_verify_data != NULL) {
|
if(plugin_state->crypto_verify_data != NULL) {
|
||||||
free(plugin_state->crypto_verify_data);
|
free(plugin_state->crypto_verify_data);
|
||||||
}
|
}
|
||||||
free(plugin_state);
|
free(plugin_state);
|
||||||
@@ -112,7 +126,7 @@ int32_t totp_app() {
|
|||||||
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
|
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
|
||||||
PluginState* plugin_state = malloc(sizeof(PluginState));
|
PluginState* plugin_state = malloc(sizeof(PluginState));
|
||||||
|
|
||||||
if (!totp_plugin_state_init(plugin_state)) {
|
if(!totp_plugin_state_init(plugin_state)) {
|
||||||
FURI_LOG_E(LOGGING_TAG, "App state initialization failed\r\n");
|
FURI_LOG_E(LOGGING_TAG, "App state initialization failed\r\n");
|
||||||
totp_plugin_state_free(plugin_state);
|
totp_plugin_state_free(plugin_state);
|
||||||
return 254;
|
return 254;
|
||||||
@@ -137,18 +151,20 @@ int32_t totp_app() {
|
|||||||
bool processing = true;
|
bool processing = true;
|
||||||
uint32_t last_user_interaction_time = furi_get_tick();
|
uint32_t last_user_interaction_time = furi_get_tick();
|
||||||
while(processing) {
|
while(processing) {
|
||||||
if (plugin_state->changing_scene) continue;
|
if(plugin_state->changing_scene) continue;
|
||||||
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
||||||
|
|
||||||
PluginState* plugin_state = acquire_mutex_block(&state_mutex);
|
PluginState* plugin_state = acquire_mutex_block(&state_mutex);
|
||||||
|
|
||||||
if(event_status == FuriStatusOk) {
|
if(event_status == FuriStatusOk) {
|
||||||
if (event.type == EventTypeKey) {
|
if(event.type == EventTypeKey) {
|
||||||
last_user_interaction_time = furi_get_tick();
|
last_user_interaction_time = furi_get_tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
processing = totp_scene_director_handle_event(&event, plugin_state);
|
processing = totp_scene_director_handle_event(&event, plugin_state);
|
||||||
} else if (plugin_state->pin_set && plugin_state->current_scene != TotpSceneAuthentication && furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
|
} else if(
|
||||||
|
plugin_state->pin_set && plugin_state->current_scene != TotpSceneAuthentication &&
|
||||||
|
furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
|
||||||
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
|
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user