Skip to content

Commit

Permalink
upd gps nmea
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed May 1, 2024
1 parent 91a93bd commit 0556b0a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion base_pack/gps_nmea_uart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This is a single-screen app, and a few interactions are provided via the
hardware buttons:

- Long press the up button to change the **baud rate**. The default baud rate
is 9600, but 19200, 38400, 57600, and 115200 baud are also supported.
is 9600, but 4800, 19200, 38400, 57600, and 115200 baud are also supported.
- Long press the right button to change **speed units** from knots to
kilometers per hour.
- Press the OK button to set the **backlight** to always on mode. Press it
Expand Down
11 changes: 5 additions & 6 deletions base_pack/gps_nmea_uart/gps.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "constants.h"

#include <furi.h>
#include <furi_hal_power.h>
#include <gui/gui.h>
#include <string.h>
#include <expansion/expansion.h>
Expand Down Expand Up @@ -38,7 +39,7 @@ static void render_callback(Canvas* const canvas, void* context) {
32,
AlignCenter,
AlignBottom,
gps_uart->backlight_enabled ? "Backlight enabled" : "Backlight disabled");
gps_uart->backlight_on ? "Backlight enabled" : "Backlight disabled");
break;
case CHANGE_DEEPSLEEP:
canvas_set_font(canvas, FontPrimary);
Expand Down Expand Up @@ -182,16 +183,16 @@ int32_t gps_app(void* p) {
processing = false;
break;
case InputKeyOk:
if(!gps_uart->backlight_enabled) {
if(!gps_uart->backlight_on) {
notification_message_block(
gps_uart->notifications, &sequence_display_backlight_enforce_on);
gps_uart->backlight_enabled = true;
gps_uart->backlight_on = true;
} else {
notification_message_block(
gps_uart->notifications, &sequence_display_backlight_enforce_auto);
notification_message(
gps_uart->notifications, &sequence_display_backlight_off);
gps_uart->backlight_enabled = false;
gps_uart->backlight_on = false;
}

gps_uart->view_state = CHANGE_BACKLIGHT;
Expand All @@ -217,7 +218,6 @@ int32_t gps_app(void* p) {

gps_uart_init_thread(gps_uart);
gps_uart->view_state = CHANGE_BAUDRATE;

furi_mutex_release(gps_uart->mutex);
view_port_update(view_port);
furi_delay_ms(1000);
Expand Down Expand Up @@ -259,7 +259,6 @@ int32_t gps_app(void* p) {
}
}
}

if(gps_uart->view_state == NORMAL) {
furi_mutex_release(gps_uart->mutex);
view_port_update(view_port);
Expand Down
11 changes: 7 additions & 4 deletions base_pack/gps_nmea_uart/gps_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ typedef enum {
#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)

static void
gps_uart_on_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent event, void* context) {
gps_uart_on_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent ev, void* context) {
GpsUart* gps_uart = (GpsUart*)context;

if(event == FuriHalSerialRxEventData) {
if(ev == FuriHalSerialRxEventData) {
uint8_t data = furi_hal_serial_async_rx(handle);
furi_stream_buffer_send(gps_uart->rx_stream, &data, 1, 0);
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtRxDone);
}
}

static void gps_uart_serial_init(GpsUart* gps_uart) {
furi_assert(!gps_uart->serial_handle);

gps_uart->serial_handle = furi_hal_serial_control_acquire(UART_CH);
furi_check(gps_uart->serial_handle);
furi_hal_serial_init(gps_uart->serial_handle, gps_uart->baudrate);
Expand All @@ -32,10 +34,11 @@ static void gps_uart_serial_init(GpsUart* gps_uart) {
}

static void gps_uart_serial_deinit(GpsUart* gps_uart) {
UNUSED(gps_uart);
furi_assert(gps_uart->serial_handle);
furi_hal_serial_async_rx_stop(gps_uart->serial_handle);
furi_hal_serial_deinit(gps_uart->serial_handle);
furi_hal_serial_control_release(gps_uart->serial_handle);
gps_uart->serial_handle = NULL;
}

static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line) {
Expand Down Expand Up @@ -209,8 +212,8 @@ GpsUart* gps_uart_enable() {
gps_uart->notifications = furi_record_open(RECORD_NOTIFICATION);

gps_uart->baudrate = gps_baudrates[current_gps_baudrate];
gps_uart->backlight_on = false;
gps_uart->speed_units = KNOTS;
gps_uart->backlight_enabled = false;
gps_uart->deep_sleep_enabled = false;
gps_uart->view_state = NORMAL;

Expand Down
5 changes: 3 additions & 2 deletions base_pack/gps_nmea_uart/gps_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ typedef struct {
FuriThread* thread;
FuriStreamBuffer* rx_stream;
uint8_t rx_buf[RX_BUF_SIZE];
FuriHalSerialHandle* serial_handle;

NotificationApp* notifications;
uint32_t baudrate;
bool backlight_enabled;
bool backlight_on;
bool deep_sleep_enabled;
SpeedUnit speed_units;
ViewState view_state;

FuriHalSerialHandle* serial_handle;

GpsStatus status;
} GpsUart;

Expand Down

0 comments on commit 0556b0a

Please sign in to comment.