Skip to content

Commit

Permalink
show hidden file setting, about screen, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rdefeo committed Mar 30, 2024
1 parent bcb5cc3 commit 7709113
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 43 deletions.
12 changes: 2 additions & 10 deletions actions/action_subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static const SubGhzDevice* action_subghz_get_device(uint32_t* device_ind) {
void action_subghz_tx(void* context, const FuriString* action_path, FuriString* error) {
App* app = context;
const char* file_name = furi_string_get_cstr(action_path);
uint32_t repeat = 1; //
uint32_t repeat = 1; // This is set to 10 in the cli - why?
uint32_t device_ind = app->settings.subghz_use_ext_antenna ? 1 : 0;

FlipperFormat* fff_data_file = flipper_format_file_alloc(app->storage);
Expand Down Expand Up @@ -114,15 +114,6 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
break;
}

// // SUBGHZ_DEVICE_CC1101_INT_NAME = "cc1101_int"
// device = subghz_devices_get_by_name("cc1101_int");
// if(!subghz_devices_is_connect(device)) {
// // power off
// if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
// device = subghz_devices_get_by_name("cc1101_int");
// // device_ind = 0;
// }

if(!flipper_format_file_open_existing(fff_data_file, file_name)) {
FURI_LOG_E(TAG, "Error opening %s", file_name);
ACTION_SET_ERROR("SUBGHZ: Error opening %s", file_name);
Expand Down Expand Up @@ -244,6 +235,7 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
status = subghz_transmitter_deserialize(transmitter, fff_data_file);
if(status != SubGhzProtocolStatusOk) {
FURI_LOG_E(TAG, "Error deserialize protocol");
ACTION_SET_ERROR("SUBGHZ: Protocol error");
is_init_protocol = false;
}
}
Expand Down
Binary file added images/quac.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 11 additions & 3 deletions item.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ ItemsView* item_get_items_view_from_path(void* context, const FuriString* input_
// Handle the app start condition
FuriString* in_path;
if(input_path == NULL) {
in_path = furi_string_alloc_set_str(QUAC_DATA_PATH);
in_path = furi_string_alloc_set_str(APP_DATA_PATH(""));
} else {
in_path = furi_string_alloc_set(input_path);
}
if(furi_string_get_char(in_path, furi_string_size(in_path) - 1) == '/') {
furi_string_left(in_path, furi_string_size(in_path) - 1);
}
const char* cpath = furi_string_get_cstr(in_path);

FURI_LOG_I(TAG, "Reading items from path: %s", cpath);
Expand Down Expand Up @@ -50,10 +53,15 @@ ItemsView* item_get_items_view_from_path(void* context, const FuriString* input_
// FURI_LOG_I(TAG, "> dir_walk: %s", furi_string_get_cstr(path));
const char* cpath = furi_string_get_cstr(path);

// Skip "hidden" files
path_extract_filename(path, filename_tmp, false);
// Always skip our .quac.conf file!
if(!furi_string_cmp_str(filename_tmp, QUAC_SETTINGS_FILENAME)) {
continue;
}

// Skip "hidden" files
char first_char = furi_string_get_char(filename_tmp, 0);
if(first_char == '.') {
if(first_char == '.' && !app->settings.show_hidden) {
// FURI_LOG_I(TAG, ">> skipping hidden file: %s", furi_string_get_cstr(filename_tmp));
continue;
}
Expand Down
4 changes: 4 additions & 0 deletions quac.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ App* app_alloc() {
view_dispatcher_add_view(
app->view_dispatcher, QView_ActionTextInput, text_input_get_view(app->text_input));

app->popup = popup_alloc();
view_dispatcher_add_view(app->view_dispatcher, QView_Popup, popup_get_view(app->popup));

// Storage
app->storage = furi_record_open(RECORD_STORAGE);

Expand All @@ -65,6 +68,7 @@ void app_free(App* app) {
view_dispatcher_remove_view(app->view_dispatcher, QView_Settings);
view_dispatcher_remove_view(app->view_dispatcher, QView_ActionSettings);
view_dispatcher_remove_view(app->view_dispatcher, QView_ActionTextInput);
view_dispatcher_remove_view(app->view_dispatcher, QView_Popup);

action_menu_free(app->action_menu);
variable_item_list_free(app->vil_settings);
Expand Down
12 changes: 9 additions & 3 deletions quac.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <gui/modules/variable_item_list.h>
#include <gui/modules/submenu.h>
#include <gui/modules/text_input.h>
#include <gui/modules/popup.h>
#include <dialogs/dialogs.h>

#include <storage/storage.h>
Expand All @@ -20,12 +21,15 @@
// #pragma GCC optimize("O0")

#define QUAC_NAME "Quac!"
#define QUAC_VERSION "v0.5.0"
#define QUAC_ABOUT \
"Quick Action remote control\n" QUAC_VERSION "\n" \
"github.com/rdefeo/quac"
#define TAG "Quac" // log statement id

// Location of our actions and folders
#define QUAC_PATH "apps_data/quac"
// Full path to actions
#define QUAC_DATA_PATH EXT_PATH(QUAC_PATH)
#define QUAC_SETTINGS_FILENAME ".quac.conf"
#define QUAC_SETTINGS_PATH APP_DATA_PATH(QUAC_SETTINGS_FILENAME)

typedef enum { QUAC_APP_PORTRAIT, QUAC_APP_LANDSCAPE } QuacAppLayout;

Expand All @@ -38,6 +42,7 @@ typedef struct App {
DialogsApp* dialog;
Submenu* sub_menu;
TextInput* text_input;
Popup* popup;

Storage* storage;
NotificationApp* notifications;
Expand All @@ -55,6 +60,7 @@ typedef struct App {
bool show_headers; // Defaults to True
uint32_t rfid_duration; // Defaults to 2500 ms
bool subghz_use_ext_antenna; // Defaults to False
bool show_hidden; // Defaults to False
} settings;

} App;
Expand Down
23 changes: 17 additions & 6 deletions quac_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <flipper_format/flipper_format.h>

// Quac Settings File Info
// "/ext/apps_data/quac/.quac.conf"
#define QUAC_SETTINGS_FILENAME QUAC_DATA_PATH "/.quac.conf"
#define QUAC_SETTINGS_FILE_TYPE "Quac Settings File"
#define QUAC_SETTINGS_FILE_VERSION 1

Expand All @@ -14,6 +12,7 @@ void quac_set_default_settings(App* app) {
app->settings.show_icons = true;
app->settings.show_headers = true;
app->settings.subghz_use_ext_antenna = false;
app->settings.show_hidden = false;
}

void quac_load_settings(App* app) {
Expand All @@ -22,10 +21,10 @@ void quac_load_settings(App* app) {
temp_str = furi_string_alloc();
uint32_t temp_data32 = 0;

FURI_LOG_I(TAG, "SETTINGS: Reading: %s", QUAC_SETTINGS_FILENAME);
FURI_LOG_I(TAG, "SETTINGS: Reading: %s", QUAC_SETTINGS_PATH);
bool successful = false;
do {
if(!flipper_format_file_open_existing(fff_settings, QUAC_SETTINGS_FILENAME)) {
if(!flipper_format_file_open_existing(fff_settings, QUAC_SETTINGS_PATH)) {
FURI_LOG_I(TAG, "SETTINGS: File not found, loading defaults");
break;
}
Expand Down Expand Up @@ -66,7 +65,7 @@ void quac_load_settings(App* app) {
FURI_LOG_E(TAG, "SETTINGS: Missing 'Show Headers'");
break;
}
app->settings.show_headers = (temp_data32 == 0) ? false : true;
app->settings.show_headers = (temp_data32 == 1) ? true : false;

if(!flipper_format_read_uint32(fff_settings, "RFID Duration", &temp_data32, 1)) {
FURI_LOG_E(TAG, "SETTINGS: Missing 'RFID Duration'");
Expand All @@ -80,6 +79,12 @@ void quac_load_settings(App* app) {
}
app->settings.subghz_use_ext_antenna = (temp_data32 == 1) ? true : false;

if(!flipper_format_read_uint32(fff_settings, "Show Hidden", &temp_data32, 1)) {
FURI_LOG_E(TAG, "SETTINGS: Missing 'Show Hidden'");
break;
}
app->settings.show_hidden = (temp_data32 == 1) ? true : false;

successful = true;
} while(false);

Expand All @@ -98,7 +103,7 @@ void quac_save_settings(App* app) {
FURI_LOG_I(TAG, "SETTINGS: Saving");
bool successful = false;
do {
if(!flipper_format_file_open_always(fff_settings, QUAC_SETTINGS_FILENAME)) {
if(!flipper_format_file_open_always(fff_settings, QUAC_SETTINGS_PATH)) {
FURI_LOG_E(TAG, "SETTINGS: Unable to open file for save!!");
break;
}
Expand Down Expand Up @@ -137,6 +142,12 @@ void quac_save_settings(App* app) {
FURI_LOG_E(TAG, "SETTINGS: Failed to write 'SubGHz Ext Antenna'");
break;
}
temp_data32 = app->settings.show_hidden ? 1 : 0;
if(!flipper_format_write_uint32(fff_settings, "Show Hidden", &temp_data32, 1)) {
FURI_LOG_E(TAG, "SETTINGS: Failed to write 'Show Hidden'");
break;
}

successful = true;
} while(false);

Expand Down
41 changes: 41 additions & 0 deletions scenes/scene_about.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <furi.h>

#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include <flipper_application/flipper_application.h>

#include "quac.h"
#include "scenes.h"
#include "scene_about.h"
#include "../actions/action.h"
#include "quac_icons.h"

enum {
SceneActionRenameEvent,
};

void scene_about_callback(void* context) {
App* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, SceneActionRenameEvent);
}

void scene_about_on_enter(void* context) {
App* app = context;

Popup* popup = app->popup;
popup_set_header(popup, QUAC_NAME, 68, 1, AlignCenter, AlignTop);
popup_set_text(popup, QUAC_ABOUT, 0, 15, AlignLeft, AlignTop);
popup_set_icon(popup, 38, 0, &I_quac);
view_dispatcher_switch_to_view(app->view_dispatcher, QView_Popup);
}

bool scene_about_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
UNUSED(event);
return false;
}

void scene_about_on_exit(void* context) {
App* app = context;
popup_reset(app->popup);
}
8 changes: 8 additions & 0 deletions scenes/scene_about.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <gui/scene_manager.h>

// For each scene, implement handler callbacks
void scene_about_on_enter(void* context);
bool scene_about_on_event(void* context, SceneManagerEvent event);
void scene_about_on_exit(void* context);
76 changes: 57 additions & 19 deletions scenes/scene_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@

#include <lib/toolbox/path.h>

typedef enum {
SceneSettingsLayout,
SceneSettingsIcons,
SceneSettingsHeaders,
SceneSettingsRFIDDuration,
SceneSettingsSubGHzExtAnt,
SceneSettingsHidden,
SceneSettingsAbout
} SceneSettingsIndex;

static const char* const layout_text[2] = {"Vert", "Horiz"};
static const uint32_t layout_value[2] = {QUAC_APP_PORTRAIT, QUAC_APP_LANDSCAPE};

static const char* const show_icons_text[2] = {"OFF", "ON"};
static const uint32_t show_icons_value[2] = {false, true};

static const char* const show_headers_text[2] = {"OFF", "ON"};
static const uint32_t show_headers_value[2] = {false, true};
static const char* const show_offon_text[2] = {"OFF", "ON"};
static const uint32_t show_offon_value[2] = {false, true};

#define V_RFID_DURATION_COUNT 8
static const char* const rfid_duration_text[V_RFID_DURATION_COUNT] = {
Expand Down Expand Up @@ -58,15 +65,15 @@ static void scene_settings_layout_changed(VariableItem* item) {
static void scene_settings_show_icons_changed(VariableItem* item) {
App* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, show_icons_text[index]);
app->settings.show_icons = show_icons_value[index];
variable_item_set_current_value_text(item, show_offon_text[index]);
app->settings.show_icons = show_offon_value[index];
}

static void scene_settings_show_headers_changed(VariableItem* item) {
App* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, show_headers_text[index]);
app->settings.show_headers = show_headers_value[index];
variable_item_set_current_value_text(item, show_offon_text[index]);
app->settings.show_headers = show_offon_value[index];
}

static void scene_settings_rfid_duration_changed(VariableItem* item) {
Expand All @@ -83,6 +90,18 @@ static void scene_settings_subghz_ext_changed(VariableItem* item) {
app->settings.subghz_use_ext_antenna = subghz_ext_value[index];
}

static void scene_settings_show_hidden_changed(VariableItem* item) {
App* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, show_offon_text[index]);
app->settings.show_hidden = show_offon_value[index];
}

static void scene_settings_enter_callback(void* context, uint32_t index) {
App* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, index);
}

// For each scene, implement handler callbacks
void scene_settings_on_enter(void* context) {
App* app = context;
Expand All @@ -99,15 +118,15 @@ void scene_settings_on_enter(void* context) {
variable_item_set_current_value_text(item, layout_text[value_index]);

item = variable_item_list_add(vil, "Show Icons", 2, scene_settings_show_icons_changed, app);
value_index = value_index_uint32(app->settings.show_icons, show_icons_value, 2);
value_index = value_index_uint32(app->settings.show_icons, show_offon_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, show_icons_text[value_index]);
variable_item_set_current_value_text(item, show_offon_text[value_index]);

item =
variable_item_list_add(vil, "Show Headers", 2, scene_settings_show_headers_changed, app);
value_index = value_index_uint32(app->settings.show_headers, show_headers_value, 2);
value_index = value_index_uint32(app->settings.show_headers, show_offon_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, show_headers_text[value_index]);
variable_item_set_current_value_text(item, show_offon_text[value_index]);

item = variable_item_list_add(
vil, "RFID Duration", V_RFID_DURATION_COUNT, scene_settings_rfid_duration_changed, app);
Expand All @@ -122,16 +141,35 @@ void scene_settings_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, subghz_ext_text[value_index]);

// TODO: Set Enter callback here - why?? All settings have custom callbacks
// variable_item_list_set_enter_callback(vil, my_cb, app);
item = variable_item_list_add(vil, "Show Hidden", 2, scene_settings_show_hidden_changed, app);
value_index = value_index_uint32(app->settings.show_hidden, show_offon_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, show_offon_text[value_index]);

// Last item is always "About"
item = variable_item_list_add(vil, "About", 1, NULL, NULL);
variable_item_list_set_enter_callback(vil, scene_settings_enter_callback, app);

view_dispatcher_switch_to_view(app->view_dispatcher, QView_Settings);
}
bool scene_settings_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
UNUSED(event);

return false;
bool scene_settings_on_event(void* context, SceneManagerEvent event) {
App* app = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case SceneSettingsAbout:
consumed = true;
FURI_LOG_I(TAG, "About popup");
scene_manager_next_scene(app->scene_manager, QScene_About);
break;
default:
break;
}
}

return consumed;
}

void scene_settings_on_exit(void* context) {
Expand Down
Loading

0 comments on commit 7709113

Please sign in to comment.