diff --git a/applications/bt/bt_hid_app/bt_hid.c b/applications/bt/bt_hid_app/bt_hid.c index 6a93ce85..020a26b8 100755 --- a/applications/bt/bt_hid_app/bt_hid.c +++ b/applications/bt/bt_hid_app/bt_hid.c @@ -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); diff --git a/applications/bt/bt_hid_app/bt_hid.h b/applications/bt/bt_hid_app/bt_hid.h index 4156b44b..875cac58 100644 --- a/applications/bt/bt_hid_app/bt_hid.h +++ b/applications/bt/bt_hid_app/bt_hid.h @@ -6,7 +6,6 @@ #include #include #include -#include #include #include @@ -14,7 +13,6 @@ #include "views/bt_hid_media.h" typedef struct { - BtSettings bt_settings; Bt* bt; Gui* gui; NotificationApp* notifications; diff --git a/applications/bt/bt_service/bt.c b/applications/bt/bt_service/bt.c index 4dfcdfb7..fdd43ec4 100755 --- a/applications/bt/bt_service/bt.c +++ b/applications/bt/bt_service/bt.c @@ -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); diff --git a/applications/cli/cli_commands.c b/applications/cli/cli_commands.c index 7f194220..c7827d2f 100644 --- a/applications/cli/cli_commands.c +++ b/applications/cli/cli_commands.c @@ -6,6 +6,9 @@ #include #include +// 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); } } diff --git a/firmware/targets/f6/furi-hal/furi-hal-bt.c b/firmware/targets/f6/furi-hal/furi-hal-bt.c index bbd29754..5a457279 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-bt.c +++ b/firmware/targets/f6/furi-hal/furi-hal-bt.c @@ -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(); diff --git a/firmware/targets/f6/furi-hal/furi-hal-rtc.c b/firmware/targets/f6/furi-hal/furi-hal-rtc.c index 13bb17cb..20e77e13 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-rtc.c +++ b/firmware/targets/f6/furi-hal/furi-hal-rtc.c @@ -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; +} diff --git a/firmware/targets/f7/furi-hal/furi-hal-bt.c b/firmware/targets/f7/furi-hal/furi-hal-bt.c index bbd29754..5a457279 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-bt.c +++ b/firmware/targets/f7/furi-hal/furi-hal-bt.c @@ -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(); diff --git a/firmware/targets/f7/furi-hal/furi-hal-rtc.c b/firmware/targets/f7/furi-hal/furi-hal-rtc.c index 13bb17cb..20e77e13 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-rtc.c +++ b/firmware/targets/f7/furi-hal/furi-hal-rtc.c @@ -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; +} diff --git a/firmware/targets/furi-hal-include/furi-hal-rtc.h b/firmware/targets/furi-hal-include/furi-hal-rtc.h index 7c36aa09..cc2f56f5 100644 --- a/firmware/targets/furi-hal-include/furi-hal-rtc.h +++ b/firmware/targets/furi-hal-include/furi-hal-rtc.h @@ -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