mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-23 04:53:08 +00:00
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
9 changed files with 92 additions and 39 deletions
|
@ -28,7 +28,7 @@ void bt_hid_dialog_callback(DialogExResult result, void* context) {
|
|||
// TODO switch to Submenu after Media is done
|
||||
view_dispatcher_stop(app->view_dispatcher);
|
||||
} 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* app = furi_alloc(sizeof(BtHid));
|
||||
|
||||
// Load Bluetooth settings
|
||||
bt_settings_load(&app->bt_settings);
|
||||
|
||||
// Gui
|
||||
app->gui = furi_record_open("gui");
|
||||
|
||||
|
@ -156,10 +153,6 @@ int32_t bt_hid_app(void* p) {
|
|||
view_dispatcher_run(app->view_dispatcher);
|
||||
|
||||
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
|
||||
bt_set_profile(app->bt, BtProfileSerial);
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <gui/view.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <applications/notification/notification.h>
|
||||
#include <applications/bt/bt_settings.h>
|
||||
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
@ -14,7 +13,6 @@
|
|||
#include "views/bt_hid_media.h"
|
||||
|
||||
typedef struct {
|
||||
BtSettings bt_settings;
|
||||
Bt* bt;
|
||||
Gui* gui;
|
||||
NotificationApp* notifications;
|
||||
|
|
|
@ -235,6 +235,7 @@ static void bt_statusbar_update(Bt* bt) {
|
|||
}
|
||||
|
||||
static void bt_change_profile(Bt* bt, BtMessage* message) {
|
||||
bt_settings_load(&bt->bt_settings);
|
||||
if(bt->profile == BtProfileSerial && bt->rpc_session) {
|
||||
FURI_LOG_I(TAG, "Close RPC connection");
|
||||
osEventFlagsSet(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
#include <time.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) {
|
||||
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;
|
||||
int ret = sscanf(
|
||||
string_get_cstr(args),
|
||||
"%hu:%hu:%hu %hu-%hu-%hu %hu",
|
||||
"%hu-%hu-%hu %hu:%hu:%hu %hu",
|
||||
&year,
|
||||
&month,
|
||||
&day,
|
||||
&hours,
|
||||
&minutes,
|
||||
&seconds,
|
||||
&month,
|
||||
&day,
|
||||
&year,
|
||||
&weekday);
|
||||
if(ret == 7) {
|
||||
datetime.hour = hours;
|
||||
datetime.minute = minutes;
|
||||
datetime.second = seconds;
|
||||
datetime.weekday = weekday;
|
||||
datetime.month = month;
|
||||
datetime.day = day;
|
||||
datetime.year = year;
|
||||
furi_hal_rtc_set_datetime(&datetime);
|
||||
// Verification
|
||||
furi_hal_rtc_get_datetime(&datetime);
|
||||
|
||||
// Some variables are going to discard upper byte
|
||||
// There will be some funky behaviour which is not breaking anything
|
||||
datetime.hour = hours;
|
||||
datetime.minute = minutes;
|
||||
datetime.second = seconds;
|
||||
datetime.weekday = weekday;
|
||||
datetime.month = month;
|
||||
datetime.day = day;
|
||||
datetime.year = year;
|
||||
|
||||
if(ret != 7) {
|
||||
printf(
|
||||
"New time is: %.2d:%.2d:%.2d %.2d-%.2d-%.2d %d",
|
||||
datetime.hour,
|
||||
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",
|
||||
"Invalid datetime format, use `%s`. sscanf %d %s",
|
||||
"%Y-%m-%d %H:%M:%S %u",
|
||||
ret,
|
||||
string_get_cstr(args));
|
||||
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);
|
||||
printf(
|
||||
"%.2d:%.2d:%.2d %.2d-%.2d-%.2d %d",
|
||||
"New datetime is: " CLI_DATE_FORMAT,
|
||||
datetime.year,
|
||||
datetime.month,
|
||||
datetime.day,
|
||||
datetime.hour,
|
||||
datetime.minute,
|
||||
datetime.second,
|
||||
datetime.weekday);
|
||||
} else {
|
||||
furi_hal_rtc_get_datetime(&datetime);
|
||||
printf(
|
||||
CLI_DATE_FORMAT,
|
||||
datetime.year,
|
||||
datetime.month,
|
||||
datetime.day,
|
||||
datetime.year,
|
||||
datetime.hour,
|
||||
datetime.minute,
|
||||
datetime.second,
|
||||
datetime.weekday);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,6 +160,7 @@ bool furi_hal_bt_change_app(FuriHalBtProfile profile, BleEventCallback event_cb,
|
|||
gap_thread_stop();
|
||||
FURI_LOG_I(TAG, "Reset SHCI");
|
||||
SHCI_C2_Reinit();
|
||||
osDelay(100);
|
||||
ble_glue_thread_stop();
|
||||
FURI_LOG_I(TAG, "Start BT initialization");
|
||||
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->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();
|
||||
FURI_LOG_I(TAG, "Reset SHCI");
|
||||
SHCI_C2_Reinit();
|
||||
osDelay(100);
|
||||
ble_glue_thread_stop();
|
||||
FURI_LOG_I(TAG, "Start BT initialization");
|
||||
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->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);
|
||||
|
||||
bool furi_hal_rtc_validate_datetime(FuriHalRtcDateTime* datetime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue