Skip to content

Commit

Permalink
Merge branch 'release-candidate' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Feb 1, 2022
2 parents 3e04b73 + 1d5ca45 commit fffacfb
Show file tree
Hide file tree
Showing 512 changed files with 6,524 additions and 2,014 deletions.
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Who owns all the code by default
# Who owns all the fish by default

* @skotopes @DrZlo13

Expand All @@ -8,7 +8,7 @@ applications/accessor/** @skotopes @DrZlo13
applications/loader/** @skotopes @DrZlo13 @gornekich
applications/bt/** @skotopes @DrZlo13
applications/cli/** @skotopes @DrZlo13
applications/dolphin/** @skotopes @DrZlo13 @itsyourbedtime
applications/dolphin/** @skotopes @DrZlo13
applications/gpio-tester/** @skotopes @DrZlo13
applications/gui/** @skotopes @DrZlo13
applications/gui-test/** @skotopes @DrZlo13
Expand Down
6 changes: 6 additions & 0 deletions applications/about/about.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ static DialogMessageButton hw_version_screen(DialogsApp* dialogs, DialogMessage*
furi_hal_version_get_hw_connect(),
my_name ? my_name : "Unknown");

string_cat_printf(buffer, "Serial number:\n");
const uint8_t* uid = furi_hal_version_uid();
for(size_t i = 0; i < furi_hal_version_uid_size(); i++) {
string_cat_printf(buffer, "%02X", uid[i]);
}

dialog_message_set_header(message, "HW Version info:", 0, 0, AlignLeft, AlignTop);
dialog_message_set_text(message, string_get_cstr(buffer), 0, 13, AlignLeft, AlignTop);
result = dialog_message_show(dialogs, message);
Expand Down
1 change: 1 addition & 0 deletions applications/archive/archive_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ struct ArchiveApp {
ArchiveBrowserView* browser;
TextInput* text_input;
char text_store[MAX_NAME_LEN];
char file_extension[MAX_EXT_LEN + 1];
};
1 change: 0 additions & 1 deletion applications/archive/helpers/archive_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ void archive_enter_dir(ArchiveBrowserView* browser, string_t name) {
with_view_model(
browser->view, (ArchiveBrowserViewModel * model) {
model->last_idx = model->idx;
model->last_offset = model->list_offset;
model->idx = 0;
model->depth = CLAMP(model->depth + 1, MAX_DEPTH, 0);
return false;
Expand Down
49 changes: 48 additions & 1 deletion applications/archive/helpers/archive_favorites.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,40 @@ uint16_t archive_favorites_count(void* context) {
return lines;
}

static bool archive_favourites_rescan() {
string_t buffer;
string_init(buffer);
FileWorker* file_worker = file_worker_alloc(true);

bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
if(result) {
while(1) {
if(!file_worker_read_until(file_worker, buffer, '\n')) {
break;
}
if(!string_size(buffer)) {
break;
}

bool file_exists = false;
file_worker_is_file_exist(file_worker, string_get_cstr(buffer), &file_exists);
if(file_exists) {
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(buffer));
}
}
}

string_clear(buffer);

file_worker_close(file_worker);
file_worker_remove(file_worker, ARCHIVE_FAV_PATH);
file_worker_rename(file_worker, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);

file_worker_free(file_worker);

return result;
}

bool archive_favorites_read(void* context) {
furi_assert(context);

Expand All @@ -41,6 +75,8 @@ bool archive_favorites_read(void* context) {
FileInfo file_info;
string_init(buffer);

bool need_refresh = false;

bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);

if(result) {
Expand All @@ -52,13 +88,24 @@ bool archive_favorites_read(void* context) {
break;
}

archive_add_item(browser, &file_info, string_get_cstr(buffer));
bool file_exists = false;
file_worker_is_file_exist(file_worker, string_get_cstr(buffer), &file_exists);

if(file_exists)
archive_add_item(browser, &file_info, string_get_cstr(buffer));
else
need_refresh = true;
string_reset(buffer);
}
}
string_clear(buffer);
file_worker_close(file_worker);
file_worker_free(file_worker);

if(need_refresh) {
archive_favourites_rescan();
}

return result;
}

Expand Down
8 changes: 8 additions & 0 deletions applications/archive/helpers/archive_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ void archive_trim_file_path(char* name, bool ext) {
}
}

void archive_get_file_extension(char* name, char* ext) {
char* dot = strrchr(name, '.');
if(dot == NULL)
*ext = '\0';
else
strncpy(ext, dot, MAX_EXT_LEN);
}

void set_file_type(ArchiveFile_t* file, FileInfo* file_info) {
furi_assert(file);
furi_assert(file_info);
Expand Down
1 change: 1 addition & 0 deletions applications/archive/helpers/archive_files.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ARRAY_DEF(
bool filter_by_extension(FileInfo* file_info, const char* tab_ext, const char* name);
void set_file_type(ArchiveFile_t* file, FileInfo* file_info);
void archive_trim_file_path(char* name, bool ext);
void archive_get_file_extension(char* name, char* ext);
bool archive_get_filenames(void* context, const char* path);
bool archive_dir_empty(void* context, const char* path);
bool archive_read_dir(void* context, const char* path);
Expand Down
12 changes: 11 additions & 1 deletion applications/archive/scenes/archive_scene_rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void archive_scene_rename_on_enter(void* context) {
ArchiveFile_t* current = archive_get_current_file(archive->browser);
strlcpy(archive->text_store, string_get_cstr(current->name), MAX_NAME_LEN);

archive_get_file_extension(archive->text_store, archive->file_extension);
archive_trim_file_path(archive->text_store, true);

text_input_set_header_text(text_input, "Rename:");
Expand All @@ -30,6 +31,10 @@ void archive_scene_rename_on_enter(void* context) {
MAX_TEXT_INPUT_LEN,
false);

ValidatorIsFile* validator_is_file =
validator_is_file_alloc_init(archive_get_path(archive->browser), archive->file_extension);
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);

view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewTextInput);
}

Expand Down Expand Up @@ -74,6 +79,11 @@ bool archive_scene_rename_on_event(void* context, SceneManagerEvent event) {

void archive_scene_rename_on_exit(void* context) {
ArchiveApp* archive = (ArchiveApp*)context;

// Clear view
text_input_clean(archive->text_input);
void* validator_context = text_input_get_validator_callback_context(archive->text_input);
text_input_set_validator(archive->text_input, NULL, NULL);
validator_is_file_free(validator_context);

text_input_reset(archive->text_input);
}
1 change: 1 addition & 0 deletions applications/archive/views/archive_browser_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#define MAX_LEN_PX 110
#define MAX_NAME_LEN 255
#define MAX_EXT_LEN 6
#define FRAME_HEIGHT 12
#define MENU_ITEMS 4
#define MAX_DEPTH 32
Expand Down
2 changes: 1 addition & 1 deletion applications/bad_usb/bad_usb_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void bad_usb_app_free(BadUsbApp* app) {
}

int32_t bad_usb_app(void* p) {
UsbInterface* usb_mode_prev = furi_hal_usb_get_config();
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
furi_hal_usb_set_config(&usb_hid);

BadUsbApp* bad_usb_app = bad_usb_app_alloc();
Expand Down
2 changes: 2 additions & 0 deletions applications/bad_usb/bad_usb_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <furi_hal_usb_hid.h>
#include <storage/storage.h>
#include "bad_usb_script.h"
#include <dolphin/dolphin.h>

#define TAG "BadUSB"
#define WORKER_TAG TAG "Worker"
Expand Down Expand Up @@ -442,6 +443,7 @@ static int32_t bad_usb_worker(void* context) {
if(flags & WorkerEvtEnd) {
break;
} else if(flags & WorkerEvtToggle) { // Start executing script
DOLPHIN_DEED(DolphinDeedBadUsbPlayScript);
delay_val = 0;
bad_usb->buf_len = 0;
bad_usb->st.line_cur = 0;
Expand Down
70 changes: 53 additions & 17 deletions applications/bt/bt_service/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#include "battery_service.h"
#include "bt_keys_storage.h"

#include <applications/notification/notification_messages.h>
#include <notification/notification_messages.h>
#include <gui/elements.h>

#define TAG "BtSrv"

Expand All @@ -29,17 +30,46 @@ static ViewPort* bt_statusbar_view_port_alloc(Bt* bt) {
return statusbar_view_port;
}

static void bt_pin_code_show_event_handler(Bt* bt, uint32_t pin) {
furi_assert(bt);
static void bt_pin_code_view_port_draw_callback(Canvas* canvas, void* context) {
furi_assert(context);
Bt* bt = context;
char pin_code_info[24];
canvas_draw_icon(canvas, 0, 0, &I_BLE_Pairing_128x64);
snprintf(pin_code_info, sizeof(pin_code_info), "Pairing code\n%06ld", bt->pin_code);
elements_multiline_text_aligned(canvas, 64, 4, AlignCenter, AlignTop, pin_code_info);
elements_button_left(canvas, "Quit");
}

static void bt_pin_code_view_port_input_callback(InputEvent* event, void* context) {
furi_assert(context);
Bt* bt = context;
if(event->type == InputTypeShort) {
if(event->key == InputKeyLeft || event->key == InputKeyBack) {
view_port_enabled_set(bt->pin_code_view_port, false);
}
}
}

static ViewPort* bt_pin_code_view_port_alloc(Bt* bt) {
ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, bt_pin_code_view_port_draw_callback, bt);
view_port_input_callback_set(view_port, bt_pin_code_view_port_input_callback, bt);
view_port_enabled_set(view_port, false);
return view_port;
}

static void bt_pin_code_show(Bt* bt, uint32_t pin_code) {
bt->pin_code = pin_code;
notification_message(bt->notification, &sequence_display_on);
string_t pin_str;
dialog_message_set_icon(bt->dialog_message, &I_BLE_Pairing_128x64, 0, 0);
string_init_printf(pin_str, "Pairing code\n%06d", pin);
dialog_message_set_text(
bt->dialog_message, string_get_cstr(pin_str), 64, 4, AlignCenter, AlignTop);
dialog_message_set_buttons(bt->dialog_message, "Quit", NULL, NULL);
dialog_message_show(bt->dialogs, bt->dialog_message);
string_clear(pin_str);
gui_view_port_send_to_front(bt->gui, bt->pin_code_view_port);
view_port_enabled_set(bt->pin_code_view_port, true);
}

static void bt_pin_code_hide(Bt* bt) {
bt->pin_code = 0;
if(view_port_is_enabled(bt->pin_code_view_port)) {
view_port_enabled_set(bt->pin_code_view_port, false);
}
}

static bool bt_pin_code_verify_event_handler(Bt* bt, uint32_t pin) {
Expand Down Expand Up @@ -84,11 +114,14 @@ Bt* bt_alloc() {

// Setup statusbar view port
bt->statusbar_view_port = bt_statusbar_view_port_alloc(bt);
// Pin code view port
bt->pin_code_view_port = bt_pin_code_view_port_alloc(bt);
// Notification
bt->notification = furi_record_open("notification");
// Gui
bt->gui = furi_record_open("gui");
gui_add_view_port(bt->gui, bt->statusbar_view_port, GuiLayerStatusBarLeft);
gui_add_view_port(bt->gui, bt->pin_code_view_port, GuiLayerFullscreen);

// Dialogs
bt->dialogs = furi_record_open("dialogs");
Expand Down Expand Up @@ -162,7 +195,7 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
if(event.type == GapEventTypeConnected) {
// Update status bar
bt->status = BtStatusConnected;
BtMessage message = {.type = BtMessageTypeUpdateStatusbar};
BtMessage message = {.type = BtMessageTypeUpdateStatus};
furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK);
if(bt->profile == BtProfileSerial) {
// Open RPC session
Expand Down Expand Up @@ -192,12 +225,12 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
ret = true;
} else if(event.type == GapEventTypeStartAdvertising) {
bt->status = BtStatusAdvertising;
BtMessage message = {.type = BtMessageTypeUpdateStatusbar};
BtMessage message = {.type = BtMessageTypeUpdateStatus};
furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK);
ret = true;
} else if(event.type == GapEventTypeStopAdvertising) {
bt->status = BtStatusOff;
BtMessage message = {.type = BtMessageTypeUpdateStatusbar};
BtMessage message = {.type = BtMessageTypeUpdateStatus};
furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK);
ret = true;
} else if(event.type == GapEventTypePinCodeShow) {
Expand Down Expand Up @@ -313,9 +346,10 @@ int32_t bt_srv() {
BtMessage message;
while(1) {
furi_check(osMessageQueueGet(bt->message_queue, &message, NULL, osWaitForever) == osOK);
if(message.type == BtMessageTypeUpdateStatusbar) {
// Update statusbar
if(message.type == BtMessageTypeUpdateStatus) {
// Update view ports
bt_statusbar_update(bt);
bt_pin_code_hide(bt);
if(bt->status_changed_cb) {
bt->status_changed_cb(bt->status, bt->status_changed_ctx);
}
Expand All @@ -324,11 +358,13 @@ int32_t bt_srv() {
furi_hal_bt_update_battery_level(message.data.battery_level);
} else if(message.type == BtMessageTypePinCodeShow) {
// Display PIN code
bt_pin_code_show_event_handler(bt, message.data.pin_code);
bt_pin_code_show(bt, message.data.pin_code);
} else if(message.type == BtMessageTypeKeysStorageUpdated) {
bt_save_key_storage(bt);
} else if(message.type == BtMessageTypeSetProfile) {
bt_change_profile(bt, &message);
} else if(message.type == BtMessageTypeForgetBondedDevices) {
bt_delete_key_storage(bt);
}
}
return 0;
Expand Down
7 changes: 7 additions & 0 deletions applications/bt/bt_service/bt.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ bool bt_set_profile(Bt* bt, BtProfile profile);
*/
void bt_set_status_changed_callback(Bt* bt, BtStatusChangedCallback callback, void* context);

