Skip to content

Commit

Permalink
ir apps add support for new settings
Browse files Browse the repository at this point in the history
by Willy-JL
  • Loading branch information
xMasterX committed Apr 4, 2024
1 parent 9313050 commit 999dc95
Show file tree
Hide file tree
Showing 11 changed files with 814 additions and 21 deletions.
674 changes: 674 additions & 0 deletions apps_source_code/ir_intervalometer/LICENSE

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions apps_source_code/ir_intervalometer/application.fam
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
App(
appid="ir_intervalometer",
name="[IR] Intervalometer",
name="IR Intervalometer",
apptype=FlipperAppType.EXTERNAL,
entry_point="flipvalo_app",
requires=["gui"],
stack_size=2 * 1024,
order=20,
fap_icon="intervalometer_10x.png",
fap_icon_assets="icons",
fap_category="Infrared",
fap_author="@Nitepone",
fap_category="Infrared",
fap_description="Intervalometer for Canon, Nikon, and Sony cameras. Uses IR shutter release.",
fap_version="1.2",
fap_weburl="https://github.com/Nitepone/flipper-intervalometer",
fap_version="1.1",
fap_description="This is a simple configurable valometer app for DSLR cameras. Works via Infrared port.",
)
36 changes: 36 additions & 0 deletions apps_source_code/ir_intervalometer/intervalometer.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include <gui/icon.h>
#include <infrared_transmit.h>

#include <infrared/infrared_app.h>
#include <toolbox/saved_struct.h>

#include <input/input.h>

