Merge branch 'Flipper-XFW:dev' into dev

This commit is contained in:
Sil
2023-07-24 17:22:24 +02:00
committed by GitHub
454 changed files with 299 additions and 98 deletions

View File

@@ -32,11 +32,12 @@ static void xtreme_app_scene_interface_lockscreen_bad_pins_format_changed(Variab
app->save_settings = true;
}
static void xtreme_app_scene_interface_lockscreen_pin_unlock_from_app_changed(VariableItem* item) {
static void
xtreme_app_scene_interface_lockscreen_allow_locked_rpc_commands_changed(VariableItem* item) {
XtremeApp* app = variable_item_get_context(item);
bool value = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
XTREME_SETTINGS()->pin_unlock_from_app = value;
XTREME_SETTINGS()->allow_locked_rpc_commands = value;
app->save_settings = true;
}
@@ -107,13 +108,13 @@ void xtreme_app_scene_interface_lockscreen_on_enter(void* context) {
item = variable_item_list_add(
var_item_list,
"PIN Unlock From App",
"Allow RPC while locked",
2,
xtreme_app_scene_interface_lockscreen_pin_unlock_from_app_changed,
xtreme_app_scene_interface_lockscreen_allow_locked_rpc_commands_changed,
app);
variable_item_set_current_value_index(item, xtreme_settings->pin_unlock_from_app);
variable_item_set_current_value_index(item, xtreme_settings->allow_locked_rpc_commands);
variable_item_set_current_value_text(
item, xtreme_settings->pin_unlock_from_app ? "ON" : "OFF");
item, xtreme_settings->allow_locked_rpc_commands ? "ON" : "OFF");
item = variable_item_list_add(
var_item_list,

View File

@@ -216,19 +216,9 @@ static void bt_rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t byt
}
}
// Called from GAP thread
static bool bt_on_gap_event_callback(GapEvent event, void* context) {
furi_assert(context);
Bt* bt = context;
bool ret = false;
bt->pin = 0;
if(event.type == GapEventTypeConnected) {
// Update status bar
bt->status = BtStatusConnected;
BtMessage message = {.type = BtMessageTypeUpdateStatus};
furi_check(
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
// Open BT Connection
void bt_open_rpc_connection(Bt* bt) {
if(!bt->rpc_session && bt->status == BtStatusConnected) {
// Clear BT_RPC_EVENT_DISCONNECTED because it might be set from previous session
furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
if(bt->profile == BtProfileSerial) {
@@ -247,6 +237,33 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
FURI_LOG_W(TAG, "RPC is busy, failed to open new session");
}
}
}
}
void bt_close_rpc_connection(Bt* bt) {
if(bt->profile == BtProfileSerial && bt->rpc_session) {
FURI_LOG_I(TAG, "Close RPC connection");
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
rpc_session_close(bt->rpc_session);
furi_hal_bt_serial_set_event_callback(0, NULL, NULL);
bt->rpc_session = NULL;
}
}
// Called from GAP thread
static bool bt_on_gap_event_callback(GapEvent event, void* context) {
furi_assert(context);
Bt* bt = context;
bool ret = false;
bt->pin = 0;
if(event.type == GapEventTypeConnected) {
// Update status bar
bt->status = BtStatusConnected;
BtMessage message = {.type = BtMessageTypeUpdateStatus};
furi_check(
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
bt_open_rpc_connection(bt);
// Update battery level
PowerInfo info;
power_get_info(bt->power, &info);
@@ -323,16 +340,6 @@ static void bt_show_warning(Bt* bt, const char* text) {
dialog_message_show(bt->dialogs, bt->dialog_message);
}
static void bt_close_rpc_connection(Bt* bt) {
if(bt->profile == BtProfileSerial && bt->rpc_session) {
FURI_LOG_I(TAG, "Close RPC connection");
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
rpc_session_close(bt->rpc_session);
furi_hal_bt_serial_set_event_callback(0, NULL, NULL);
bt->rpc_session = NULL;
}
}
static void bt_change_profile(Bt* bt, BtMessage* message) {
if(furi_hal_bt_is_ble_gatt_gap_supported()) {
bt_settings_load(&bt->bt_settings);

View File

@@ -99,6 +99,19 @@ void bt_disable_peer_key_update(Bt* bt);
*/
void bt_enable_peer_key_update(Bt* bt);
/**
*
* (Probably bad) way of opening the RPC connection, everywhereTM
*/
void bt_open_rpc_connection(Bt* bt);
/**
*
* Closing the RPC connection, everywhereTM
*/
void bt_close_rpc_connection(Bt* bt);
#ifdef __cplusplus
}
#endif

View File

@@ -14,7 +14,7 @@
#include <xtreme.h>
#define ANIMATION_META_FILE "meta.txt"
#define TAG "AnimationStorage"
char ANIMATION_DIR[26 /*"/ext/dolphin_custom//Anims"*/ + XTREME_ASSETS_PACK_NAME_LEN + 1];
char ANIMATION_DIR[26 /*"/ext/asset_packs//Anims"*/ + XTREME_ASSETS_PACK_NAME_LEN + 1];
char ANIMATION_MANIFEST_FILE[sizeof(ANIMATION_DIR) + 13 /*"/manifest.txt"*/];
static void animation_storage_free_bubbles(BubbleAnimation* animation);

View File

@@ -242,6 +242,11 @@ void desktop_lock(Desktop* desktop, bool pin_lock) {
Cli* cli = furi_record_open(RECORD_CLI);
cli_session_close(cli);
furi_record_close(RECORD_CLI);
if(!XTREME_SETTINGS()->allow_locked_rpc_commands) {
Bt* bt = furi_record_open(RECORD_BT);
bt_close_rpc_connection(bt);
furi_record_close(RECORD_BT);
}
}
desktop_auto_lock_inhibit(desktop);
@@ -270,6 +275,10 @@ void desktop_unlock(Desktop* desktop) {
furi_record_close(RECORD_CLI);
}
Bt* bt = furi_record_open(RECORD_BT);
bt_open_rpc_connection(bt);
furi_record_close(RECORD_BT);
DesktopStatus status = {.locked = false};
furi_pubsub_publish(desktop->status_pubsub, &status);
}
@@ -435,9 +444,7 @@ bool desktop_api_is_locked(Desktop* instance) {
void desktop_api_unlock(Desktop* instance) {
furi_assert(instance);
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock) || XTREME_SETTINGS()->pin_unlock_from_app) {
view_dispatcher_send_custom_event(instance->view_dispatcher, DesktopLockedEventUnlocked);
}
view_dispatcher_send_custom_event(instance->view_dispatcher, DesktopLockedEventUnlocked);
}
FuriPubSub* desktop_api_get_status_pubsub(Desktop* instance) {

View File

@@ -1,4 +1,4 @@
#include "text_input.h"
#include "text_input_i.h"
#include <gui/elements.h>
#include <assets_icons.h>
#include <furi.h>
@@ -51,7 +51,7 @@ static const uint8_t keyboard_count = 2;
#define ENTER_KEY '\r'
#define BACKSPACE_KEY '\b'
#define SWITCH_KEYBOARD_KEY 0xfe
#define SWITCH_KEYBOARD_KEY '\t'
static const TextInputKey keyboard_keys_row_1[] = {
{'q', 1, 8},
@@ -490,7 +490,7 @@ static void text_input_handle_ok(TextInput* text_input, TextInputModel* model, I
}
}
static bool text_input_view_input_callback(InputEvent* event, void* context) {
bool text_input_view_input_callback(InputEvent* event, void* context) {
TextInput* text_input = context;
furi_assert(text_input);
@@ -811,3 +811,52 @@ void text_input_set_header_text(TextInput* text_input, const char* text) {
with_view_model(
text_input->view, TextInputModel * model, { model->header = text; }, true);
}
bool text_input_insert_character(TextInput* text_input, char chr) {
if(chr == 0x1b) { // Arrow escape code = Select input row
with_view_model(
text_input->view,
TextInputModel * model,
{
model->cursor_select = true;
model->clear_default_text = false;
model->selected_row = 0;
},
true);
return false; // Don't consume so CLI gives arrow input
}
if(chr == 0x01) { // Ctrl A = Select all text
with_view_model(
text_input->view, TextInputModel * model, { model->clear_default_text = true; }, true);
return true;
}
for(size_t k = 0; k < keyboard_count; k++) {
const Keyboard* keyboard = keyboards[k];
for(size_t r = 0; r < keyboard_row_count; r++) {
const TextInputKey* row = get_row(keyboard, r);
uint8_t size = get_row_size(keyboard, r);
for(size_t key = 0; key < size; key++) {
char lower = row[key].text;
char upper = char_to_uppercase(lower);
if(chr == lower || chr == upper) {
with_view_model(
text_input->view,
TextInputModel * model,
{
model->cursor_select = false;
model->selected_keyboard = k;
model->selected_row = r;
model->selected_column = key;
bool shift = (chr == upper) != (model->clear_default_text ||
strlen(model->text_buffer) == 0);
text_input_handle_ok(
text_input, model, shift ? InputTypeLong : InputTypeShort);
},
true);
return true;
}
}
}
}
return false;
}

View File

@@ -89,6 +89,8 @@ void* text_input_get_validator_callback_context(TextInput* text_input);
*/
void text_input_set_header_text(TextInput* text_input, const char* text);
bool text_input_insert_character(TextInput* text_input, char c);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,5 @@
#pragma once
#include "text_input.h"
bool text_input_view_input_callback(InputEvent* event, void* context);

View File

@@ -68,6 +68,23 @@ const char* input_get_type_name(InputType type) {
}
}
void input_fake_event(Input* input, InputKey key, InputType type) {
bool wrap = type == InputTypeShort || type == InputTypeLong;
InputEvent event;
event.key = key;
if(wrap) {
event.type = InputTypePress;
furi_pubsub_publish(input->event_pubsub, &event);
}
event.type = type;
furi_pubsub_publish(input->event_pubsub, &event);
if(wrap) {
event.type = InputTypeRelease;
furi_pubsub_publish(input->event_pubsub, &event);
}
}
int32_t input_srv(void* p) {
UNUSED(p);
input = malloc(sizeof(Input));

View File

@@ -3,6 +3,10 @@
#include <furi.h>
#include <cli/cli.h>
#include <toolbox/args.h>
#include <gui/view_i.h>
#include <gui/view_port_i.h>
#include <gui/view_dispatcher_i.h>
#include <gui/modules/text_input_i.h>
static void input_cli_usage() {
printf("Usage:\r\n");
@@ -10,6 +14,7 @@ static void input_cli_usage() {
printf("Cmd list:\r\n");
printf("\tdump\t\t\t - dump input events\r\n");
printf("\tsend <key> <type>\t - send input event\r\n");
printf("\tkeyboard\t\t - read keyboard input and control flipper with it\r\n");
}
static void input_cli_dump_events_callback(const void* value, void* ctx) {
@@ -40,6 +45,82 @@ static void input_cli_dump(Cli* cli, FuriString* args, Input* input) {
furi_message_queue_free(input_queue);
}
static void input_cli_keyboard(Cli* cli, FuriString* args, Input* input) {
UNUSED(args);
Gui* gui = furi_record_open(RECORD_GUI);
printf("Using console keyboard feedback for flipper input\r\n");
printf("\r\nUsage:\r\n");
printf("\tMove = Arrows\r\n");
printf("\tOk = Enter\r\n");
printf("\tHold Ok = Shift + Enter\r\n");
printf("\tBack = Backspace\r\n");
printf("\r\nIn Keyboard:\r\n");
printf("\tType normally on PC Keyboard\r\n");
printf("\tQuit = Ctrl + Q\r\n");
printf("\tSelect All = Ctrl + A\r\n");
printf("\tMove Cursor = Arrows\r\n");
printf("\tSave Text = Enter\r\n");
printf("\r\nPress CTRL+C to stop\r\n");
while(cli_is_connected(cli)) {
char in_chr = cli_getc(cli);
if(in_chr == CliSymbolAsciiETX) break;
InputKey send_key = InputKeyMAX;
InputType send_type = InputTypeShort;
ViewPort* view_port = gui->ongoing_input_view_port;
if(view_port && view_port->input_callback == view_dispatcher_input_callback) {
ViewDispatcher* view_dispatcher = view_port->input_callback_context;
if(view_dispatcher) {
View* view = view_dispatcher->current_view;
if(view && view->input_callback == text_input_view_input_callback) {
TextInput* text_input = view->context;
if(text_input) {
if(in_chr == 0x11) { // Ctrl Q = Close text input
send_key = InputKeyBack;
} else if(text_input_insert_character(text_input, in_chr)) {
continue;
}
}
}
}
}
if(send_key == InputKeyMAX) {
switch(in_chr) {
case CliSymbolAsciiEsc: // Escape code for arrows
if(!cli_read(cli, (uint8_t*)&in_chr, 1) || in_chr != '[') break;
if(!cli_read(cli, (uint8_t*)&in_chr, 1)) break;
if(in_chr >= 'A' && in_chr <= 'D') { // Arrows = Dpad
send_key = in_chr - 'A'; // Arrows in same order as InputKey
}
break;
case CliSymbolAsciiBackspace: // Backspace = Back
send_key = InputKeyBack;
break;
case 0x4d: // Shift Enter = Hold Ok
send_type = InputTypeLong;
/* fall through */
case CliSymbolAsciiCR: // Enter = Ok
send_key = InputKeyOk;
break;
default:
printf("ignoring key: %u\r\n", in_chr);
break;
}
}
if(send_key != InputKeyMAX) {
input_fake_event(input, send_key, send_type);
}
}
furi_record_close(RECORD_GUI);
}
static void input_cli_send_print_usage() {
printf("Invalid arguments. Usage:\r\n");
printf("\tinput send <key> <type>\r\n");
@@ -49,7 +130,8 @@ static void input_cli_send_print_usage() {
static void input_cli_send(Cli* cli, FuriString* args, Input* input) {
UNUSED(cli);
InputEvent event;
InputKey key;
InputType type;
FuriString* key_str;
key_str = furi_string_alloc();
bool parsed = false;
@@ -60,29 +142,29 @@ static void input_cli_send(Cli* cli, FuriString* args, Input* input) {
break;
}
if(!furi_string_cmp(key_str, "up")) {
event.key = InputKeyUp;
key = InputKeyUp;
} else if(!furi_string_cmp(key_str, "down")) {
event.key = InputKeyDown;
key = InputKeyDown;
} else if(!furi_string_cmp(key_str, "left")) {
event.key = InputKeyLeft;
key = InputKeyLeft;
} else if(!furi_string_cmp(key_str, "right")) {
event.key = InputKeyRight;
key = InputKeyRight;
} else if(!furi_string_cmp(key_str, "ok")) {
event.key = InputKeyOk;
key = InputKeyOk;
} else if(!furi_string_cmp(key_str, "back")) {
event.key = InputKeyBack;
key = InputKeyBack;
} else {
break;
}
// Parse Type
if(!furi_string_cmp(args, "press")) {
event.type = InputTypePress;
type = InputTypePress;
} else if(!furi_string_cmp(args, "release")) {
event.type = InputTypeRelease;
type = InputTypeRelease;
} else if(!furi_string_cmp(args, "short")) {
event.type = InputTypeShort;
type = InputTypeShort;
} else if(!furi_string_cmp(args, "long")) {
event.type = InputTypeLong;
type = InputTypeLong;
} else {
break;
}
@@ -90,7 +172,7 @@ static void input_cli_send(Cli* cli, FuriString* args, Input* input) {
} while(false);
if(parsed) { //-V547
furi_pubsub_publish(input->event_pubsub, &event);
input_fake_event(input, key, type);
} else {
input_cli_send_print_usage();
}
@@ -113,6 +195,10 @@ void input_cli(Cli* cli, FuriString* args, void* context) {
input_cli_dump(cli, args, input);
break;
}
if(furi_string_cmp_str(cmd, "keyboard") == 0) {
input_cli_keyboard(cli, args, input);
break;
}
if(furi_string_cmp_str(cmd, "send") == 0) {
input_cli_send(cli, args, input);
break;

View File

@@ -46,3 +46,5 @@ void input_isr(void* _ctx);
/** Input CLI command handler */
void input_cli(Cli* cli, FuriString* args, void* context);
void input_fake_event(Input* input, InputKey key, InputType type);

View File

@@ -338,9 +338,6 @@ Power* power_alloc() {
power->settings_events_subscription =
furi_pubsub_subscribe(power->settings_events, power_shutdown_time_changed_callback, power);
power->input_events_pubsub = furi_record_open(RECORD_INPUT_EVENTS);
power->input_events_subscription = NULL;
// State initialization
power->state = PowerStateNotCharging;
power->battery_low = false;

View File

@@ -9,11 +9,13 @@
#include <portmacro.h>
#include <furi.h>
#include <furi_hal.h>
#include <cli/cli.h>
#include <stdint.h>
#include <stdio.h>
#include <m-dict.h>
#include <xtreme.h>
#define TAG "RpcSrv"
@@ -363,41 +365,47 @@ static void rpc_session_thread_state_callback(FuriThreadState thread_state, void
}
RpcSession* rpc_session_open(Rpc* rpc, RpcOwner owner) {
furi_assert(rpc);
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock) ||
XTREME_SETTINGS()->allow_locked_rpc_commands) {
furi_assert(rpc);
RpcSession* session = malloc(sizeof(RpcSession));
session->callbacks_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
session->stream = furi_stream_buffer_alloc(RPC_BUFFER_SIZE, 1);
session->rpc = rpc;
session->terminate = false;
session->decode_error = false;
session->owner = owner;
RpcHandlerDict_init(session->handlers);
RpcSession* session = malloc(sizeof(RpcSession));
session->callbacks_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
session->stream = furi_stream_buffer_alloc(RPC_BUFFER_SIZE, 1);
session->rpc = rpc;
session->terminate = false;
session->decode_error = false;
session->owner = owner;
RpcHandlerDict_init(session->handlers);
session->decoded_message = malloc(sizeof(PB_Main));
session->decoded_message->cb_content.funcs.decode = rpc_pb_content_callback;
session->decoded_message->cb_content.arg = session;
session->decoded_message = malloc(sizeof(PB_Main));
session->decoded_message->cb_content.funcs.decode = rpc_pb_content_callback;
session->decoded_message->cb_content.arg = session;
session->system_contexts = malloc(COUNT_OF(rpc_systems) * sizeof(void*));
for(size_t i = 0; i < COUNT_OF(rpc_systems); ++i) {
session->system_contexts[i] = rpc_systems[i].alloc(session);
session->system_contexts = malloc(COUNT_OF(rpc_systems) * sizeof(void*));
for(size_t i = 0; i < COUNT_OF(rpc_systems); ++i) {
session->system_contexts[i] = rpc_systems[i].alloc(session);
}
RpcHandler rpc_handler = {
.message_handler = rpc_close_session_process,
.decode_submessage = NULL,
.context = session,
};
rpc_add_handler(session, PB_Main_stop_session_tag, &rpc_handler);
session->thread =
furi_thread_alloc_ex("RpcSessionWorker", 3072, rpc_session_worker, session);
furi_thread_set_state_context(session->thread, session);
furi_thread_set_state_callback(session->thread, rpc_session_thread_state_callback);
furi_thread_start(session->thread);
return session;
} else {
return NULL;
}
RpcHandler rpc_handler = {
.message_handler = rpc_close_session_process,
.decode_submessage = NULL,
.context = session,
};
rpc_add_handler(session, PB_Main_stop_session_tag, &rpc_handler);
session->thread = furi_thread_alloc_ex("RpcSessionWorker", 3072, rpc_session_worker, session);
furi_thread_set_state_context(session->thread, session);
furi_thread_set_state_callback(session->thread, rpc_session_thread_state_callback);
furi_thread_start(session->thread);
return session;
}
void rpc_session_close(RpcSession* session) {

View File

@@ -29,7 +29,8 @@ static void storage_cli_print_usage() {
"\twrite_chunk\t - read data from cli and append it to file, <args> should contain how many bytes you want to write\r\n");
printf("\tcopy\t - copy file to new file, <args> must contain new path\r\n");
printf("\trename\t - move file to new file, <args> must contain new path\r\n");
printf("\tmigrate\t - \r\n");
printf(
"\tmigrate\t - move folder to new path, renaming already present files by adding numbers to the end\r\n");
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");