/** Forget bonded devices
* @note Leads to wipe ble key storage and deleting bt.keys
*
* @param bt Bt instance
*/
void bt_forget_bonded_devices(Bt* bt);

#ifdef __cplusplus
}
#endif
6 changes: 6 additions & 0 deletions applications/bt/bt_service/bt_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ void bt_set_status_changed_callback(Bt* bt, BtStatusChangedCallback callback, vo
bt->status_changed_cb = callback;
bt->status_changed_ctx = context;
}

void bt_forget_bonded_devices(Bt* bt) {
furi_assert(bt);
BtMessage message = {.type = BtMessageTypeForgetBondedDevices};
furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK);
}
5 changes: 4 additions & 1 deletion applications/bt/bt_service/bt_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
#define BT_API_UNLOCK_EVENT (1UL << 0)

typedef enum {
BtMessageTypeUpdateStatusbar,
BtMessageTypeUpdateStatus,
BtMessageTypeUpdateBatteryLevel,
BtMessageTypePinCodeShow,
BtMessageTypeKeysStorageUpdated,
BtMessageTypeSetProfile,
BtMessageTypeForgetBondedDevices,
} BtMessageType;

typedef union {
Expand All @@ -49,6 +50,8 @@ struct Bt {
NotificationApp* notification;
Gui* gui;
ViewPort* statusbar_view_port;
ViewPort* pin_code_view_port;
uint32_t pin_code;
DialogsApp* dialogs;
DialogMessage* dialog_message;
Power* power;
Expand Down
Loading

0 comments on commit fffacfb

Please sign in to comment.