Skip to content

Commit

Permalink
Settings & Storage for SubGhz Timing
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lee committed Feb 5, 2024
1 parent 6cf5fb9 commit 34a5851
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion helpers/subghz/subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void subghz_send(void* context, const char* path) {
} else {
subghz_tx_start(app->subghz, subghz_txrx_get_fff_data(app->subghz->txrx));
app->state_notifications = SubGhzNotificationStateTx;
furi_thread_flags_wait(0, FuriFlagWaitAny, 500);
furi_thread_flags_wait(0, FuriFlagWaitAny, app->sg_timing);
app->state_notifications = SubGhzNotificationStateIDLE;
subghz_txrx_stop(app->subghz->txrx);

Expand Down
2 changes: 2 additions & 0 deletions helpers/xremote_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void xremote_save_settings(void* context) {
flipper_format_write_uint32(
fff_file, XREMOTE_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1);
flipper_format_write_uint32(fff_file, XREMOTE_SETTINGS_KEY_IR_TIMING, &app->ir_timing, 1);
flipper_format_write_uint32(fff_file, XREMOTE_SETTINGS_KEY_SG_TIMING, &app->sg_timing, 1);

if(!flipper_format_rewind(fff_file)) {
xremote_close_config_file(fff_file);
Expand Down Expand Up @@ -110,6 +111,7 @@ void xremote_read_settings(void* context) {
flipper_format_read_uint32(
fff_file, XREMOTE_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1);
flipper_format_read_uint32(fff_file, XREMOTE_SETTINGS_KEY_IR_TIMING, &app->ir_timing, 1);
flipper_format_read_uint32(fff_file, XREMOTE_SETTINGS_KEY_SG_TIMING, &app->sg_timing, 1);

flipper_format_rewind(fff_file);

Expand Down
1 change: 1 addition & 0 deletions helpers/xremote_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define XREMOTE_SETTINGS_KEY_SPEAKER "Speaker"
#define XREMOTE_SETTINGS_KEY_SAVE_SETTINGS "SaveSettings"
#define XREMOTE_SETTINGS_KEY_IR_TIMING "IRTiming"
#define XREMOTE_SETTINGS_KEY_SG_TIMING "SGTiming"

void xremote_save_settings(void* context);
void xremote_read_settings(void* context);
19 changes: 18 additions & 1 deletion scenes/xremote_scene_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ static void xremote_scene_settings_set_ir_timing(VariableItem* item) {
app->ir_timing = (index * 100);
}

static void xremote_scene_settings_set_sg_timing(VariableItem* item) {
XRemote* app = variable_item_get_context(item);
uint32_t index = variable_item_get_current_value_index(item);

snprintf(app->sg_timing_char, 20, "%lu", (index * 100));
variable_item_set_current_value_text(item, app->sg_timing_char);
app->sg_timing = (index * 100);
}

void xremote_scene_settings_submenu_callback(void* context, uint32_t index) {
XRemote* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, index);
Expand Down Expand Up @@ -121,12 +130,20 @@ void xremote_scene_settings_on_enter(void* context) {

// Set Infrared Timer
item = variable_item_list_add(
app->variable_item_list, "IR Timing in ms:", 30, xremote_scene_settings_set_ir_timing, app);
app->variable_item_list, "IR Time ms", 30, xremote_scene_settings_set_ir_timing, app);

variable_item_set_current_value_index(item, (uint8_t)(app->ir_timing / 100));
snprintf(app->ir_timing_char, 20, "%lu", app->ir_timing);
variable_item_set_current_value_text(item, app->ir_timing_char);

// Set SubGhz Timer
item = variable_item_list_add(
app->variable_item_list, "SubG. Time ms", 30, xremote_scene_settings_set_sg_timing, app);

variable_item_set_current_value_index(item, (uint8_t)(app->sg_timing / 100));
snprintf(app->sg_timing_char, 20, "%lu", app->sg_timing);
variable_item_set_current_value_text(item, app->sg_timing_char);

view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdSettings);
}

Expand Down
2 changes: 2 additions & 0 deletions xremote.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ XRemote* xremote_app_alloc() {
app->transmitting = 0;
app->ir_timing = 1000;
app->ir_timing_char = "1000";
app->sg_timing = 500;
app->sg_timing_char = "500";
app->stop_transmit = false;

// Load configs
Expand Down
2 changes: 2 additions & 0 deletions xremote.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ typedef struct {
uint32_t edit_item;
uint32_t ir_timing;
char* ir_timing_char;
uint32_t sg_timing;
char* sg_timing_char;
bool transmitting;
bool stop_transmit;
char text_store[XREMOTE_TEXT_STORE_NUM][XREMOTE_TEXT_STORE_SIZE + 1];
Expand Down

0 comments on commit 34a5851

Please sign in to comment.