BT hid navigation fix (#911)
* bt: fix bt hid navigation * Cli: change datetime format to more ISO-ish, add datetime validation. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
parent
e109e2e3e8
commit
93871f9425
@ -28,7 +28,7 @@ void bt_hid_dialog_callback(DialogExResult result, void* context) {
|
|||||||
// TODO switch to Submenu after Media is done
|
// TODO switch to Submenu after Media is done
|
||||||
view_dispatcher_stop(app->view_dispatcher);
|
view_dispatcher_stop(app->view_dispatcher);
|
||||||
} else if(result == DialogExResultRight) {
|
} else if(result == DialogExResultRight) {
|
||||||
view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id);
|
view_dispatcher_switch_to_view(app->view_dispatcher, BtHidViewKeynote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,9 +56,6 @@ void bt_hid_connection_status_changed_callback(BtStatus status, void* context) {
|
|||||||
BtHid* bt_hid_app_alloc() {
|
BtHid* bt_hid_app_alloc() {
|
||||||
BtHid* app = furi_alloc(sizeof(BtHid));
|
BtHid* app = furi_alloc(sizeof(BtHid));
|
||||||
|
|
||||||
// Load Bluetooth settings
|
|
||||||
bt_settings_load(&app->bt_settings);
|
|
||||||
|
|
||||||
// Gui
|
// Gui
|
||||||
app->gui = furi_record_open("gui");
|
app->gui = furi_record_open("gui");
|
||||||
|
|
||||||
@ -156,10 +153,6 @@ int32_t bt_hid_app(void* p) {
|
|||||||
view_dispatcher_run(app->view_dispatcher);
|
view_dispatcher_run(app->view_dispatcher);
|
||||||
|
|
||||||
bt_set_status_changed_callback(app->bt, NULL, NULL);
|
bt_set_status_changed_callback(app->bt, NULL, NULL);
|
||||||
// Stop advertising if bt was off
|
|
||||||
if(app->bt_settings.enabled) {
|
|
||||||
furi_hal_bt_stop_advertising();
|
|
||||||
}
|
|
||||||
// Change back profile to Serial
|
// Change back profile to Serial
|
||||||
bt_set_profile(app->bt, BtProfileSerial);
|
bt_set_profile(app->bt, BtProfileSerial);
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
#include <gui/view_dispatcher.h>
|
#include <gui/view_dispatcher.h>
|
||||||
#include <applications/notification/notification.h>
|
#include <applications/notification/notification.h>
|
||||||
#include <applications/bt/bt_settings.h>
|
|
||||||
|
|
||||||
#include <gui/modules/submenu.h>
|
#include <gui/modules/submenu.h>
|
||||||
#include <gui/modules/dialog_ex.h>
|
#include <gui/modules/dialog_ex.h>
|
||||||
@ -14,7 +13,6 @@
|
|||||||
#include "views/bt_hid_media.h"
|
#include "views/bt_hid_media.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
BtSettings bt_settings;
|
|
||||||
Bt* bt;
|
Bt* bt;
|
||||||
Gui* gui;
|
Gui* gui;
|
||||||
NotificationApp* notifications;
|
NotificationApp* notifications;
|
||||||
|
@ -235,6 +235,7 @@ static void bt_statusbar_update(Bt* bt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void bt_change_profile(Bt* bt, BtMessage* message) {
|
static void bt_change_profile(Bt* bt, BtMessage* message) {
|
||||||
|
bt_settings_load(&bt->bt_settings);
|
||||||
if(bt->profile == BtProfileSerial && bt->rpc_session) {
|
if(bt->profile == BtProfileSerial && bt->rpc_session) {
|
||||||
FURI_LOG_I(TAG, "Close RPC connection");
|
FURI_LOG_I(TAG, "Close RPC connection");
|
||||||
osEventFlagsSet(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
osEventFlagsSet(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <notification/notification-messages.h>
|
#include <notification/notification-messages.h>
|
||||||
|
|
||||||
|
// Close to ISO, `date +'%Y-%m-%d %H:%M:%S %u'`
|
||||||
|
#define CLI_DATE_FORMAT "%.4d-%.2d-%.2d %.2d:%.2d:%.2d %d"
|
||||||
|
|
||||||
void cli_command_device_info_callback(const char* key, const char* value, bool last, void* context) {
|
void cli_command_device_info_callback(const char* key, const char* value, bool last, void* context) {
|
||||||
printf("%-24s: %s\r\n", key, value);
|
printf("%-24s: %s\r\n", key, value);
|
||||||
}
|
}
|
||||||
@ -63,51 +66,61 @@ void cli_command_date(Cli* cli, string_t args, void* context) {
|
|||||||
uint16_t hours, minutes, seconds, month, day, year, weekday;
|
uint16_t hours, minutes, seconds, month, day, year, weekday;
|
||||||
int ret = sscanf(
|
int ret = sscanf(
|
||||||
string_get_cstr(args),
|
string_get_cstr(args),
|
||||||
"%hu:%hu:%hu %hu-%hu-%hu %hu",
|
"%hu-%hu-%hu %hu:%hu:%hu %hu",
|
||||||
|
&year,
|
||||||
|
&month,
|
||||||
|
&day,
|
||||||
&hours,
|
&hours,
|
||||||
&minutes,
|
&minutes,
|
||||||
&seconds,
|
&seconds,
|
||||||
&month,
|
|
||||||
&day,
|
|
||||||
&year,
|
|
||||||
&weekday);
|
&weekday);
|
||||||
if(ret == 7) {
|
|
||||||
datetime.hour = hours;
|
// Some variables are going to discard upper byte
|
||||||
datetime.minute = minutes;
|
// There will be some funky behaviour which is not breaking anything
|
||||||
datetime.second = seconds;
|
datetime.hour = hours;
|
||||||
datetime.weekday = weekday;
|
datetime.minute = minutes;
|
||||||
datetime.month = month;
|
datetime.second = seconds;
|
||||||
datetime.day = day;
|
datetime.weekday = weekday;
|
||||||
datetime.year = year;
|
datetime.month = month;
|
||||||
furi_hal_rtc_set_datetime(&datetime);
|
datetime.day = day;
|
||||||
// Verification
|
datetime.year = year;
|
||||||
furi_hal_rtc_get_datetime(&datetime);
|
|
||||||
|
if(ret != 7) {
|
||||||
printf(
|
printf(
|
||||||
"New time is: %.2d:%.2d:%.2d %.2d-%.2d-%.2d %d",
|
"Invalid datetime format, use `%s`. sscanf %d %s",
|
||||||
datetime.hour,
|
"%Y-%m-%d %H:%M:%S %u",
|
||||||
datetime.minute,
|
|
||||||
datetime.second,
|
|
||||||
datetime.month,
|
|
||||||
datetime.day,
|
|
||||||
datetime.year,
|
|
||||||
datetime.weekday);
|
|
||||||
} else {
|
|
||||||
printf(
|
|
||||||
"Invalid time format, use `hh:mm:ss MM-DD-YYYY WD`. sscanf %d %s",
|
|
||||||
ret,
|
ret,
|
||||||
string_get_cstr(args));
|
string_get_cstr(args));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
if(!furi_hal_rtc_validate_datetime(&datetime)) {
|
||||||
|
printf("Invalid datetime data");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
furi_hal_rtc_set_datetime(&datetime);
|
||||||
|
// Verification
|
||||||
furi_hal_rtc_get_datetime(&datetime);
|
furi_hal_rtc_get_datetime(&datetime);
|
||||||
printf(
|
printf(
|
||||||
"%.2d:%.2d:%.2d %.2d-%.2d-%.2d %d",
|
"New datetime is: " CLI_DATE_FORMAT,
|
||||||
|
datetime.year,
|
||||||
|
datetime.month,
|
||||||
|
datetime.day,
|
||||||
datetime.hour,
|
datetime.hour,
|
||||||
datetime.minute,
|
datetime.minute,
|
||||||
datetime.second,
|
datetime.second,
|
||||||
|
datetime.weekday);
|
||||||
|
} else {
|
||||||
|
furi_hal_rtc_get_datetime(&datetime);
|
||||||
|
printf(
|
||||||
|
CLI_DATE_FORMAT,
|
||||||
|
datetime.year,
|
||||||
datetime.month,
|
datetime.month,
|
||||||
datetime.day,
|
datetime.day,
|
||||||
datetime.year,
|
datetime.hour,
|
||||||
|
datetime.minute,
|
||||||
|
datetime.second,
|
||||||
datetime.weekday);
|
datetime.weekday);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,6 +160,7 @@ bool furi_hal_bt_change_app(FuriHalBtProfile profile, BleEventCallback event_cb,
|
|||||||
gap_thread_stop();
|
gap_thread_stop();
|
||||||
FURI_LOG_I(TAG, "Reset SHCI");
|
FURI_LOG_I(TAG, "Reset SHCI");
|
||||||
SHCI_C2_Reinit();
|
SHCI_C2_Reinit();
|
||||||
|
osDelay(100);
|
||||||
ble_glue_thread_stop();
|
ble_glue_thread_stop();
|
||||||
FURI_LOG_I(TAG, "Start BT initialization");
|
FURI_LOG_I(TAG, "Start BT initialization");
|
||||||
furi_hal_bt_init();
|
furi_hal_bt_init();
|
||||||
|
@ -120,3 +120,25 @@ void furi_hal_rtc_get_datetime(FuriHalRtcDateTime* datetime) {
|
|||||||
datetime->day = __LL_RTC_CONVERT_BCD2BIN((date >> 16) & 0xFF);
|
datetime->day = __LL_RTC_CONVERT_BCD2BIN((date >> 16) & 0xFF);
|
||||||
datetime->weekday = __LL_RTC_CONVERT_BCD2BIN((date >> 24) & 0xFF);
|
datetime->weekday = __LL_RTC_CONVERT_BCD2BIN((date >> 24) & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool furi_hal_rtc_validate_datetime(FuriHalRtcDateTime* datetime) {
|
||||||
|
bool invalid = false;
|
||||||
|
|
||||||
|
invalid |= (datetime->second > 59);
|
||||||
|
invalid |= (datetime->minute > 59);
|
||||||
|
invalid |= (datetime->hour > 23);
|
||||||
|
|
||||||
|
invalid |= (datetime->year < 2000);
|
||||||
|
invalid |= (datetime->year > 2099);
|
||||||
|
|
||||||
|
invalid |= (datetime->month == 0);
|
||||||
|
invalid |= (datetime->month > 12);
|
||||||
|
|
||||||
|
invalid |= (datetime->day == 0);
|
||||||
|
invalid |= (datetime->day > 31);
|
||||||
|
|
||||||
|
invalid |= (datetime->weekday == 0);
|
||||||
|
invalid |= (datetime->weekday > 7);
|
||||||
|
|
||||||
|
return !invalid;
|
||||||
|
}
|
||||||
|
@ -160,6 +160,7 @@ bool furi_hal_bt_change_app(FuriHalBtProfile profile, BleEventCallback event_cb,
|
|||||||
gap_thread_stop();
|
gap_thread_stop();
|
||||||
FURI_LOG_I(TAG, "Reset SHCI");
|
FURI_LOG_I(TAG, "Reset SHCI");
|
||||||
SHCI_C2_Reinit();
|
SHCI_C2_Reinit();
|
||||||
|
osDelay(100);
|
||||||
ble_glue_thread_stop();
|
ble_glue_thread_stop();
|
||||||
FURI_LOG_I(TAG, "Start BT initialization");
|
FURI_LOG_I(TAG, "Start BT initialization");
|
||||||
furi_hal_bt_init();
|
furi_hal_bt_init();
|
||||||
|
@ -120,3 +120,25 @@ void furi_hal_rtc_get_datetime(FuriHalRtcDateTime* datetime) {
|
|||||||
datetime->day = __LL_RTC_CONVERT_BCD2BIN((date >> 16) & 0xFF);
|
datetime->day = __LL_RTC_CONVERT_BCD2BIN((date >> 16) & 0xFF);
|
||||||
datetime->weekday = __LL_RTC_CONVERT_BCD2BIN((date >> 24) & 0xFF);
|
datetime->weekday = __LL_RTC_CONVERT_BCD2BIN((date >> 24) & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool furi_hal_rtc_validate_datetime(FuriHalRtcDateTime* datetime) {
|
||||||
|
bool invalid = false;
|
||||||
|
|
||||||
|
invalid |= (datetime->second > 59);
|
||||||
|
invalid |= (datetime->minute > 59);
|
||||||
|
invalid |= (datetime->hour > 23);
|
||||||
|
|
||||||
|
invalid |= (datetime->year < 2000);
|
||||||
|
invalid |= (datetime->year > 2099);
|
||||||
|
|
||||||
|
invalid |= (datetime->month == 0);
|
||||||
|
invalid |= (datetime->month > 12);
|
||||||
|
|
||||||
|
invalid |= (datetime->day == 0);
|
||||||
|
invalid |= (datetime->day > 31);
|
||||||
|
|
||||||
|
invalid |= (datetime->weekday == 0);
|
||||||
|
invalid |= (datetime->weekday > 7);
|
||||||
|
|
||||||
|
return !invalid;
|
||||||
|
}
|
||||||
|
@ -47,6 +47,8 @@ void furi_hal_rtc_set_datetime(FuriHalRtcDateTime* datetime);
|
|||||||
|
|
||||||
void furi_hal_rtc_get_datetime(FuriHalRtcDateTime* datetime);
|
void furi_hal_rtc_get_datetime(FuriHalRtcDateTime* datetime);
|
||||||
|
|
||||||
|
bool furi_hal_rtc_validate_datetime(FuriHalRtcDateTime* datetime);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user