Merge branch 'dev' into shutdown_idle

This commit is contained in:
SHxKenzuto
2022-11-04 20:33:23 +01:00
committed by GitHub
163 changed files with 3200 additions and 377 deletions

View File

@@ -40,7 +40,7 @@ static bool pin_name_to_int(FuriString* pin_name, size_t* result) {
bool debug = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug);
for(size_t i = 0; i < COUNT_OF(cli_command_gpio_pins); i++) {
if(!furi_string_cmp(pin_name, cli_command_gpio_pins[i].name)) {
if(!cli_command_gpio_pins[i].debug || (cli_command_gpio_pins[i].debug && debug)) {
if(!cli_command_gpio_pins[i].debug || debug) {
*result = i;
found = true;
break;
@@ -55,7 +55,7 @@ static void gpio_print_pins(void) {
printf("Wrong pin name. Available pins: ");
bool debug = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug);
for(size_t i = 0; i < COUNT_OF(cli_command_gpio_pins); i++) {
if(!cli_command_gpio_pins[i].debug || (cli_command_gpio_pins[i].debug && debug)) {
if(!cli_command_gpio_pins[i].debug || debug) {
printf("%s ", cli_command_gpio_pins[i].name);
}
}

View File

@@ -160,7 +160,7 @@ static bool desktop_view_locked_input(InputEvent* event, void* context) {
view_commit_model(locked_view->view, is_changed);
if(view_state == DesktopViewLockedStateUnlocked) {
return view_state != DesktopViewLockedStateUnlocked;
return false;
} else if(view_state == DesktopViewLockedStateLocked && pin_locked) {
locked_view->callback(DesktopLockedEventShowPinInput, locked_view->context);
} else if(

View File

@@ -12,6 +12,7 @@ App(
order=70,
sdk_headers=[
"gui.h",
"icon_i.h",
"elements.h",
"view_dispatcher.h",
"view_stack.h",

View File

@@ -304,8 +304,7 @@ void view_dispatcher_handle_custom_event(ViewDispatcher* view_dispatcher, uint32
}
// If custom event is not consumed in View, call callback
if(!is_consumed && view_dispatcher->custom_event_callback) {
is_consumed =
view_dispatcher->custom_event_callback(view_dispatcher->event_context, event);
view_dispatcher->custom_event_callback(view_dispatcher->event_context, event);
}
}

View File

@@ -7,61 +7,51 @@
// TODO add mutex to view_port ops
static void view_port_remap_buttons_vertical(InputEvent* event) {
switch(event->key) {
case InputKeyUp:
event->key = InputKeyRight;
break;
case InputKeyDown:
event->key = InputKeyLeft;
break;
case InputKeyRight:
event->key = InputKeyDown;
break;
case InputKeyLeft:
event->key = InputKeyUp;
break;
default:
break;
}
}
_Static_assert(ViewPortOrientationMAX == 4, "Incorrect ViewPortOrientation count");
_Static_assert(
(ViewPortOrientationHorizontal == 0 && ViewPortOrientationHorizontalFlip == 1 &&
ViewPortOrientationVertical == 2 && ViewPortOrientationVerticalFlip == 3),
"Incorrect ViewPortOrientation order");
_Static_assert(InputKeyMAX == 6, "Incorrect InputKey count");
_Static_assert(
(InputKeyUp == 0 && InputKeyDown == 1 && InputKeyRight == 2 && InputKeyLeft == 3 &&
InputKeyOk == 4 && InputKeyBack == 5),
"Incorrect InputKey order");
static void view_port_remap_buttons_vertical_flip(InputEvent* event) {
switch(event->key) {
case InputKeyUp:
event->key = InputKeyLeft;
break;
case InputKeyDown:
event->key = InputKeyRight;
break;
case InputKeyRight:
event->key = InputKeyUp;
break;
case InputKeyLeft:
event->key = InputKeyDown;
break;
default:
break;
}
}
/** InputKey directional keys mappings for different screen orientations
*
*/
static const InputKey view_port_input_mapping[ViewPortOrientationMAX][InputKeyMAX] = {
{InputKeyUp,
InputKeyDown,
InputKeyRight,
InputKeyLeft,
InputKeyOk,
InputKeyBack}, //ViewPortOrientationHorizontal
{InputKeyDown,
InputKeyUp,
InputKeyLeft,
InputKeyRight,
InputKeyOk,
InputKeyBack}, //ViewPortOrientationHorizontalFlip
{InputKeyRight,
InputKeyLeft,
InputKeyDown,
InputKeyUp,
InputKeyOk,
InputKeyBack}, //ViewPortOrientationVertical
{InputKeyLeft,
InputKeyRight,
InputKeyUp,
InputKeyDown,
InputKeyOk,
InputKeyBack}, //ViewPortOrientationVerticalFlip
};
static void view_port_remap_buttons_horizontal_flip(InputEvent* event) {
switch(event->key) {
case InputKeyUp:
event->key = InputKeyDown;
break;
case InputKeyDown:
event->key = InputKeyUp;
break;
case InputKeyRight:
event->key = InputKeyLeft;
break;
case InputKeyLeft:
event->key = InputKeyRight;
break;
default:
break;
}
// Remaps directional pad buttons on Flipper based on ViewPort orientation
static void view_port_map_input(InputEvent* event, ViewPortOrientation orientation) {
furi_assert(orientation < ViewPortOrientationMAX && event->key < InputKeyMAX);
event->key = view_port_input_mapping[orientation][event->key];
}
static void view_port_setup_canvas_orientation(const ViewPort* view_port, Canvas* canvas) {
@@ -170,19 +160,7 @@ void view_port_input(ViewPort* view_port, InputEvent* event) {
if(view_port->input_callback) {
ViewPortOrientation orientation = view_port_get_orientation(view_port);
switch(orientation) {
case ViewPortOrientationHorizontalFlip:
view_port_remap_buttons_horizontal_flip(event);
break;
case ViewPortOrientationVertical:
view_port_remap_buttons_vertical(event);
break;
case ViewPortOrientationVerticalFlip:
view_port_remap_buttons_vertical_flip(event);
break;
default:
break;
}
view_port_map_input(event, orientation);
view_port->input_callback(event, view_port->input_callback_context);
}
}

View File

@@ -19,6 +19,7 @@ typedef enum {
ViewPortOrientationHorizontalFlip,
ViewPortOrientationVertical,
ViewPortOrientationVerticalFlip,
ViewPortOrientationMAX, /**< Special value, don't use it */
} ViewPortOrientation;
/** ViewPort Draw callback

View File

@@ -60,8 +60,9 @@ const char* input_get_type_name(InputType type) {
return "Long";
case InputTypeRepeat:
return "Repeat";
default:
return "Unknown";
}
return "Unknown";
}
int32_t input_srv(void* p) {

View File

@@ -22,6 +22,7 @@ typedef enum {
InputTypeShort, /**< Short event, emitted after InputTypeRelease done withing INPUT_LONG_PRESS interval */
InputTypeLong, /**< Long event, emmited after INPUT_LONG_PRESS interval, asynchronouse to InputTypeRelease */
InputTypeRepeat, /**< Repeat event, emmited with INPUT_REPEATE_PRESS period after InputTypeLong event */
InputTypeMAX, /**< Special value for exceptional */
} InputType;
/** Input Event, dispatches with FuriPubSub */

View File

@@ -22,7 +22,7 @@ static const uint8_t reset_blink_mask = 1 << 6;
void notification_vibro_on();
void notification_vibro_off();
void notification_sound_on(float pwm, float freq);
void notification_sound_on(float freq, float volume);
void notification_sound_off();
uint8_t notification_settings_get_display_brightness(NotificationApp* app, uint8_t value);

View File

@@ -138,6 +138,41 @@ static void rpc_system_storage_info_process(const PB_Main* request, void* contex
furi_record_close(RECORD_STORAGE);
}
static void rpc_system_storage_timestamp_process(const PB_Main* request, void* context) {
furi_assert(request);
furi_assert(context);
furi_assert(request->which_content == PB_Main_storage_timestamp_request_tag);
FURI_LOG_D(TAG, "Timestamp");
RpcStorageSystem* rpc_storage = context;
RpcSession* session = rpc_storage->session;
furi_assert(session);
rpc_system_storage_reset_state(rpc_storage, session, true);
PB_Main* response = malloc(sizeof(PB_Main));
response->command_id = request->command_id;
Storage* fs_api = furi_record_open(RECORD_STORAGE);
const char* path = request->content.storage_timestamp_request.path;
uint32_t timestamp = 0;
FS_Error error = storage_common_timestamp(fs_api, path, &timestamp);
response->command_status = rpc_system_storage_get_error(error);
response->which_content = PB_Main_empty_tag;
if(error == FSE_OK) {
response->which_content = PB_Main_storage_timestamp_response_tag;
response->content.storage_timestamp_response.timestamp = timestamp;
}
rpc_send_and_release(session, response);
free(response);
furi_record_close(RECORD_STORAGE);
}
static void rpc_system_storage_stat_process(const PB_Main* request, void* context) {
furi_assert(request);
furi_assert(context);
@@ -405,6 +440,10 @@ static void rpc_system_storage_write_process(const PB_Main* request, void* conte
if(!fs_operation_success) {
send_response = true;
command_status = rpc_system_storage_get_file_error(file);
if(command_status == PB_CommandStatus_OK) {
// Report errors not handled by underlying APIs
command_status = PB_CommandStatus_ERROR_STORAGE_INTERNAL;
}
}
if(send_response) {
@@ -668,6 +707,9 @@ void* rpc_system_storage_alloc(RpcSession* session) {
rpc_handler.message_handler = rpc_system_storage_info_process;
rpc_add_handler(session, PB_Main_storage_info_request_tag, &rpc_handler);
rpc_handler.message_handler = rpc_system_storage_timestamp_process;
rpc_add_handler(session, PB_Main_storage_timestamp_request_tag, &rpc_handler);
rpc_handler.message_handler = rpc_system_storage_stat_process;
rpc_add_handler(session, PB_Main_storage_stat_request_tag, &rpc_handler);

View File

@@ -39,6 +39,7 @@ Storage* storage_app_alloc() {
for(uint8_t i = 0; i < STORAGE_COUNT; i++) {
storage_data_init(&app->storage[i]);
storage_data_timestamp(&app->storage[i]);
}
#ifndef FURI_RAM_EXEC

View File

@@ -177,6 +177,16 @@ bool storage_dir_rewind(File* file);
/******************* Common Functions *******************/
/** Retrieves unix timestamp of last access
*
* @param storage The storage instance
* @param path path to file/directory
* @param timestamp the timestamp pointer
*
* @return FS_Error operation result
*/
FS_Error storage_common_timestamp(Storage* storage, const char* path, uint32_t* timestamp);
/** Retrieves information about a file/directory
* @param app pointer to the api
* @param path path to file/directory

View File

@@ -32,6 +32,7 @@ static void storage_cli_print_usage() {
printf("\tmkdir\t - creates a new directory\r\n");
printf("\tmd5\t - md5 hash of the file\r\n");
printf("\tstat\t - info about file or dir\r\n");
printf("\ttimestamp\t - last modification timestamp\r\n");
};
static void storage_cli_print_error(FS_Error error) {
@@ -386,6 +387,22 @@ static void storage_cli_stat(Cli* cli, FuriString* path) {
furi_record_close(RECORD_STORAGE);
}
static void storage_cli_timestamp(Cli* cli, FuriString* path) {
UNUSED(cli);
Storage* api = furi_record_open(RECORD_STORAGE);
uint32_t timestamp = 0;
FS_Error error = storage_common_timestamp(api, furi_string_get_cstr(path), &timestamp);
if(error != FSE_OK) {
printf("Invalid arguments\r\n");
} else {
printf("Timestamp %lu\r\n", timestamp);
}
furi_record_close(RECORD_STORAGE);
}
static void storage_cli_copy(Cli* cli, FuriString* old_path, FuriString* args) {
UNUSED(cli);
Storage* api = furi_record_open(RECORD_STORAGE);
@@ -578,6 +595,11 @@ void storage_cli(Cli* cli, FuriString* args, void* context) {
break;
}
if(furi_string_cmp_str(cmd, "timestamp") == 0) {
storage_cli_timestamp(cli, path);
break;
}
storage_cli_print_usage();
} while(false);

View File

@@ -354,6 +354,16 @@ bool storage_dir_rewind(File* file) {
/****************** COMMON ******************/
FS_Error storage_common_timestamp(Storage* storage, const char* path, uint32_t* timestamp) {
S_API_PROLOGUE;
SAData data = {.ctimestamp = {.path = path, .timestamp = timestamp}};
S_API_MESSAGE(StorageCommandCommonTimestamp);
S_API_EPILOGUE;
return S_RETURN_ERROR;
}
FS_Error storage_common_stat(Storage* storage, const char* path, FileInfo* fileinfo) {
S_API_PROLOGUE;

View File

@@ -82,6 +82,14 @@ const char* storage_data_status_text(StorageData* storage) {
return result;
}
void storage_data_timestamp(StorageData* storage) {
storage->timestamp = furi_hal_rtc_get_timestamp();
}
uint32_t storage_data_get_timestamp(StorageData* storage) {
return storage->timestamp;
}
/****************** storage glue ******************/
bool storage_has_file(const File* file, StorageData* storage_data) {

View File

@@ -42,6 +42,8 @@ bool storage_data_lock(StorageData* storage);
bool storage_data_unlock(StorageData* storage);
StorageStatus storage_data_status(StorageData* storage);
const char* storage_data_status_text(StorageData* storage);
void storage_data_timestamp(StorageData* storage);
uint32_t storage_data_get_timestamp(StorageData* storage);
LIST_DEF(
StorageFileList,
@@ -58,6 +60,7 @@ struct StorageData {
FuriMutex* mutex;
StorageStatus status;
StorageFileList_t files;
uint32_t timestamp;
};
bool storage_has_file(const File* file, StorageData* storage_data);

View File

@@ -1,5 +1,6 @@
#pragma once
#include <furi.h>
#include <furi_hal.h>
#include <gui/gui.h>
#include "storage_glue.h"
#include "storage_sd_api.h"

View File

@@ -42,6 +42,11 @@ typedef struct {
uint16_t name_length;
} SADataDRead;
typedef struct {
const char* path;
uint32_t* timestamp;
} SADataCTimestamp;
typedef struct {
const char* path;
FileInfo* fileinfo;
@@ -78,6 +83,7 @@ typedef union {
SADataDOpen dopen;
SADataDRead dread;
SADataCTimestamp ctimestamp;
SADataCStat cstat;
SADataCFSInfo cfsinfo;
@@ -112,6 +118,7 @@ typedef enum {
StorageCommandDirClose,
StorageCommandDirRead,
StorageCommandDirRewind,
StorageCommandCommonTimestamp,
StorageCommandCommonStat,
StorageCommandCommonRemove,
StorageCommandCommonMkDir,

View File

@@ -114,6 +114,9 @@ bool storage_process_file_open(
if(storage_path_already_open(real_path, storage->files)) {
file->error_id = FSE_ALREADY_OPEN;
} else {
if(access_mode & FSAM_WRITE) {
storage_data_timestamp(storage);
}
storage_push_storage_file(file, real_path, type, storage);
FS_CALL(storage, file.open(storage, file, remove_vfs(path), access_mode, open_mode));
}
@@ -166,6 +169,7 @@ static uint16_t storage_process_file_write(
if(storage == NULL) {
file->error_id = FSE_INVALID_PARAMETER;
} else {
storage_data_timestamp(storage);
FS_CALL(storage, file.write(storage, file, buff, bytes_to_write));
}
@@ -209,6 +213,7 @@ static bool storage_process_file_truncate(Storage* app, File* file) {
if(storage == NULL) {
file->error_id = FSE_INVALID_PARAMETER;
} else {
storage_data_timestamp(storage);
FS_CALL(storage, file.truncate(storage, file));
}
@@ -222,6 +227,7 @@ static bool storage_process_file_sync(Storage* app, File* file) {
if(storage == NULL) {
file->error_id = FSE_INVALID_PARAMETER;
} else {
storage_data_timestamp(storage);
FS_CALL(storage, file.sync(storage, file));
}
@@ -332,6 +338,21 @@ bool storage_process_dir_rewind(Storage* app, File* file) {
/******************* Common FS Functions *******************/
static FS_Error
storage_process_common_timestamp(Storage* app, const char* path, uint32_t* timestamp) {
FS_Error ret = FSE_OK;
StorageType type = storage_get_type_by_path(app, path);
if(storage_type_is_not_valid(type)) {
ret = FSE_INVALID_NAME;
} else {
StorageData* storage = storage_get_storage_by_type(app, type);
*timestamp = storage_data_get_timestamp(storage);
}
return ret;
}
static FS_Error storage_process_common_stat(Storage* app, const char* path, FileInfo* fileinfo) {
FS_Error ret = FSE_OK;
StorageType type = storage_get_type_by_path(app, path);
@@ -366,6 +387,7 @@ static FS_Error storage_process_common_remove(Storage* app, const char* path) {
break;
}
storage_data_timestamp(storage);
FS_CALL(storage, common.remove(storage, remove_vfs(path)));
} while(false);
@@ -382,6 +404,7 @@ static FS_Error storage_process_common_mkdir(Storage* app, const char* path) {
ret = FSE_INVALID_NAME;
} else {
StorageData* storage = storage_get_storage_by_type(app, type);
storage_data_timestamp(storage);
FS_CALL(storage, common.mkdir(storage, remove_vfs(path)));
}
@@ -417,6 +440,7 @@ static FS_Error storage_process_sd_format(Storage* app) {
ret = FSE_NOT_READY;
} else {
ret = sd_format_card(&app->storage[ST_EXT]);
storage_data_timestamp(&app->storage[ST_EXT]);
}
return ret;
@@ -429,6 +453,7 @@ static FS_Error storage_process_sd_unmount(Storage* app) {
ret = FSE_NOT_READY;
} else {
sd_unmount_card(&app->storage[ST_EXT]);
storage_data_timestamp(&app->storage[ST_EXT]);
}
return ret;
@@ -541,6 +566,10 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) {
message->return_data->bool_value =
storage_process_dir_rewind(app, message->data->file.file);
break;
case StorageCommandCommonTimestamp:
message->return_data->error_value = storage_process_common_timestamp(
app, message->data->ctimestamp.path, message->data->ctimestamp.timestamp);
break;
case StorageCommandCommonStat:
message->return_data->error_value = storage_process_common_stat(
app, message->data->cstat.path, message->data->cstat.fileinfo);

View File

@@ -90,6 +90,7 @@ static bool sd_mount_card(StorageData* storage, bool notify) {
}
}
storage_data_timestamp(storage);
storage_data_unlock(storage);
return result;