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 7, 2022
2 parents fffacfb + 3cdcd64 commit bb81e86
Show file tree
Hide file tree
Showing 78 changed files with 923 additions and 290 deletions.
2 changes: 1 addition & 1 deletion applications/archive/helpers/archive_browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static const char* tab_default_paths[] = {
[ArchiveTabFavorites] = "/any/favorites",
[ArchiveTabIButton] = "/any/ibutton",
[ArchiveTabNFC] = "/any/nfc",
[ArchiveTabSubGhz] = "/any/subghz/saved",
[ArchiveTabSubGhz] = "/any/subghz",
[ArchiveTabLFRFID] = "/any/lfrfid",
[ArchiveTabIrda] = "/any/irda",
[ArchiveTabBrowser] = "/any",
Expand Down
34 changes: 33 additions & 1 deletion applications/bad_usb/bad_usb_app.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "bad_usb_app_i.h"
#include <furi.h>
#include <furi_hal.h>
#include <storage/storage.h>

static bool bad_usb_app_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
Expand All @@ -20,6 +21,24 @@ static void bad_usb_app_tick_event_callback(void* context) {
scene_manager_handle_tick_event(app->scene_manager);
}

static bool bad_usb_check_assets() {
Storage* fs_api = furi_record_open("storage");

File* dir = storage_file_alloc(fs_api);
bool ret = false;

if(storage_dir_open(dir, BAD_USB_APP_PATH_FOLDER)) {
ret = true;
}

storage_dir_close(dir);
storage_file_free(dir);

furi_record_close("storage");

return ret;
}

BadUsbApp* bad_usb_app_alloc() {
BadUsbApp* app = furi_alloc(sizeof(BadUsbApp));

Expand All @@ -41,11 +60,20 @@ BadUsbApp* bad_usb_app_alloc() {

view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);

// Custom Widget
app->widget = widget_alloc();
view_dispatcher_add_view(
app->view_dispatcher, BadUsbAppViewError, widget_get_view(app->widget));

app->bad_usb_view = bad_usb_alloc();
view_dispatcher_add_view(
app->view_dispatcher, BadUsbAppViewWork, bad_usb_get_view(app->bad_usb_view));

scene_manager_next_scene(app->scene_manager, BadUsbAppViewFileSelect);
if(bad_usb_check_assets()) {
scene_manager_next_scene(app->scene_manager, BadUsbSceneFileSelect);
} else {
scene_manager_next_scene(app->scene_manager, BadUsbSceneError);
}

return app;
}
Expand All @@ -58,6 +86,10 @@ void bad_usb_app_free(BadUsbApp* app) {
view_dispatcher_remove_view(app->view_dispatcher, BadUsbAppViewWork);
bad_usb_free(app->bad_usb_view);

// Custom Widget
view_dispatcher_remove_view(app->view_dispatcher, BadUsbAppViewError);
widget_free(app->widget);

// View dispatcher
view_dispatcher_free(app->view_dispatcher);
scene_manager_free(app->scene_manager);
Expand Down
3 changes: 3 additions & 0 deletions applications/bad_usb/bad_usb_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <dialogs/dialogs.h>
#include <notification/notification_messages.h>
#include <gui/modules/variable_item_list.h>
#include <gui/modules/widget.h>
#include "views/bad_usb_view.h"

#define BAD_USB_APP_PATH_FOLDER "/any/badusb"
Expand All @@ -23,13 +24,15 @@ struct BadUsbApp {
SceneManager* scene_manager;
NotificationApp* notifications;
DialogsApp* dialogs;
Widget* widget;

char file_name[BAD_USB_FILE_NAME_LEN + 1];
BadUsb* bad_usb_view;
BadUsbScript* bad_usb_script;
};

typedef enum {
BadUsbAppViewError,
BadUsbAppViewFileSelect,
BadUsbAppViewWork,
} BadUsbAppView;
2 changes: 0 additions & 2 deletions applications/bad_usb/bad_usb_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ static bool ducky_altchar(const char* charcode) {
uint8_t i = 0;
bool state = false;

//TODO: numlock

FURI_LOG_I(WORKER_TAG, "char %s", charcode);

furi_hal_hid_kb_press(KEY_MOD_LEFT_ALT);
Expand Down
1 change: 1 addition & 0 deletions applications/bad_usb/scenes/bad_usb_scene_config.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ADD_SCENE(bad_usb, file_select, FileSelect)
ADD_SCENE(bad_usb, work, Work)
ADD_SCENE(bad_usb, error, Error)
53 changes: 53 additions & 0 deletions applications/bad_usb/scenes/bad_usb_scene_error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "../bad_usb_app_i.h"

typedef enum {
SubghzCustomEventErrorBack,
} BadUsbCustomEvent;

static void
bad_usb_scene_error_event_callback(GuiButtonType result, InputType type, void* context) {
furi_assert(context);
BadUsbApp* app = context;

if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(app->view_dispatcher, SubghzCustomEventErrorBack);
}
}

void bad_usb_scene_error_on_enter(void* context) {
BadUsbApp* app = context;

widget_add_icon_element(app->widget, 0, 0, &I_SDQuestion_35x43);

widget_add_string_multiline_element(
app->widget,
81,
4,
AlignCenter,
AlignTop,
FontSecondary,
"No SD card or\napp data found.\nThis app will not\nwork without\nrequired files.");

widget_add_button_element(
app->widget, GuiButtonTypeLeft, "Back", bad_usb_scene_error_event_callback, app);

view_dispatcher_switch_to_view(app->view_dispatcher, BadUsbAppViewError);
}

bool bad_usb_scene_error_on_event(void* context, SceneManagerEvent event) {
BadUsbApp* app = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventErrorBack) {
view_dispatcher_stop(app->view_dispatcher);
consumed = true;
}
}
return consumed;
}

