Merge branch 'ofwdev' into 420

This commit is contained in:
RogueMaster
2022-10-18 16:55:00 -04:00
9 changed files with 94 additions and 31 deletions

View File

@@ -24,6 +24,7 @@ struct GpioApp {
Widget* widget;
VariableItemList* var_item_list;
VariableItem* var_item_flow;
GpioTest* gpio_test;
GpioUsbUart* gpio_usb_uart;
UsbUartBridge* usb_uart_bridge;

View File

@@ -13,7 +13,7 @@ static UsbUartConfig* cfg_set;
static const char* vcp_ch[] = {"0 (CLI)", "1"};
static const char* uart_ch[] = {"13,14", "15,16"};
static const char* flow_pins[] = {"None", "2,3", "6,7"};
static const char* flow_pins[] = {"None", "2,3", "6,7", "16,15"};
static const char* baudrate_mode[] = {"Host"};
static const uint32_t baudrate_list[] = {
2400,
@@ -33,6 +33,24 @@ bool gpio_scene_usb_uart_cfg_on_event(void* context, SceneManagerEvent event) {
return false;
}
void line_ensure_flow_invariant(GpioApp* app) {
// GPIO pins PC0, PC1 (16,15) are unavailable for RTS/DTR when LPUART is
// selected. This function enforces that invariant by resetting flow_pins
// to None if it is configured to 16,15 when LPUART is selected.
uint8_t available_flow_pins = cfg_set->uart_ch == FuriHalUartIdLPUART1 ? 3 : 4;
VariableItem* item = app->var_item_flow;
variable_item_set_values_count(item, available_flow_pins);
if(cfg_set->flow_pins >= available_flow_pins) {
cfg_set->flow_pins = 0;
usb_uart_set_config(app->usb_uart_bridge, cfg_set);
variable_item_set_current_value_index(item, cfg_set->flow_pins);
variable_item_set_current_value_text(item, flow_pins[cfg_set->flow_pins]);
}
}
static void line_vcp_cb(VariableItem* item) {
GpioApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
@@ -54,6 +72,7 @@ static void line_port_cb(VariableItem* item) {
else if(index == 1)
cfg_set->uart_ch = FuriHalUartIdLPUART1;
usb_uart_set_config(app->usb_uart_bridge, cfg_set);
line_ensure_flow_invariant(app);
}
static void line_flow_cb(VariableItem* item) {
@@ -116,9 +135,12 @@ void gpio_scene_usb_uart_cfg_on_enter(void* context) {
variable_item_set_current_value_index(item, cfg_set->uart_ch);
variable_item_set_current_value_text(item, uart_ch[cfg_set->uart_ch]);
item = variable_item_list_add(var_item_list, "RTS/DTR Pins", 3, line_flow_cb, app);
item = variable_item_list_add(
var_item_list, "RTS/DTR Pins", COUNT_OF(flow_pins), line_flow_cb, app);
variable_item_set_current_value_index(item, cfg_set->flow_pins);
variable_item_set_current_value_text(item, flow_pins[cfg_set->flow_pins]);
app->var_item_flow = item;
line_ensure_flow_invariant(app);
variable_item_list_set_selected_item(
var_item_list, scene_manager_get_scene_state(app->scene_manager, GpioAppViewUsbUartCfg));

View File

@@ -14,6 +14,7 @@
static const GpioPin* flow_pins[][2] = {
{&gpio_ext_pa7, &gpio_ext_pa6}, // 2, 3
{&gpio_ext_pb2, &gpio_ext_pc3}, // 6, 7
{&gpio_ext_pc0, &gpio_ext_pc1}, // 16, 15
};
typedef enum {

View File

@@ -71,25 +71,9 @@ static void signal_received_callback(void* context, InfraredWorkerSignal* receiv
}
}
static void infrared_cli_start_ir_rx(Cli* cli, FuriString* args) {
UNUSED(cli);
UNUSED(args);
InfraredWorker* worker = infrared_worker_alloc();
infrared_worker_rx_start(worker);
infrared_worker_rx_set_received_signal_callback(worker, signal_received_callback, cli);
printf("Receiving INFRARED...\r\nPress Ctrl+C to abort\r\n");
while(!cli_cmd_interrupt_received(cli)) {
furi_delay_ms(50);
}
infrared_worker_rx_stop(worker);
infrared_worker_free(worker);
}
static void infrared_cli_print_usage(void) {
printf("Usage:\r\n");
printf("\tir rx\r\n");
printf("\tir rx [raw]\r\n");
printf("\tir tx <protocol> <address> <command>\r\n");
printf("\t<command> and <address> are hex-formatted\r\n");
printf("\tAvailable protocols:");
@@ -108,6 +92,35 @@ static void infrared_cli_print_usage(void) {
printf("\tir universal list <tv, ac>\r\n");
}
static void infrared_cli_start_ir_rx(Cli* cli, FuriString* args) {
UNUSED(cli);
bool enable_decoding = true;
if(!furi_string_empty(args)) {
if(!furi_string_cmp_str(args, "raw")) {
enable_decoding = false;
} else {
printf("Wrong arguments.\r\n");
infrared_cli_print_usage();
return;
}
}
InfraredWorker* worker = infrared_worker_alloc();
infrared_worker_rx_enable_signal_decoding(worker, enable_decoding);
infrared_worker_rx_start(worker);
infrared_worker_rx_set_received_signal_callback(worker, signal_received_callback, cli);
printf("Receiving %s INFRARED...\r\nPress Ctrl+C to abort\r\n", enable_decoding ? "" : "RAW");
while(!cli_cmd_interrupt_received(cli)) {
furi_delay_ms(50);
}
infrared_worker_rx_stop(worker);
infrared_worker_free(worker);
}
static bool infrared_cli_parse_message(const char* str, InfraredSignal* signal) {
char protocol_name[32];
InfraredMessage message;

View File

@@ -396,6 +396,10 @@ void variable_item_set_current_value_index(VariableItem* item, uint8_t current_v
item->current_value_index = current_value_index;
}
void variable_item_set_values_count(VariableItem* item, uint8_t values_count) {
item->values_count = values_count;
}
void variable_item_set_current_value_text(VariableItem* item, const char* current_value_text) {
furi_string_set(item->current_value_text, current_value_text);
}

View File

@@ -81,6 +81,13 @@ uint8_t variable_item_list_get_selected_item_index(VariableItemList* variable_it
*/
void variable_item_set_current_value_index(VariableItem* item, uint8_t current_value_index);
/** Set number of values for item
*
* @param item VariableItem* instance
* @param values_count The new values count
*/
void variable_item_set_values_count(VariableItem* item, uint8_t values_count);
/** Set item current selected text
*
* @param item VariableItem* instance

View File

@@ -57,6 +57,7 @@ struct InfraredWorker {
InfraredDecoderHandler* infrared_decoder;
NotificationApp* notification;
bool blink_enable;
bool decode_enable;
union {
struct {
@@ -131,7 +132,8 @@ static void infrared_worker_process_timeout(InfraredWorker* instance) {
static void
infrared_worker_process_timings(InfraredWorker* instance, uint32_t duration, bool level) {
const InfraredMessage* message_decoded =
infrared_decode(instance->infrared_decoder, level, duration);
instance->decode_enable ? infrared_decode(instance->infrared_decoder, level, duration) :
NULL;
if(message_decoded) {
instance->signal.message = *message_decoded;
instance->signal.timings_cnt = 0;
@@ -233,6 +235,7 @@ InfraredWorker* infrared_worker_alloc() {
instance->infrared_decoder = infrared_alloc_decoder();
instance->infrared_encoder = infrared_alloc_encoder();
instance->blink_enable = false;
instance->decode_enable = true;
instance->notification = furi_record_open(RECORD_NOTIFICATION);
instance->state = InfraredWorkerStateIdle;
@@ -316,6 +319,11 @@ void infrared_worker_rx_enable_blink_on_receiving(InfraredWorker* instance, bool
instance->blink_enable = enable;
}
void infrared_worker_rx_enable_signal_decoding(InfraredWorker* instance, bool enable) {
furi_assert(instance);
instance->decode_enable = enable;
}
void infrared_worker_tx_start(InfraredWorker* instance) {
furi_assert(instance);
furi_assert(instance->state == InfraredWorkerStateIdle);

View File

@@ -76,6 +76,14 @@ void infrared_worker_rx_set_received_signal_callback(
*/
void infrared_worker_rx_enable_blink_on_receiving(InfraredWorker* instance, bool enable);
/** Enable decoding of received infrared signals.
*
* @param[in] instance - instance of InfraredWorker
* @param[in] enable - true if you want to enable decoding
* false otherwise
*/
void infrared_worker_rx_enable_signal_decoding(InfraredWorker* instance, bool enable);
/** Clarify is received signal either decoded or raw
*
* @param[in] signal - received signal

View File

@@ -16,6 +16,8 @@
#define CAME_24_COUNT_BIT 24
#define PRASTEL_COUNT_BIT 25
#define PRASTEL_NAME "Prastel"
#define AIRFORCE_COUNT_BIT 18
#define AIRFORCE_NAME "Airforce"
static const SubGhzBlockConst subghz_protocol_came_const = {
.te_short = 320,
@@ -86,7 +88,7 @@ void* subghz_protocol_encoder_came_alloc(SubGhzEnvironment* environment) {
instance->generic.protocol_name = instance->base.protocol->name;
instance->encoder.repeat = 10;
instance->encoder.size_upload = 52; //max 24bit*2 + 2 (start, stop)
instance->encoder.size_upload = 128;
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
instance->encoder.is_running = false;
return instance;
@@ -151,10 +153,7 @@ bool subghz_protocol_encoder_came_deserialize(void* context, FlipperFormat* flip
FURI_LOG_E(TAG, "Deserialize error");
break;
}
if((instance->generic.data_count_bit !=
subghz_protocol_came_const.min_count_bit_for_found) &&
(instance->generic.data_count_bit != CAME_24_COUNT_BIT) &&
(instance->generic.data_count_bit != PRASTEL_COUNT_BIT)) {
if((instance->generic.data_count_bit > PRASTEL_COUNT_BIT)) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
@@ -310,10 +309,7 @@ bool subghz_protocol_decoder_came_deserialize(void* context, FlipperFormat* flip
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
break;
}
if((instance->generic.data_count_bit !=
subghz_protocol_came_const.min_count_bit_for_found) &&
(instance->generic.data_count_bit != CAME_24_COUNT_BIT) &&
(instance->generic.data_count_bit != PRASTEL_COUNT_BIT)) {
if((instance->generic.data_count_bit > PRASTEL_COUNT_BIT)) {
FURI_LOG_E(TAG, "Wrong number of bits in key");
break;
}
@@ -338,8 +334,11 @@ void subghz_protocol_decoder_came_get_string(void* context, FuriString* output)
"%s %dbit\r\n"
"Key:0x%08lX\r\n"
"Yek:0x%08lX\r\n",
(instance->generic.data_count_bit == PRASTEL_COUNT_BIT ? PRASTEL_NAME :
instance->generic.protocol_name),
(instance->generic.data_count_bit == PRASTEL_COUNT_BIT ?
PRASTEL_NAME :
(instance->generic.data_count_bit == AIRFORCE_COUNT_BIT ?
AIRFORCE_NAME :
instance->generic.protocol_name)),
instance->generic.data_count_bit,
code_found_lo,
code_found_reverse_lo);