#include <notification/notification.h>
Expand Down Expand Up @@ -628,6 +631,31 @@ int32_t flipvalo_app() {

flipvalo_priv_init(fv_priv);

bool otg_was_enabled = furi_hal_power_is_otg_enabled();
InfraredSettings settings = {0};
saved_struct_load(
INFRARED_SETTINGS_PATH,
&settings,
sizeof(InfraredSettings),
INFRARED_SETTINGS_MAGIC,
INFRARED_SETTINGS_VERSION);
if(settings.tx_pin < FuriHalInfraredTxPinMax) {
furi_hal_infrared_set_tx_output(settings.tx_pin);
if(settings.otg_enabled != otg_was_enabled) {
if(settings.otg_enabled) {
furi_hal_power_enable_otg();
} else {
furi_hal_power_disable_otg();
}
}
} else {
FuriHalInfraredTxPin tx_pin_detected = furi_hal_infrared_detect_tx_output();
furi_hal_infrared_set_tx_output(tx_pin_detected);
if(tx_pin_detected != FuriHalInfraredTxPinInternal) {
furi_hal_power_enable_otg();
}
}

if(!fv_priv->mutex) {
FURI_LOG_E("Flipvalo", "Cannot create mutex\r\n");
ret = 1;
Expand Down Expand Up @@ -724,6 +752,14 @@ int32_t flipvalo_app() {
}
view_port_free(view_port);
}
furi_hal_infrared_set_tx_output(FuriHalInfraredTxPinInternal);
if(furi_hal_power_is_otg_enabled() != otg_was_enabled) {
if(otg_was_enabled) {
furi_hal_power_enable_otg();
} else {
furi_hal_power_disable_otg();
}
}
if(event_queue) {
furi_message_queue_free(event_queue);
}
Expand Down
2 changes: 1 addition & 1 deletion non_catalog_apps/ir_remote/infrared_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static void infrared_remote_clear_buttons(InfraredRemote* remote) {
InfraredButtonArray_reset(remote->buttons);
}

InfraredRemote* infrared_remote_alloc() {
InfraredRemote* infrared_remote_alloc(void) {
InfraredRemote* remote = malloc(sizeof(InfraredRemote));
InfraredButtonArray_init(remote->buttons);
remote->name = furi_string_alloc();
Expand Down
4 changes: 3 additions & 1 deletion non_catalog_apps/ir_remote/infrared_remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

#include "infrared_remote_button.h"

#define IR_REMOTE_PATH EXT_PATH("infrared/remote")

typedef struct InfraredRemote InfraredRemote;

InfraredRemote* infrared_remote_alloc();
InfraredRemote* infrared_remote_alloc(void);
void infrared_remote_free(InfraredRemote* remote);
void infrared_remote_reset(InfraredRemote* remote);

Expand Down
66 changes: 55 additions & 11 deletions non_catalog_apps/ir_remote/infrared_remote_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <dialogs/dialogs.h>
#include <ir_remote_icons.h>

#include <infrared/infrared_app.h>
#include <toolbox/saved_struct.h>

#include <notification/notification.h>
#include <notification/notification_messages.h>

Expand Down Expand Up @@ -109,8 +112,7 @@ static void app_input_callback(InputEvent* input_event, void* ctx) {
furi_message_queue_put(event_queue, input_event, FuriWaitForever);
}

int32_t infrared_remote_app(void* p) {
UNUSED(p);
int32_t infrared_remote_app(char* p) {
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));

// App button string
Expand Down Expand Up @@ -139,18 +141,26 @@ int32_t infrared_remote_app(void* p) {

InputEvent event;

FuriString* map_file = furi_string_alloc();
Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* ff = flipper_format_file_alloc(storage);
if(!storage_file_exists(storage, IR_REMOTE_PATH)) {
storage_common_mkdir(storage, IR_REMOTE_PATH); //Make Folder If dir not exist
}

DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(&browser_options, ".txt", &I_sub1_10px);
FuriString* map_file = furi_string_alloc();
furi_string_set(map_file, "/ext/ir_remote");

bool res = dialog_file_browser_show(dialogs, map_file, map_file, &browser_options);

furi_record_close(RECORD_DIALOGS);
bool res;
if(p && strlen(p)) {
furi_string_set(map_file, p);
res = true;
} else {
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(&browser_options, ".txt", &I_sub1_10px);
browser_options.base_path = IR_REMOTE_PATH;
furi_string_set(map_file, IR_REMOTE_PATH);
res = dialog_file_browser_show(dialogs, map_file, map_file, &browser_options);
furi_record_close(RECORD_DIALOGS);
}

// if user didn't choose anything, free everything and exit
if(!res) {
Expand Down Expand Up @@ -392,6 +402,31 @@ int32_t infrared_remote_app(void* p) {
flipper_format_free(ff);
furi_record_close(RECORD_STORAGE);

bool otg_was_enabled = furi_hal_power_is_otg_enabled();
InfraredSettings settings = {0};
saved_struct_load(
INFRARED_SETTINGS_PATH,
&settings,
sizeof(InfraredSettings),
INFRARED_SETTINGS_MAGIC,
INFRARED_SETTINGS_VERSION);
if(settings.tx_pin < FuriHalInfraredTxPinMax) {
furi_hal_infrared_set_tx_output(settings.tx_pin);
if(settings.otg_enabled != otg_was_enabled) {
if(settings.otg_enabled) {
furi_hal_power_enable_otg();
} else {
furi_hal_power_disable_otg();
}
}
} else {
FuriHalInfraredTxPin tx_pin_detected = furi_hal_infrared_detect_tx_output();
furi_hal_infrared_set_tx_output(tx_pin_detected);
if(tx_pin_detected != FuriHalInfraredTxPinInternal) {
furi_hal_power_enable_otg();
}
}

bool running = true;
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);

Expand Down Expand Up @@ -533,6 +568,15 @@ int32_t infrared_remote_app(void* p) {
}
}

furi_hal_infrared_set_tx_output(FuriHalInfraredTxPinInternal);
if(furi_hal_power_is_otg_enabled() != otg_was_enabled) {
if(otg_was_enabled) {
furi_hal_power_enable_otg();
} else {
furi_hal_power_disable_otg();
}
}

// Free all things
furi_string_free(app->up_button);
furi_string_free(app->down_button);
Expand Down
2 changes: 1 addition & 1 deletion non_catalog_apps/ir_remote/infrared_remote_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct InfraredRemoteButton {
InfraredSignal* signal;
};

InfraredRemoteButton* infrared_remote_button_alloc() {
InfraredRemoteButton* infrared_remote_button_alloc(void) {
InfraredRemoteButton* button = malloc(sizeof(InfraredRemoteButton));
button->name = furi_string_alloc();
button->signal = infrared_signal_alloc();
Expand Down
2 changes: 1 addition & 1 deletion non_catalog_apps/ir_remote/infrared_remote_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

typedef struct InfraredRemoteButton InfraredRemoteButton;

InfraredRemoteButton* infrared_remote_button_alloc();
InfraredRemoteButton* infrared_remote_button_alloc(void);
void infrared_remote_button_free(InfraredRemoteButton* button);

void infrared_remote_button_set_name(InfraredRemoteButton* button, const char* name);
Expand Down
2 changes: 1 addition & 1 deletion non_catalog_apps/ir_remote/infrared_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static bool infrared_signal_read_body(InfraredSignal* signal, FlipperFormat* ff)
return success;
}

InfraredSignal* infrared_signal_alloc() {
InfraredSignal* infrared_signal_alloc(void) {
InfraredSignal* signal = malloc(sizeof(InfraredSignal));

signal->is_raw = false;
Expand Down
2 changes: 1 addition & 1 deletion non_catalog_apps/ir_remote/infrared_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typedef struct {
float duty_cycle;
} InfraredRawSignal;

InfraredSignal* infrared_signal_alloc();
InfraredSignal* infrared_signal_alloc(void);
void infrared_signal_free(InfraredSignal* signal);

bool infrared_signal_is_raw(InfraredSignal* signal);
Expand Down
37 changes: 37 additions & 0 deletions non_catalog_apps/xremote/xremote.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#include "views/xremote_learn_view.h"
#include "views/xremote_signal_view.h"

#include <infrared/infrared_app.h>
#include <toolbox/saved_struct.h>

#define TAG "XRemote"

void xremote_get_version(char* version, size_t length) {
Expand Down Expand Up @@ -90,10 +93,44 @@ int32_t xremote_main(void* p) {
xremote_app_submenu_add(app, "Settings", XRemoteViewSettings, xremote_submenu_callback);
xremote_app_submenu_add(app, "About", XRemoteViewAbout, xremote_submenu_callback);

bool otg_was_enabled = furi_hal_power_is_otg_enabled();
InfraredSettings settings = {0};
saved_struct_load(
INFRARED_SETTINGS_PATH,
&settings,
sizeof(InfraredSettings),
INFRARED_SETTINGS_MAGIC,
INFRARED_SETTINGS_VERSION);
if(settings.tx_pin < FuriHalInfraredTxPinMax) {
furi_hal_infrared_set_tx_output(settings.tx_pin);
if(settings.otg_enabled != otg_was_enabled) {
if(settings.otg_enabled) {
furi_hal_power_enable_otg();
} else {
furi_hal_power_disable_otg();
}
}
} else {
FuriHalInfraredTxPin tx_pin_detected = furi_hal_infrared_detect_tx_output();
furi_hal_infrared_set_tx_output(tx_pin_detected);
if(tx_pin_detected != FuriHalInfraredTxPinInternal) {
furi_hal_power_enable_otg();
}
}

/* Switch to main menu by default and run disparcher*/
xremote_app_switch_to_view(app, XRemoteViewSubmenu);
view_dispatcher_run(app->app_ctx->view_dispatcher);

furi_hal_infrared_set_tx_output(FuriHalInfraredTxPinInternal);
if(furi_hal_power_is_otg_enabled() != otg_was_enabled) {
if(otg_was_enabled) {
furi_hal_power_enable_otg();
} else {
furi_hal_power_disable_otg();
}
}

/* Cleanup and exit */
xremote_app_free(app);
xremote_app_context_free(context);
Expand Down

0 comments on commit 999dc95

Please sign in to comment.