void bad_usb_scene_error_on_exit(void* context) {
BadUsbApp* app = context;
widget_reset(app->widget);
}
2 changes: 1 addition & 1 deletion applications/bad_usb/scenes/bad_usb_scene_file_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void bad_usb_scene_file_select_on_enter(void* context) {
BadUsbApp* bad_usb = context;

if(bad_usb_file_select(bad_usb)) {
scene_manager_next_scene(bad_usb->scene_manager, BadUsbAppViewWork);
scene_manager_next_scene(bad_usb->scene_manager, BadUsbSceneWork);
} else {
//scene_manager_previous_scene(bad_usb->scene_manager);
view_dispatcher_stop(bad_usb->view_dispatcher);
Expand Down
3 changes: 1 addition & 2 deletions applications/gui/elements.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ void elements_text_box(
line[line_num].height = line_height;
line[line_num].descender = line_descender;
if(total_height_min + line_leading_min > height) {
line_num--;
break;
}
total_height_min += line_leading_min;
Expand Down Expand Up @@ -640,7 +639,7 @@ void elements_text_box(
uint8_t free_pixel_num = height - total_height_min;
uint8_t fill_pixel = 0;
uint8_t j = 1;
line[0].y = line[0].height;
line[0].y = y + line[0].height;
while(fill_pixel < free_pixel_num) {
line[j].y = line[j - 1].y + line[j - 1].leading_min + 1;
fill_pixel++;
Expand Down
46 changes: 23 additions & 23 deletions applications/gui/modules/text_box.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@

struct TextBox {
View* view;
void* context;
TextBoxExitCallback callback;
};

typedef struct {
const char* text;
char* text_pos;
string_t text_formatted;
size_t scroll_pos;
size_t scroll_num;
int32_t scroll_pos;
int32_t scroll_num;
TextBoxFont font;
TextBoxFocus focus;
bool formatted;
} TextBoxModel;

Expand Down Expand Up @@ -52,12 +51,6 @@ static void text_box_process_up(TextBox* text_box) {
});
}

static void text_box_process_back(TextBox* text_box) {
if(text_box->callback) {
text_box->callback(text_box->context);
}
}

static void text_box_insert_endline(Canvas* canvas, TextBoxModel* model) {
size_t i = 0;
size_t line_width = 0;
Expand All @@ -84,8 +77,18 @@ static void text_box_insert_endline(Canvas* canvas, TextBoxModel* model) {
line_num++;
model->text = string_get_cstr(model->text_formatted);
model->text_pos = (char*)model->text;
model->scroll_num = MAX(line_num - 4, 0);
model->scroll_pos = 0;
if(model->focus == TextBoxFocusEnd && line_num > 5) {
// Set text position to 5th line from the end
for(uint8_t i = 0; i < line_num - 5; i++) {
while(*model->text_pos++ != '\n') {
};
}
model->scroll_num = line_num - 4;
model->scroll_pos = line_num - 5;
} else {
model->scroll_num = MAX(line_num - 4, 0);
model->scroll_pos = 0;
}
}

static void text_box_view_draw_callback(Canvas* canvas, void* _model) {
Expand Down Expand Up @@ -119,9 +122,6 @@ static bool text_box_view_input_callback(InputEvent* event, void* context) {
} else if(event->key == InputKeyUp) {
text_box_process_up(text_box);
consumed = true;
} else if(event->key == InputKeyBack) {
text_box_process_back(text_box);
consumed = true;
}
}
return consumed;
Expand Down Expand Up @@ -172,10 +172,9 @@ void text_box_reset(TextBox* text_box) {
model->text = NULL;
string_set_str(model->text_formatted, "");
model->font = TextBoxFontText;
model->focus = TextBoxFocusStart;
return true;
});
text_box->context = NULL;
text_box->callback = NULL;
}

void text_box_set_text(TextBox* text_box, const char* text) {
Expand All @@ -185,6 +184,7 @@ void text_box_set_text(TextBox* text_box, const char* text) {
with_view_model(
text_box->view, (TextBoxModel * model) {
model->text = text;
string_reset(model->text_formatted);
string_reserve(model->text_formatted, strlen(text));
model->formatted = false;
return true;
Expand All @@ -201,12 +201,12 @@ void text_box_set_font(TextBox* text_box, TextBoxFont font) {
});
}

void text_box_set_context(TextBox* text_box, void* context) {
void text_box_set_focus(TextBox* text_box, TextBoxFocus focus) {
furi_assert(text_box);
text_box->context = context;
}

void text_box_set_exit_callback(TextBox* text_box, TextBoxExitCallback callback) {
furi_assert(text_box);
text_box->callback = callback;
with_view_model(
text_box->view, (TextBoxModel * model) {
model->focus = focus;
return true;
});
}
20 changes: 9 additions & 11 deletions applications/gui/modules/text_box.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ extern "C" {

/** TextBox anonymous structure */
typedef struct TextBox TextBox;
typedef void (*TextBoxExitCallback)(void* context);

typedef enum {
TextBoxFontText,
TextBoxFontHex,
} TextBoxFont;

typedef enum {
TextBoxFocusStart,
TextBoxFocusEnd,
} TextBoxFocus;

/** Allocate and initialize text_box
*
* @return TextBox instance
Expand Down Expand Up @@ -60,19 +64,13 @@ void text_box_set_text(TextBox* text_box, const char* text);
*/
void text_box_set_font(TextBox* text_box, TextBoxFont font);

/** Set text_box context
*
* @param text_box TextBox instance
* @param context context pointer
*/
void text_box_set_context(TextBox* text_box, void* context);

/** Set exit callback
/** Set TextBox focus
* @note Use to display from start or from end
*
* @param text_box TextBox instance
* @param callback TextBoxExitCallback callback pointer
* @param focus TextBoxFocus instance
*/
void text_box_set_exit_callback(TextBox* text_box, TextBoxExitCallback callback);
void text_box_set_focus(TextBox* text_box, TextBoxFocus focus);

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions applications/gui/modules/widget.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Widget* widget_alloc() {
return widget;
}

void widget_clear(Widget* widget) {
void widget_reset(Widget* widget) {
furi_assert(widget);

with_view_model(
Expand All @@ -89,7 +89,7 @@ void widget_clear(Widget* widget) {
void widget_free(Widget* widget) {
furi_assert(widget);
// Free all elements
widget_clear(widget);
widget_reset(widget);
// Free elements container
with_view_model(
widget->view, (GuiWidgetModel * model) {
Expand Down
4 changes: 2 additions & 2 deletions applications/gui/modules/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ Widget* widget_alloc();
*/
void widget_free(Widget* widget);

/** Clear Widget
/** Reset Widget
*
* @param widget Widget instance
*/
void widget_clear(Widget* widget);
void widget_reset(Widget* widget);

/** Get Widget view
*
Expand Down
4 changes: 2 additions & 2 deletions applications/ibutton/scene/ibutton_scene_delete_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void iButtonSceneDeleteConfirm::on_exit(iButtonApp* app) {

app->set_text_store("");

widget_clear(widget);
widget_reset(widget);
}

void iButtonSceneDeleteConfirm::widget_callback(
Expand All @@ -91,4 +91,4 @@ void iButtonSceneDeleteConfirm::widget_callback(
}

app->get_view_manager()->send_event(&event);
}
}
2 changes: 1 addition & 1 deletion applications/ibutton/scene/ibutton_scene_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void iButtonSceneInfo::on_exit(iButtonApp* app) {

app->set_text_store("");

widget_clear(widget);
widget_reset(widget);
}

void iButtonSceneInfo::widget_callback(GuiButtonType result, InputType type, void* context) {
Expand Down
Loading

0 comments on commit bb81e86

Please sign in to comment.