Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FL-1652, FL-1554] IRDA: Continuous transmitting #636

Merged
merged 9 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 31 additions & 9 deletions applications/gui/modules/button_menu.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "button_menu.h"
#include "gui/canvas.h"
#include "gui/elements.h"
#include "input/input.h"
#include <m-array.h>
#include <furi.h>
#include <stdint.h>
Expand All @@ -23,6 +24,7 @@ ARRAY_DEF(ButtonMenuItemArray, ButtonMenuItem, M_POD_OPLIST);

struct ButtonMenu {
View* view;
bool freeze_input;
};

typedef struct {
Expand Down Expand Up @@ -158,7 +160,7 @@ static void button_menu_process_down(ButtonMenu* button_menu) {
});
}

static void button_menu_process_ok(ButtonMenu* button_menu) {
static void button_menu_process_ok(ButtonMenu* button_menu, InputType type) {
furi_assert(button_menu);

ButtonMenuItem* item = NULL;
Expand All @@ -168,11 +170,22 @@ static void button_menu_process_ok(ButtonMenu* button_menu) {
if(model->position < (ButtonMenuItemArray_size(model->items))) {
item = ButtonMenuItemArray_get(model->items, model->position);
}
return true;
return false;
});

if(item && item->callback) {
item->callback(item->callback_context, item->index);
if(item->type == ButtonMenuItemTypeControl) {
if(type == InputTypeShort) {
if(item && item->callback) {
item->callback(item->callback_context, item->index, type);
}
}
}
if(item->type == ButtonMenuItemTypeCommon) {
if((type == InputTypePress) || (type == InputTypeRelease)) {
if(item && item->callback) {
item->callback(item->callback_context, item->index, type);
}
}
}
}

Expand All @@ -182,7 +195,19 @@ static bool button_menu_view_input_callback(InputEvent* event, void* context) {
ButtonMenu* button_menu = context;
bool consumed = false;

if(event->type == InputTypeShort) {
if(event->key == InputKeyOk) {
if((event->type == InputTypeRelease) || (event->type == InputTypePress)) {
consumed = true;
button_menu->freeze_input = (event->type == InputTypePress);
button_menu_process_ok(button_menu, event->type);
} else if(event->type == InputTypeShort) {
consumed = true;
button_menu_process_ok(button_menu, event->type);
}
}

if(!button_menu->freeze_input &&
((event->type == InputTypeRepeat) || (event->type == InputTypeShort))) {
switch(event->key) {
case InputKeyUp:
consumed = true;
Expand All @@ -192,10 +217,6 @@ static bool button_menu_view_input_callback(InputEvent* event, void* context) {
consumed = true;
button_menu_process_down(button_menu);
break;
case InputKeyOk:
consumed = true;
button_menu_process_ok(button_menu);
break;
default:
break;
}
Expand Down Expand Up @@ -272,6 +293,7 @@ ButtonMenu* button_menu_alloc(void) {
return true;
});

button_menu->freeze_input = false;
return button_menu;
}

Expand Down
2 changes: 1 addition & 1 deletion applications/gui/modules/button_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef struct ButtonMenu ButtonMenu;
typedef struct ButtonMenuItem ButtonMenuItem;

/* Callback for any button menu actions */
typedef void (*ButtonMenuItemCallback)(void* context, int32_t index);
typedef void (*ButtonMenuItemCallback)(void* context, int32_t index, InputType type);

/* Type of button. Difference in drawing buttons. */
typedef enum {
Expand Down
9 changes: 4 additions & 5 deletions applications/irda/cli/irda-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static void signal_received_callback(void* context, IrdaWorkerSignal* received_s
Cli* cli = (Cli*)context;

if(irda_worker_signal_is_decoded(received_signal)) {
const IrdaMessage* message = irda_worker_get_decoded_message(received_signal);
const IrdaMessage* message = irda_worker_get_decoded_signal(received_signal);
buf_cnt = sniprintf(
buf,
sizeof(buf),
Expand Down Expand Up @@ -54,16 +54,15 @@ static void irda_cli_start_ir_rx(Cli* cli, string_t args, void* context) {
}

IrdaWorker* worker = irda_worker_alloc();
irda_worker_set_context(worker, cli);
irda_worker_start(worker);
irda_worker_set_received_signal_callback(worker, signal_received_callback);
irda_worker_rx_start(worker);
irda_worker_rx_set_received_signal_callback(worker, signal_received_callback, cli);

printf("Receiving IRDA...\r\nPress Ctrl+C to abort\r\n");
while(!cli_cmd_interrupt_received(cli)) {
delay(50);
}

irda_worker_stop(worker);
irda_worker_rx_stop(worker);
irda_worker_free(worker);
}

Expand Down
5 changes: 2 additions & 3 deletions applications/irda/irda-app-brute-force.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "irda-app-brute-force.hpp"
#include "irda/irda-app-file-parser.hpp"
#include "irda-app-brute-force.h"
#include "irda/irda-app-file-parser.h"
#include "m-string.h"
#include <file-worker-cpp.h>
#include <memory>
Expand Down Expand Up @@ -47,7 +47,6 @@ void IrdaAppBruteForce::stop_bruteforce() {
}
}

// TODO: [FL-1418] replace with timer-chained consequence of messages.
bool IrdaAppBruteForce::send_next_bruteforce(void) {
furi_assert(current_record.size());
furi_assert(file_parser);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "furi/check.h"
#include <unordered_map>
#include "irda-app-file-parser.hpp"
#include "irda-app-file-parser.h"
#include <memory>

class IrdaAppBruteForce {
Expand All @@ -28,7 +28,9 @@ class IrdaAppBruteForce {
bool start_bruteforce(int index, int& record_amount);
void add_record(int index, const char* name);

IrdaAppBruteForce(const char* filename) : universal_db_filename (filename) {}
~IrdaAppBruteForce() {}
IrdaAppBruteForce(const char* filename)
: universal_db_filename(filename) {
}
~IrdaAppBruteForce() {
}
};

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class IrdaAppEvent {
Exit,
Back,
MenuSelected,
MenuSelectedPress,
MenuSelectedRelease,
DialogExSelected,
NextScene,
IrdaMessageReceived,
Expand All @@ -24,4 +26,3 @@ class IrdaAppEvent {

Type type;
};

4 changes: 2 additions & 2 deletions applications/irda/irda-app-file-parser.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "irda-app-file-parser.hpp"
#include "irda-app-file-parser.h"
#include "furi/check.h"
#include "irda-app-remote-manager.hpp"
#include "irda-app-remote-manager.h"
#include "irda-app-signal.h"
#include "m-string.h"
#include <text-store.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ class IrdaAppFileParser {
std::string make_name(const std::string& full_name) const;

private:
size_t stringify_message(const IrdaAppSignal& signal, const char* name, char* content, size_t content_len);
size_t stringify_raw_signal(const IrdaAppSignal& signal, const char* name, char* content, size_t content_len);
size_t stringify_message(
const IrdaAppSignal& signal,
const char* name,
char* content,
size_t content_len);
size_t stringify_raw_signal(
const IrdaAppSignal& signal,
const char* name,
char* content,
size_t content_len);
std::unique_ptr<IrdaFileSignal> parse_signal(const std::string& str) const;
std::unique_ptr<IrdaFileSignal> parse_signal_raw(const std::string& str) const;
std::string make_full_name(const std::string& name) const;
Expand All @@ -41,4 +49,3 @@ class IrdaAppFileParser {
char file_buf[128];
size_t file_buf_cnt = 0;
};

4 changes: 2 additions & 2 deletions applications/irda/irda-app-remote-manager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "irda-app-remote-manager.hpp"
#include "irda-app-remote-manager.h"
#include <storage/storage.h>
#include "furi.h"
#include "furi/check.h"
Expand All @@ -8,7 +8,7 @@
#include <stdint.h>
#include <string>
#include <utility>
#include "irda-app-file-parser.hpp"
#include "irda-app-file-parser.h"

static const std::string default_remote_name = "remote";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ class IrdaAppRemoteButton {
friend class IrdaAppRemoteManager;
std::string name;
IrdaAppSignal signal;

public:
IrdaAppRemoteButton(const char* name, const IrdaAppSignal& signal)
: name(name), signal (signal) {}
~IrdaAppRemoteButton() {}
: name(name)
, signal(signal) {
}
~IrdaAppRemoteButton() {
}
};

class IrdaAppRemote {
friend class IrdaAppRemoteManager;
std::vector<IrdaAppRemoteButton> buttons;
std::string name;

public:
IrdaAppRemote(const std::string& name) : name(name) {}
IrdaAppRemote(const std::string& name)
: name(name) {
}

IrdaAppRemote& operator=(std::string& new_name) noexcept
{
IrdaAppRemote& operator=(std::string& new_name) noexcept {
name = new_name;
buttons.clear();
return *this;
Expand Down Expand Up @@ -61,4 +67,3 @@ class IrdaAppRemoteManager {
bool store();
bool load(const std::string& name);
};

14 changes: 10 additions & 4 deletions applications/irda/irda-app-view-manager.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "furi.h"
#include "gui/modules/button_panel.h"
#include "irda-app.hpp"
#include "irda/irda-app-event.hpp"
#include "irda-app.h"
#include "irda/irda-app-event.h"
#include <callback-connector.h>

IrdaAppViewManager::IrdaAppViewManager() {
Expand Down Expand Up @@ -112,8 +112,14 @@ void IrdaAppViewManager::receive_event(IrdaAppEvent* event) {
}

void IrdaAppViewManager::send_event(IrdaAppEvent* event) {
osStatus_t result = osMessageQueuePut(event_queue, event, 0, 0);
furi_check(result == osOK);
uint32_t timeout = 0;
/* Rapid button hammering on Remote Scene causes queue overflow - ignore it,
* but try to keep button release event - it switches off IRDA DMA sending. */
if(event->type == IrdaAppEvent::Type::MenuSelectedRelease) {
timeout = 200;
}
osMessageQueuePut(event_queue, event, 0, timeout);
/* furi_check(result == osOK); */
}

uint32_t IrdaAppViewManager::previous_view_callback(void* context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <gui/modules/dialog_ex.h>
#include <gui/modules/submenu.h>
#include <gui/modules/popup.h>
#include "irda-app.hpp"
#include "irda-app.h"
#include "view/irda-app-brut-view.h"
#include "gui/modules/button_panel.h"

Expand Down Expand Up @@ -57,4 +57,3 @@ class IrdaAppViewManager {

void add_view(ViewType view_type, View* view);
};

21 changes: 16 additions & 5 deletions applications/irda/irda-app.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "irda-app.hpp"
#include "irda/irda-app-file-parser.hpp"
#include "irda-app.h"
#include "irda/irda-app-file-parser.h"
#include <irda_worker.h>
#include <furi.h>
#include <gui/gui.h>
Expand Down Expand Up @@ -222,22 +222,33 @@ void IrdaApp::notify_click() {
notification_message_block(notification, &sequence);
}

void IrdaApp::notify_click_and_blink() {
void IrdaApp::notify_click_and_green_blink() {
static const NotificationSequence sequence = {
&message_click,
&message_delay_1,
&message_sound_off,
&message_red_0,
&message_green_255,
&message_blue_0,
&message_delay_10,
&message_green_0,
&message_do_not_reset,
NULL,
};

notification_message_block(notification, &sequence);
}

void IrdaApp::notify_blink_green() {
static const NotificationSequence sequence = {
&message_green_255,
&message_delay_10,
&message_green_0,
&message_do_not_reset,
NULL,
};

notification_message(notification, &sequence);
}

void IrdaApp::notify_double_vibro() {
notification_message(notification, &sequence_double_vibro);
}
Expand Down