Skip to content

Commit

Permalink
upd hex viewer
Browse files Browse the repository at this point in the history
fixes by Willy-JL
  • Loading branch information
xMasterX committed May 15, 2024
1 parent a15380b commit 91b7fb2
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 41 deletions.
9 changes: 4 additions & 5 deletions base_pack/hex_viewer/helpers/hex_viewer_haptic.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include "hex_viewer_haptic.h"
#include "../hex_viewer.h"


void hex_viewer_play_happy_bump(void* context) {
HexViewer* app = context;
if (app->haptic != 1) {
if(app->haptic != 1) {
return;
}
notification_message(app->notification, &sequence_set_vibro_on);
Expand All @@ -14,7 +13,7 @@ void hex_viewer_play_happy_bump(void* context) {

void hex_viewer_play_bad_bump(void* context) {
HexViewer* app = context;
if (app->haptic != 1) {
if(app->haptic != 1) {
return;
}
notification_message(app->notification, &sequence_set_vibro_on);
Expand All @@ -24,10 +23,10 @@ void hex_viewer_play_bad_bump(void* context) {

void hex_viewer_play_long_bump(void* context) {
HexViewer* app = context;
if (app->haptic != 1) {
if(app->haptic != 1) {
return;
}
for (int i = 0; i < 4; i++) {
for(int i = 0; i < 4; i++) {
notification_message(app->notification, &sequence_set_vibro_on);
furi_thread_flags_wait(0, FuriFlagWaitAny, 50);
notification_message(app->notification, &sequence_reset_vibro);
Expand Down
1 change: 0 additions & 1 deletion base_pack/hex_viewer/helpers/hex_viewer_haptic.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ void hex_viewer_play_happy_bump(void* context);
void hex_viewer_play_bad_bump(void* context);

void hex_viewer_play_long_bump(void* context);

12 changes: 6 additions & 6 deletions base_pack/hex_viewer/helpers/hex_viewer_led.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include "hex_viewer_led.h"
#include "../hex_viewer.h"



void hex_viewer_led_set_rgb(void* context, int red, int green, int blue) {
HexViewer* app = context;
if (app->led != 1) {
if(app->led != 1) {
return;
}
NotificationMessage notification_led_message_1;
Expand All @@ -26,14 +24,16 @@ void hex_viewer_led_set_rgb(void* context, int red, int green, int blue) {
NULL,
};
notification_message(app->notification, &notification_sequence);
furi_thread_flags_wait(0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set
furi_thread_flags_wait(
0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set
}

void hex_viewer_led_reset(void* context) {
HexViewer* app = context;
notification_message(app->notification, &sequence_reset_red);
notification_message(app->notification, &sequence_reset_green);
notification_message(app->notification, &sequence_reset_blue);

furi_thread_flags_wait(0, FuriFlagWaitAny, 300); //Delay, prevent removal from RAM before LED value set

furi_thread_flags_wait(
0, FuriFlagWaitAny, 300); //Delay, prevent removal from RAM before LED value set
}
1 change: 0 additions & 1 deletion base_pack/hex_viewer/helpers/hex_viewer_led.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
void hex_viewer_led_set_rgb(void* context, int red, int green, int blue);

void hex_viewer_led_reset(void* context);

5 changes: 2 additions & 3 deletions base_pack/hex_viewer/helpers/hex_viewer_speaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@

void hex_viewer_play_input_sound(void* context) {
HexViewer* app = context;
if (app->speaker != 1) {
if(app->speaker != 1) {
return;
}
float volume = 1.0f;
if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_INPUT, volume);
}

}

void hex_viewer_stop_all_sound(void* context) {
HexViewer* app = context;
if (app->speaker != 1) {
if(app->speaker != 1) {
return;
}
if(furi_hal_speaker_is_mine()) {
Expand Down
20 changes: 13 additions & 7 deletions base_pack/hex_viewer/hex_viewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ HexViewer* hex_viewer_app_alloc() {
view_dispatcher_set_custom_event_callback(
app->view_dispatcher, hex_viewer_custom_event_callback);

app->submenu = submenu_alloc();
app->text_input = text_input_alloc();

// Set defaults, in case no config loaded
app->haptic = 1;
app->speaker = 1;
Expand All @@ -61,6 +58,7 @@ HexViewer* hex_viewer_app_alloc() {
// Load configs
hex_viewer_read_settings(app);

app->submenu = submenu_alloc();
view_dispatcher_add_view(
app->view_dispatcher, HexViewerViewIdMenu, submenu_get_view(app->submenu));

Expand All @@ -70,6 +68,7 @@ HexViewer* hex_viewer_app_alloc() {
HexViewerViewIdStartscreen,
hex_viewer_startscreen_get_view(app->hex_viewer_startscreen));

app->text_input = text_input_alloc();
view_dispatcher_add_view(
app->view_dispatcher, HexViewerViewIdScroll, text_input_get_view(app->text_input));

Expand Down Expand Up @@ -97,12 +96,13 @@ void hex_viewer_app_free(HexViewer* app) {

// View Dispatcher
view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdMenu);
submenu_free(app->submenu);
view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdStartscreen);
hex_viewer_startscreen_free(app->hex_viewer_startscreen);
view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdScroll);
view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdSettings);

submenu_free(app->submenu);
text_input_free(app->text_input);
view_dispatcher_remove_view(app->view_dispatcher, HexViewerViewIdSettings);
variable_item_list_free(app->variable_item_list);

view_dispatcher_free(app->view_dispatcher);
furi_record_close(RECORD_STORAGE);
Expand All @@ -128,7 +128,13 @@ int32_t hex_viewer_app(void* p) {

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

scene_manager_next_scene(app->scene_manager, HexViewerSceneStartscreen);
if(p && strlen(p) && hex_viewer_open_file(app, (const char*)p)) {
hex_viewer_read_file(app);
scene_manager_next_scene(app->scene_manager, HexViewerSceneStartscreen);
} else {
scene_manager_next_scene(app->scene_manager, HexViewerSceneStartscreen);
scene_manager_next_scene(app->scene_manager, HexViewerSceneOpen);
}

furi_hal_power_suppress_charge_enter();

Expand Down
22 changes: 4 additions & 18 deletions base_pack/hex_viewer/scenes/hex_viewer_scene_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const uint32_t settings_value[2] = {
HexViewerSettingsOn,
};


static void hex_viewer_scene_settings_set_haptic(VariableItem* item) {
HexViewer* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
Expand Down Expand Up @@ -85,33 +84,21 @@ void hex_viewer_scene_settings_on_enter(void* context) {

// Vibro on/off
item = variable_item_list_add(
app->variable_item_list,
"Vibro/Haptic:",
2,
hex_viewer_scene_settings_set_haptic,
app);
app->variable_item_list, "Vibro/Haptic:", 2, hex_viewer_scene_settings_set_haptic, app);
value_index = value_index_uint32(app->haptic, haptic_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, haptic_text[value_index]);

// Sound on/off
item = variable_item_list_add(
app->variable_item_list,
"Sound:",
2,
hex_viewer_scene_settings_set_speaker,
app);
app->variable_item_list, "Sound:", 2, hex_viewer_scene_settings_set_speaker, app);
value_index = value_index_uint32(app->speaker, speaker_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, speaker_text[value_index]);

// LED Effects on/off
item = variable_item_list_add(
app->variable_item_list,
"LED FX:",
2,
hex_viewer_scene_settings_set_led,
app);
app->variable_item_list, "LED FX:", 2, hex_viewer_scene_settings_set_led, app);
value_index = value_index_uint32(app->led, led_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, led_text[value_index]);
Expand All @@ -126,7 +113,7 @@ void hex_viewer_scene_settings_on_enter(void* context) {
value_index = value_index_uint32(app->save_settings, settings_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, settings_text[value_index]);

view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerViewIdSettings);
}

Expand All @@ -135,7 +122,6 @@ bool hex_viewer_scene_settings_on_event(void* context, SceneManagerEvent event)
UNUSED(app);
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {

}
return consumed;
}
Expand Down

0 comments on commit 91b7fb2

Please sign in to comment.