mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 15:38:35 -07:00
Merge branch 'dev' of https://github.com/flipperdevices/flipperzero-firmware into mntm-dev
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
#include "infrared_app_i.h"
|
||||
|
||||
#include <furi_hal_power.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <toolbox/path.h>
|
||||
#include <toolbox/saved_struct.h>
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
#define TAG "InfraredApp"
|
||||
@@ -9,6 +12,13 @@
|
||||
#define INFRARED_TX_MIN_INTERVAL_MS (50U)
|
||||
#define INFRARED_TASK_STACK_SIZE (2048UL)
|
||||
|
||||
#define INFRARED_SETTINGS_VERSION (0)
|
||||
#define INFRARED_SETTINGS_MAGIC (0x1F)
|
||||
|
||||
typedef struct {
|
||||
uint8_t tx_pin;
|
||||
} InfraredSettings;
|
||||
|
||||
static const NotificationSequence*
|
||||
infrared_notification_sequences[InfraredNotificationMessageCount] = {
|
||||
&sequence_success,
|
||||
@@ -174,12 +184,6 @@ static InfraredApp* infrared_alloc(void) {
|
||||
view_dispatcher_add_view(
|
||||
view_dispatcher, InfraredViewDialogEx, dialog_ex_get_view(infrared->dialog_ex));
|
||||
|
||||
infrared->variable_item_list = variable_item_list_alloc();
|
||||
view_dispatcher_add_view(
|
||||
infrared->view_dispatcher,
|
||||
InfraredViewVariableItemList,
|
||||
variable_item_list_get_view(infrared->variable_item_list));
|
||||
|
||||
infrared->button_menu = button_menu_alloc();
|
||||
view_dispatcher_add_view(
|
||||
view_dispatcher, InfraredViewButtonMenu, button_menu_get_view(infrared->button_menu));
|
||||
@@ -187,6 +191,12 @@ static InfraredApp* infrared_alloc(void) {
|
||||
infrared->popup = popup_alloc();
|
||||
view_dispatcher_add_view(view_dispatcher, InfraredViewPopup, popup_get_view(infrared->popup));
|
||||
|
||||
infrared->var_item_list = variable_item_list_alloc();
|
||||
view_dispatcher_add_view(
|
||||
view_dispatcher,
|
||||
InfraredViewVariableList,
|
||||
variable_item_list_get_view(infrared->var_item_list));
|
||||
|
||||
infrared->view_stack = view_stack_alloc();
|
||||
view_dispatcher_add_view(
|
||||
view_dispatcher, InfraredViewStack, view_stack_get_view(infrared->view_stack));
|
||||
@@ -210,10 +220,6 @@ static InfraredApp* infrared_alloc(void) {
|
||||
infrared->button_panel = button_panel_alloc();
|
||||
infrared->progress = infrared_progress_view_alloc();
|
||||
|
||||
infrared->last_settings = infrared_last_settings_alloc();
|
||||
infrared_last_settings_load(infrared->last_settings);
|
||||
infrared_last_settings_apply(infrared->last_settings);
|
||||
|
||||
return infrared;
|
||||
}
|
||||
|
||||
@@ -241,15 +247,15 @@ static void infrared_free(InfraredApp* infrared) {
|
||||
view_dispatcher_remove_view(view_dispatcher, InfraredViewDialogEx);
|
||||
dialog_ex_free(infrared->dialog_ex);
|
||||
|
||||
view_dispatcher_remove_view(infrared->view_dispatcher, InfraredViewVariableItemList);
|
||||
variable_item_list_free(infrared->variable_item_list);
|
||||
|
||||
view_dispatcher_remove_view(view_dispatcher, InfraredViewButtonMenu);
|
||||
button_menu_free(infrared->button_menu);
|
||||
|
||||
view_dispatcher_remove_view(view_dispatcher, InfraredViewPopup);
|
||||
popup_free(infrared->popup);
|
||||
|
||||
view_dispatcher_remove_view(view_dispatcher, InfraredViewVariableList);
|
||||
variable_item_list_free(infrared->var_item_list);
|
||||
|
||||
view_dispatcher_remove_view(view_dispatcher, InfraredViewStack);
|
||||
view_stack_free(infrared->view_stack);
|
||||
|
||||
@@ -287,9 +293,6 @@ static void infrared_free(InfraredApp* infrared) {
|
||||
furi_string_free(infrared->file_path);
|
||||
furi_string_free(infrared->button_name);
|
||||
|
||||
infrared_last_settings_reset(infrared->last_settings);
|
||||
infrared_last_settings_free(infrared->last_settings);
|
||||
|
||||
free(infrared);
|
||||
}
|
||||
|
||||
@@ -447,6 +450,59 @@ void infrared_show_error_message(const InfraredApp* infrared, const char* fmt, .
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void infrared_set_tx_pin(InfraredApp* infrared, FuriHalInfraredTxPin tx_pin) {
|
||||
if(tx_pin < FuriHalInfraredTxPinMax) {
|
||||
furi_hal_infrared_set_tx_output(tx_pin);
|
||||
} 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) {
|
||||
infrared_enable_otg(infrared, true);
|
||||
}
|
||||
}
|
||||
|
||||
infrared->app_state.tx_pin = tx_pin;
|
||||
}
|
||||
|
||||
void infrared_enable_otg(InfraredApp* infrared, bool enable) {
|
||||
if(enable) {
|
||||
furi_hal_power_enable_otg();
|
||||
} else {
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
infrared->app_state.is_otg_enabled = enable;
|
||||
}
|
||||
|
||||
static void infrared_load_settings(InfraredApp* infrared) {
|
||||
InfraredSettings settings = {0};
|
||||
|
||||
if(!saved_struct_load(
|
||||
INFRARED_SETTINGS_PATH,
|
||||
&settings,
|
||||
sizeof(InfraredSettings),
|
||||
INFRARED_SETTINGS_MAGIC,
|
||||
INFRARED_SETTINGS_VERSION)) {
|
||||
FURI_LOG_D(TAG, "Failed to load settings, using defaults");
|
||||
}
|
||||
|
||||
infrared_set_tx_pin(infrared, settings.tx_pin);
|
||||
}
|
||||
|
||||
void infrared_save_settings(InfraredApp* infrared) {
|
||||
InfraredSettings settings = {
|
||||
.tx_pin = infrared->app_state.tx_pin,
|
||||
};
|
||||
|
||||
if(!saved_struct_save(
|
||||
INFRARED_SETTINGS_PATH,
|
||||
&settings,
|
||||
sizeof(InfraredSettings),
|
||||
INFRARED_SETTINGS_MAGIC,
|
||||
INFRARED_SETTINGS_VERSION)) {
|
||||
FURI_LOG_E(TAG, "Failed to save settings");
|
||||
}
|
||||
}
|
||||
|
||||
void infrared_signal_received_callback(void* context, InfraredWorkerSignal* received_signal) {
|
||||
furi_assert(context);
|
||||
InfraredApp* infrared = context;
|
||||
@@ -484,9 +540,10 @@ void infrared_popup_closed_callback(void* context) {
|
||||
infrared->view_dispatcher, InfraredCustomEventTypePopupClosed);
|
||||
}
|
||||
|
||||
int32_t infrared_app(char* p) {
|
||||
int32_t infrared_app(void* p) {
|
||||
InfraredApp* infrared = infrared_alloc();
|
||||
|
||||
infrared_load_settings(infrared);
|
||||
infrared_make_app_folder(infrared);
|
||||
|
||||
bool is_remote_loaded = false;
|
||||
@@ -529,6 +586,9 @@ int32_t infrared_app(char* p) {
|
||||
|
||||
view_dispatcher_run(infrared->view_dispatcher);
|
||||
|
||||
infrared_set_tx_pin(infrared, FuriHalInfraredTxPinInternal);
|
||||
infrared_enable_otg(infrared, false);
|
||||
infrared_free(infrared);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,6 @@
|
||||
* @brief InfraredApp opaque type declaration.
|
||||
*/
|
||||
typedef struct InfraredApp InfraredApp;
|
||||
|
||||
#include <storage/storage.h>
|
||||
#define INFRARED_SETTINGS_PATH CFG_PATH("infrared.settings")
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <furi_hal_infrared.h>
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view.h>
|
||||
#include <assets_icons.h>
|
||||
@@ -25,14 +27,12 @@
|
||||
#include <dialogs/dialogs.h>
|
||||
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#include <infrared/worker/infrared_worker.h>
|
||||
|
||||
#include "infrared_app.h"
|
||||
#include "infrared_remote.h"
|
||||
#include "infrared_brute_force.h"
|
||||
#include "infrared_custom_event.h"
|
||||
#include "infrared_last_settings.h"
|
||||
|
||||
#include "scenes/infrared_scene.h"
|
||||
#include "views/infrared_progress_view.h"
|
||||
@@ -84,11 +84,13 @@ typedef struct {
|
||||
bool is_learning_new_remote; /**< Learning new remote or adding to an existing one. */
|
||||
bool is_debug_enabled; /**< Whether to enable or disable debugging features. */
|
||||
bool is_transmitting; /**< Whether a signal is currently being transmitted. */
|
||||
bool is_otg_enabled; /**< Whether OTG power (external 5V) is enabled. */
|
||||
InfraredEditTarget edit_target : 8; /**< Selected editing target (a remote or a button). */
|
||||
InfraredEditMode edit_mode : 8; /**< Selected editing operation (rename or delete). */
|
||||
int32_t current_button_index; /**< Selected button index (move destination). */
|
||||
int32_t prev_button_index; /**< Previous button index (move source). */
|
||||
uint32_t last_transmit_time; /**< Lat time a signal was transmitted. */
|
||||
FuriHalInfraredTxPin tx_pin;
|
||||
} InfraredAppState;
|
||||
|
||||
/**
|
||||
@@ -112,7 +114,7 @@ struct InfraredApp {
|
||||
DialogEx* dialog_ex; /**< Standard view for displaying dialogs. */
|
||||
ButtonMenu* button_menu; /**< Custom view for interacting with IR remotes. */
|
||||
Popup* popup; /**< Standard view for displaying messages. */
|
||||
VariableItemList* variable_item_list;
|
||||
VariableItemList* var_item_list; /**< Standard view for displaying menus of choice items. */
|
||||
|
||||
ViewStack* view_stack; /**< Standard view for displaying stacked interfaces. */
|
||||
InfraredDebugView* debug_view; /**< Custom view for displaying debug information. */
|
||||
@@ -128,7 +130,6 @@ struct InfraredApp {
|
||||
/** Arbitrary text storage for various inputs. */
|
||||
char text_store[INFRARED_TEXT_STORE_NUM][INFRARED_TEXT_STORE_SIZE + 1];
|
||||
InfraredAppState app_state; /**< Application state. */
|
||||
InfraredLastSettings* last_settings; /**< Last settings. */
|
||||
|
||||
void* rpc_ctx; /**< Pointer to the RPC context object. */
|
||||
};
|
||||
@@ -142,10 +143,10 @@ typedef enum {
|
||||
InfraredViewDialogEx,
|
||||
InfraredViewButtonMenu,
|
||||
InfraredViewPopup,
|
||||
InfraredViewVariableList,
|
||||
InfraredViewStack,
|
||||
InfraredViewDebugView,
|
||||
InfraredViewMove,
|
||||
InfraredViewVariableItemList,
|
||||
InfraredViewLoading,
|
||||
} InfraredView;
|
||||
|
||||
@@ -278,6 +279,32 @@ void infrared_play_notification_message(
|
||||
void infrared_show_error_message(const InfraredApp* infrared, const char* fmt, ...)
|
||||
_ATTRIBUTE((__format__(__printf__, 2, 3)));
|
||||
|
||||
/**
|
||||
* @brief Set which pin will be used to transmit infrared signals.
|
||||
*
|
||||
* Setting tx_pin to InfraredTxPinInternal will enable transmission via
|
||||
* the built-in infrared LEDs.
|
||||
*
|
||||
* @param[in] infrared pointer to the application instance.
|
||||
* @param[in] tx_pin pin to be used for signal transmission.
|
||||
*/
|
||||
void infrared_set_tx_pin(InfraredApp* infrared, FuriHalInfraredTxPin tx_pin);
|
||||
|
||||
/**
|
||||
* @brief Enable or disable 5V at the GPIO pin 1.
|
||||
*
|
||||
* @param[in] infrared pointer to the application instance.
|
||||
* @param[in] enable boolean value corresponding to OTG state (true = enable, false = disable)
|
||||
*/
|
||||
void infrared_enable_otg(InfraredApp* infrared, bool enable);
|
||||
|
||||
/**
|
||||
* @brief Save current settings to a file.
|
||||
*
|
||||
* @param[in] infrared pointer to the application instance.
|
||||
*/
|
||||
void infrared_save_settings(InfraredApp* infrared);
|
||||
|
||||
/**
|
||||
* @brief Common received signal callback.
|
||||
*
|
||||
|
||||
@@ -22,6 +22,9 @@ enum InfraredCustomEventType {
|
||||
InfraredCustomEventTypeRpcButtonPressIndex,
|
||||
InfraredCustomEventTypeRpcButtonRelease,
|
||||
InfraredCustomEventTypeRpcSessionClose,
|
||||
|
||||
InfraredCustomEventTypeGpioTxPinChanged,
|
||||
InfraredCustomEventTypeGpioOtgChanged,
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
#include "infrared_last_settings.h"
|
||||
|
||||
#include <furi_hal_infrared.h>
|
||||
|
||||
#define TAG "InfraredLastSettings"
|
||||
|
||||
#define INFRARED_LAST_SETTINGS_FILE_TYPE "Flipper Infrared Last Settings File"
|
||||
#define INFRARED_LAST_SETTINGS_FILE_VERSION 1
|
||||
#define INFRARED_LAST_SETTINGS_PATH EXT_PATH("infrared/assets/last_infrared.settings")
|
||||
|
||||
#define INFRARED_LAST_SETTINGS_FIELD_EXTPOWER "External5V"
|
||||
#define INFRARED_LAST_SETTINGS_FIELD_EXTOUT "ExternalOut"
|
||||
#define INFRARED_LAST_SETTINGS_FIELD_AUTO_DETECT "AutoDetect"
|
||||
|
||||
InfraredLastSettings* infrared_last_settings_alloc(void) {
|
||||
InfraredLastSettings* instance = malloc(sizeof(InfraredLastSettings));
|
||||
return instance;
|
||||
}
|
||||
|
||||
void infrared_last_settings_free(InfraredLastSettings* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void infrared_last_settings_load(InfraredLastSettings* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
||||
|
||||
bool temp_extpower = false;
|
||||
bool temp_extout = false;
|
||||
bool temp_auto_detect = true;
|
||||
|
||||
if(FSE_OK == storage_sd_status(storage) && INFRARED_LAST_SETTINGS_PATH &&
|
||||
flipper_format_file_open_existing(fff_data_file, INFRARED_LAST_SETTINGS_PATH)) {
|
||||
flipper_format_read_bool(
|
||||
fff_data_file, INFRARED_LAST_SETTINGS_FIELD_EXTPOWER, (bool*)&temp_extpower, 1);
|
||||
flipper_format_read_bool(
|
||||
fff_data_file, INFRARED_LAST_SETTINGS_FIELD_EXTOUT, (bool*)&temp_extout, 1);
|
||||
flipper_format_read_bool(
|
||||
fff_data_file, INFRARED_LAST_SETTINGS_FIELD_AUTO_DETECT, (bool*)&temp_auto_detect, 1);
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Error open file %s", INFRARED_LAST_SETTINGS_PATH);
|
||||
}
|
||||
|
||||
instance->ext_5v = temp_extpower;
|
||||
instance->ext_out = temp_extout;
|
||||
instance->auto_detect = temp_auto_detect;
|
||||
|
||||
flipper_format_file_close(fff_data_file);
|
||||
flipper_format_free(fff_data_file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
bool infrared_last_settings_save(InfraredLastSettings* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
bool saved = false;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
|
||||
do {
|
||||
if(FSE_OK != storage_sd_status(storage)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Open file
|
||||
if(!flipper_format_file_open_always(file, INFRARED_LAST_SETTINGS_PATH)) break;
|
||||
|
||||
// Write header
|
||||
if(!flipper_format_write_header_cstr(
|
||||
file, INFRARED_LAST_SETTINGS_FILE_TYPE, INFRARED_LAST_SETTINGS_FILE_VERSION))
|
||||
break;
|
||||
|
||||
if(!flipper_format_insert_or_update_bool(
|
||||
file, INFRARED_LAST_SETTINGS_FIELD_EXTPOWER, &instance->ext_5v, 1))
|
||||
break;
|
||||
if(!flipper_format_insert_or_update_bool(
|
||||
file, INFRARED_LAST_SETTINGS_FIELD_EXTOUT, &instance->ext_out, 1))
|
||||
break;
|
||||
if(!flipper_format_insert_or_update_bool(
|
||||
file, INFRARED_LAST_SETTINGS_FIELD_AUTO_DETECT, &instance->auto_detect, 1))
|
||||
break;
|
||||
|
||||
saved = true;
|
||||
} while(0);
|
||||
|
||||
if(!saved) {
|
||||
FURI_LOG_E(TAG, "Error save file %s", INFRARED_LAST_SETTINGS_PATH);
|
||||
}
|
||||
|
||||
flipper_format_file_close(file);
|
||||
flipper_format_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return saved;
|
||||
}
|
||||
|
||||
void infrared_last_settings_apply(InfraredLastSettings* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
instance->_otg_was_enabled = furi_hal_power_is_otg_enabled();
|
||||
furi_hal_infrared_set_auto_detect(instance->auto_detect);
|
||||
if(!instance->auto_detect) {
|
||||
furi_hal_infrared_set_debug_out(instance->ext_out);
|
||||
if(instance->ext_5v) {
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
} else if(furi_hal_power_is_otg_enabled()) {
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
} else if(furi_hal_power_is_otg_enabled()) {
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
}
|
||||
|
||||
void infrared_last_settings_reset(InfraredLastSettings* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
if(instance->_otg_was_enabled != furi_hal_power_is_otg_enabled()) {
|
||||
if(instance->_otg_was_enabled) {
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
} else {
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi_hal.h>
|
||||
#include <storage/storage.h>
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
|
||||
typedef struct {
|
||||
bool ext_5v;
|
||||
bool ext_out;
|
||||
bool auto_detect;
|
||||
|
||||
bool _otg_was_enabled;
|
||||
} InfraredLastSettings;
|
||||
|
||||
InfraredLastSettings* infrared_last_settings_alloc(void);
|
||||
void infrared_last_settings_free(InfraredLastSettings* instance);
|
||||
void infrared_last_settings_load(InfraredLastSettings* instance);
|
||||
bool infrared_last_settings_save(InfraredLastSettings* instance);
|
||||
void infrared_last_settings_apply(InfraredLastSettings* instance);
|
||||
void infrared_last_settings_reset(InfraredLastSettings* instance);
|
||||
@@ -4232,3 +4232,52 @@ type: parsed
|
||||
protocol: NECext
|
||||
address: 87 7C 00 00
|
||||
command: 25 DA 00 00
|
||||
#
|
||||
# Model: Dutch Originals Sound Bar
|
||||
name: Power
|
||||
type: parsed
|
||||
protocol: NEC
|
||||
address: 00 00 00 00
|
||||
command: 07 00 00 00
|
||||
#
|
||||
name: Next
|
||||
type: parsed
|
||||
protocol: NEC
|
||||
address: 00 00 00 00
|
||||
command: 15 00 00 00
|
||||
#
|
||||
name: Prev
|
||||
type: parsed
|
||||
protocol: NEC
|
||||
address: 00 00 00 00
|
||||
command: 15 00 00 00
|
||||
#
|
||||
name: Play
|
||||
type: parsed
|
||||
protocol: NEC
|
||||
address: 00 00 00 00
|
||||
command: 6A 00 00 00
|
||||
#
|
||||
name: Pause
|
||||
type: parsed
|
||||
protocol: NEC
|
||||
address: 00 00 00 00
|
||||
command: 6A 00 00 00
|
||||
#
|
||||
name: Mute
|
||||
type: parsed
|
||||
protocol: NEC
|
||||
address: 00 00 00 00
|
||||
command: 09 00 00 00
|
||||
#
|
||||
name: Vol_up
|
||||
type: parsed
|
||||
protocol: NEC
|
||||
address: 00 00 00 00
|
||||
command: 5E 00 00 00
|
||||
#
|
||||
name: Vol_dn
|
||||
type: parsed
|
||||
protocol: NEC
|
||||
address: 00 00 00 00
|
||||
command: 85 00 00 00
|
||||
|
||||
@@ -23,7 +23,7 @@ ADD_SCENE(infrared, universal_audio, UniversalAudio)
|
||||
ADD_SCENE(infrared, universal_led, UniversalLED)
|
||||
ADD_SCENE(infrared, universal_ac, UniversalAC)
|
||||
ADD_SCENE(infrared, universal_fan, UniversalFan)
|
||||
ADD_SCENE(infrared, gpio_settings, GpioSettings)
|
||||
ADD_SCENE(infrared, debug, Debug)
|
||||
ADD_SCENE(infrared, error_databases, ErrorDatabases)
|
||||
ADD_SCENE(infrared, debug_settings, DebugSettings)
|
||||
ADD_SCENE(infrared, rpc, Rpc)
|
||||
|
||||
@@ -1,141 +0,0 @@
|
||||
#include "../infrared_app_i.h"
|
||||
|
||||
#include <furi_hal_infrared.h>
|
||||
|
||||
uint8_t value_index_ir;
|
||||
|
||||
#define DEB_PINS_COUNT (sizeof(infrared_debug_cfg_variables_text) / sizeof(char* const))
|
||||
const char* const infrared_debug_cfg_variables_text[] = {
|
||||
"Internal",
|
||||
"2 (A7)",
|
||||
};
|
||||
|
||||
static void infrared_scene_debug_settings_auto_detect_changed(VariableItem* item) {
|
||||
InfraredApp* infrared = variable_item_get_context(item);
|
||||
bool value = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
|
||||
|
||||
// enable/disable other list items
|
||||
VariableItemList* var_item_list = infrared->variable_item_list;
|
||||
variable_item_set_locked(variable_item_list_get(var_item_list, 1), value, NULL);
|
||||
variable_item_set_locked(variable_item_list_get(var_item_list, 2), value, NULL);
|
||||
|
||||
infrared->last_settings->auto_detect = value;
|
||||
infrared_last_settings_save(infrared->last_settings);
|
||||
|
||||
furi_hal_infrared_set_auto_detect(infrared->last_settings->auto_detect);
|
||||
if(!infrared->last_settings->auto_detect) {
|
||||
furi_hal_infrared_set_debug_out(infrared->last_settings->ext_out);
|
||||
if(infrared->last_settings->ext_5v) {
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
} else if(furi_hal_power_is_otg_enabled()) {
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
} else if(furi_hal_power_is_otg_enabled()) {
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
}
|
||||
|
||||
static void infrared_scene_debug_settings_pin_changed(VariableItem* item) {
|
||||
InfraredApp* infrared = variable_item_get_context(item);
|
||||
value_index_ir = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, infrared_debug_cfg_variables_text[value_index_ir]);
|
||||
|
||||
furi_hal_infrared_set_debug_out(value_index_ir);
|
||||
|
||||
infrared->last_settings->ext_out = value_index_ir == 1;
|
||||
infrared_last_settings_save(infrared->last_settings);
|
||||
}
|
||||
|
||||
static void infrared_scene_debug_settings_power_changed(VariableItem* item) {
|
||||
InfraredApp* infrared = variable_item_get_context(item);
|
||||
bool value = variable_item_get_current_value_index(item);
|
||||
if(value) {
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
} else {
|
||||
if(furi_hal_power_is_otg_enabled()) {
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
}
|
||||
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
|
||||
|
||||
infrared->last_settings->ext_5v = value;
|
||||
infrared_last_settings_save(infrared->last_settings);
|
||||
}
|
||||
|
||||
static void infrared_debug_settings_start_var_list_enter_callback(void* context, uint32_t index) {
|
||||
InfraredApp* infrared = context;
|
||||
view_dispatcher_send_custom_event(infrared->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void infrared_scene_debug_settings_on_enter(void* context) {
|
||||
InfraredApp* infrared = context;
|
||||
|
||||
VariableItemList* variable_item_list = infrared->variable_item_list;
|
||||
variable_item_list_set_enter_callback(
|
||||
variable_item_list, infrared_debug_settings_start_var_list_enter_callback, infrared);
|
||||
|
||||
VariableItem* item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"Auto detect",
|
||||
2,
|
||||
infrared_scene_debug_settings_auto_detect_changed,
|
||||
infrared);
|
||||
|
||||
bool auto_detect = infrared->last_settings->auto_detect;
|
||||
|
||||
variable_item_set_current_value_index(item, auto_detect);
|
||||
variable_item_set_current_value_text(item, auto_detect ? "ON" : "OFF");
|
||||
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"Send signal to",
|
||||
DEB_PINS_COUNT,
|
||||
infrared_scene_debug_settings_pin_changed,
|
||||
infrared);
|
||||
|
||||
value_index_ir = infrared->last_settings->ext_out;
|
||||
|
||||
variable_item_list_set_enter_callback(
|
||||
variable_item_list, infrared_debug_settings_start_var_list_enter_callback, infrared);
|
||||
|
||||
variable_item_set_current_value_index(item, value_index_ir);
|
||||
variable_item_set_current_value_text(item, infrared_debug_cfg_variables_text[value_index_ir]);
|
||||
variable_item_set_locked(item, auto_detect, "Disable auto detect");
|
||||
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"Ext Module 5v",
|
||||
2,
|
||||
infrared_scene_debug_settings_power_changed,
|
||||
infrared);
|
||||
bool enabled = infrared->last_settings->ext_5v;
|
||||
variable_item_set_current_value_index(item, enabled);
|
||||
variable_item_set_current_value_text(item, enabled ? "ON" : "OFF");
|
||||
variable_item_set_locked(item, auto_detect, "Disable auto detect");
|
||||
|
||||
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewVariableItemList);
|
||||
}
|
||||
|
||||
bool infrared_scene_debug_settings_on_event(void* context, SceneManagerEvent event) {
|
||||
InfraredApp* infrared = context;
|
||||
UNUSED(infrared);
|
||||
UNUSED(event);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void infrared_scene_debug_settings_on_exit(void* context) {
|
||||
InfraredApp* infrared = context;
|
||||
variable_item_list_reset(infrared->variable_item_list);
|
||||
}
|
||||
102
applications/main/infrared/scenes/infrared_scene_gpio_settings.c
Normal file
102
applications/main/infrared/scenes/infrared_scene_gpio_settings.c
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "../infrared_app_i.h"
|
||||
|
||||
static const char* infrared_scene_gpio_settings_pin_text[] = {
|
||||
"Flipper",
|
||||
"2 (A7)",
|
||||
"Detect",
|
||||
};
|
||||
|
||||
static const char* infrared_scene_gpio_settings_otg_text[] = {
|
||||
"OFF",
|
||||
"ON",
|
||||
};
|
||||
|
||||
static void infrared_scene_gpio_settings_pin_change_callback(VariableItem* item) {
|
||||
InfraredApp* infrared = variable_item_get_context(item);
|
||||
const uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, infrared_scene_gpio_settings_pin_text[index]);
|
||||
view_dispatcher_send_custom_event(
|
||||
infrared->view_dispatcher,
|
||||
infrared_custom_event_pack(InfraredCustomEventTypeGpioTxPinChanged, index));
|
||||
}
|
||||
|
||||
static void infrared_scene_gpio_settings_otg_change_callback(VariableItem* item) {
|
||||
InfraredApp* infrared = variable_item_get_context(item);
|
||||
const uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, infrared_scene_gpio_settings_otg_text[index]);
|
||||
view_dispatcher_send_custom_event(
|
||||
infrared->view_dispatcher,
|
||||
infrared_custom_event_pack(InfraredCustomEventTypeGpioOtgChanged, index));
|
||||
}
|
||||
|
||||
static void infrared_scene_gpio_settings_init(InfraredApp* infrared) {
|
||||
VariableItemList* var_item_list = infrared->var_item_list;
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"Signal Output",
|
||||
COUNT_OF(infrared_scene_gpio_settings_pin_text),
|
||||
infrared_scene_gpio_settings_pin_change_callback,
|
||||
infrared);
|
||||
|
||||
value_index = infrared->app_state.tx_pin;
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, infrared_scene_gpio_settings_pin_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"5V on GPIO",
|
||||
COUNT_OF(infrared_scene_gpio_settings_otg_text),
|
||||
infrared_scene_gpio_settings_otg_change_callback,
|
||||
infrared);
|
||||
|
||||
if(infrared->app_state.tx_pin < FuriHalInfraredTxPinMax) {
|
||||
value_index = infrared->app_state.is_otg_enabled;
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(
|
||||
item, infrared_scene_gpio_settings_otg_text[value_index]);
|
||||
} else {
|
||||
variable_item_set_values_count(item, 1);
|
||||
variable_item_set_current_value_index(item, 0);
|
||||
variable_item_set_current_value_text(item, "Auto");
|
||||
}
|
||||
}
|
||||
|
||||
void infrared_scene_gpio_settings_on_enter(void* context) {
|
||||
InfraredApp* infrared = context;
|
||||
infrared_scene_gpio_settings_init(infrared);
|
||||
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewVariableList);
|
||||
}
|
||||
|
||||
bool infrared_scene_gpio_settings_on_event(void* context, SceneManagerEvent event) {
|
||||
bool consumed = false;
|
||||
|
||||
InfraredApp* infrared = context;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
const uint16_t custom_event_type = infrared_custom_event_get_type(event.event);
|
||||
const uint16_t custom_event_value = infrared_custom_event_get_value(event.event);
|
||||
|
||||
if(custom_event_type == InfraredCustomEventTypeGpioTxPinChanged) {
|
||||
infrared_set_tx_pin(infrared, custom_event_value);
|
||||
variable_item_list_reset(infrared->var_item_list);
|
||||
infrared_scene_gpio_settings_init(infrared);
|
||||
} else if(custom_event_type == InfraredCustomEventTypeGpioOtgChanged) {
|
||||
infrared_enable_otg(infrared, custom_event_value);
|
||||
}
|
||||
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void infrared_scene_gpio_settings_on_exit(void* context) {
|
||||
InfraredApp* infrared = context;
|
||||
variable_item_list_reset(infrared->var_item_list);
|
||||
infrared_save_settings(infrared);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ void infrared_scene_learn_done_on_enter(void* context) {
|
||||
|
||||
if(infrared->app_state.is_learning_new_remote) {
|
||||
popup_set_icon(popup, 48, 6, &I_DolphinDone_80x58);
|
||||
popup_set_header(popup, "New remote\ncreated!", 0, 0, AlignLeft, AlignTop);
|
||||
popup_set_header(popup, "Success!", 10, 12, AlignLeft, AlignTop);
|
||||
} else {
|
||||
popup_set_icon(popup, 36, 5, &I_DolphinSaved_92x58);
|
||||
popup_set_header(popup, "Saved", 15, 19, AlignLeft, AlignBottom);
|
||||
|
||||
@@ -4,7 +4,7 @@ enum SubmenuIndex {
|
||||
SubmenuIndexUniversalRemotes,
|
||||
SubmenuIndexLearnNewRemote,
|
||||
SubmenuIndexSavedRemotes,
|
||||
SubmenuIndexDebugSettings,
|
||||
SubmenuIndexGpioSettings,
|
||||
SubmenuIndexLearnNewRemoteRaw,
|
||||
SubmenuIndexDebug
|
||||
};
|
||||
@@ -40,7 +40,7 @@ void infrared_scene_start_on_enter(void* context) {
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"GPIO Settings",
|
||||
SubmenuIndexDebugSettings,
|
||||
SubmenuIndexGpioSettings,
|
||||
infrared_scene_start_submenu_callback,
|
||||
infrared);
|
||||
|
||||
@@ -80,7 +80,6 @@ bool infrared_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
scene_manager_set_scene_state(scene_manager, InfraredSceneStart, submenu_index);
|
||||
if(submenu_index == SubmenuIndexUniversalRemotes) {
|
||||
scene_manager_next_scene(scene_manager, InfraredSceneUniversal);
|
||||
consumed = true;
|
||||
} else if(
|
||||
submenu_index == SubmenuIndexLearnNewRemote ||
|
||||
submenu_index == SubmenuIndexLearnNewRemoteRaw) {
|
||||
@@ -90,18 +89,16 @@ bool infrared_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
infrared->worker, submenu_index == SubmenuIndexLearnNewRemote);
|
||||
infrared->app_state.is_learning_new_remote = true;
|
||||
scene_manager_next_scene(scene_manager, InfraredSceneLearn);
|
||||
consumed = true;
|
||||
} else if(submenu_index == SubmenuIndexSavedRemotes) {
|
||||
furi_string_set(infrared->file_path, INFRARED_APP_FOLDER);
|
||||
scene_manager_next_scene(scene_manager, InfraredSceneRemoteList);
|
||||
consumed = true;
|
||||
} else if(submenu_index == SubmenuIndexGpioSettings) {
|
||||
scene_manager_next_scene(scene_manager, InfraredSceneGpioSettings);
|
||||
} else if(submenu_index == SubmenuIndexDebug) {
|
||||
scene_manager_next_scene(scene_manager, InfraredSceneDebug);
|
||||
consumed = true;
|
||||
} else if(submenu_index == SubmenuIndexDebugSettings) {
|
||||
scene_manager_next_scene(scene_manager, InfraredSceneDebugSettings);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
|
||||
@@ -34,7 +34,7 @@ static void infrared_move_view_draw_callback(Canvas* canvas, void* _model) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
elements_multiline_text_aligned(
|
||||
canvas, canvas_width(canvas) / 2, 0, AlignCenter, AlignTop, "Select a button to move");
|
||||
canvas, canvas_width(canvas) / 2, 0, AlignCenter, AlignTop, "Select a Button to Move");
|
||||
|
||||
const size_t btn_number = InfraredMoveViewItemArray_size(model->labels);
|
||||
const bool show_scrollbar = btn_number > LIST_ITEMS;
|
||||
|
||||
Reference in New Issue
Block a user