Skip to content

Commit

Permalink
ir: clean-up and refactoring of the existing module
Browse files Browse the repository at this point in the history
- provide a queue for the outgoing messages, don't depend on the MQTT
  callback implementation details and always postpone the actual transfer.
- generate user input parsers using re2c, adds special PlatformIO build handlers
- add terminal command to show GPIO info and send a simple payload
- rework button<->action presets into value<->terminal command presets and custom ones
  through the use of `irCmd<VALUE>` settings, where the VALUE is taken from the simple payload
  (yet, it does not understand repeated codes, but that's something to add later *or* use rpnlib)
- add tx message integration for the relay module via `irRelayOn#` and `irRelayOff#`
- rework simple payload to include 'repeats' value for the 'IRsend::send()'
  also adds internal 'series', 'delay' and includes full 64bit 'value'
  (as uppercase HEX, instead of decimal)
- rework raw payload to use 'series' instead of 'repeats', and provide a
  clear distinction between the usec time and the options of the message
  by moving the required options to the front and separating them using ':'
  (just like the simple variant)
- make RX and TX pin a runtime setting, make RX and TX support a build flag
- small test framework to check whether internal string encode<->decode works

Also updates the hexEncode & hexDecode implementations to use
'iterators' instead of just pointer + index.
  • Loading branch information
mcspr committed Oct 3, 2021
1 parent 62d83c6 commit 001ec79
Show file tree
Hide file tree
Showing 20 changed files with 2,461 additions and 623 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
*.ini text eol=lf
*.h text eol=lf
*.cpp text eol=lf
*.re text eol=lf
*.cpp.inc text eol=lf
*.c text eol=lf
5 changes: 5 additions & 0 deletions code/espurna/config/deprecated.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,8 @@
#ifdef PZEM004T_ADDRESSES
#warning "PZEM004T_ADDRESSES is deprecated! Addresses can be set by using individual flags PZEM004T_ADDRESS_{1,2,3}"
#endif

#if defined(IR_BUTTON_SET) && not defined(IT_RX_PRESET)
#define IR_RX_PRESET IR_BUTTON_SET
#warning "IR_BUTTON_SET was renamed to IR_RX_PRESET"
#endif
79 changes: 63 additions & 16 deletions code/espurna/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -1532,35 +1532,82 @@
#define IR_SUPPORT 0 // Do not build with IR support by default (10.25Kb)
#endif

//#define IR_RX_PIN 5 // GPIO the receiver is connected to
//#define IR_TX_PIN 4 // GPIO the transmitter is connected to
#ifndef IR_RX_SUPPORT
#define IR_RX_SUPPORT 1 // (boolean) IR receiver support in the build (~30Kb, enabled by default)
#endif

#ifndef IR_RX_PIN
#define IR_RX_PIN GPIO_NONE // GPIO the receiver is connected to
#endif

#ifndef IR_TX_SUPPORT
#define IR_TX_SUPPORT 1 // (boolean) IR transmitter support in the build (~8Kb, enabled by default)
#endif

#ifndef IR_TX_PIN
#define IR_TX_PIN GPIO_NONE // GPIO the transmitter is connected to
#endif

#ifndef IR_RX_BUFFER_SIZE
#define IR_RX_BUFFER_SIZE 128 // (ms, internal) size of the buffer that will be used to store the captured data
// required heap amount is the buffer size multiplied by four (default is 512bytes)
#endif

#ifndef IR_RX_TIMEOUT
#define IR_RX_TIMEOUT 15 // (ms, internal) amount of time of no IR signal before the library stops capturing the data
#endif

#ifndef IR_RX_MQTT
#define IR_RX_MQTT 1 // (boolean) Report basic codes
#endif

#ifndef IR_RX_RAW_MQTT
#define IR_RX_RAW_MQTT 0 // (boolean) Report RAW codes
#endif

#ifndef IR_RX_MQTT_TOPIC
#define IR_RX_MQTT_TOPIC "irin" // (string) MQTT topic magnitude used to publish the received messages
#endif

#ifndef IR_TX_MQTT_TOPIC
#define IR_TX_MQTT_TOPIC "irout" // (string) MQTT topic magnitude to subscribe to transmit messages
#endif


#ifndef IR_USE_RAW
#define IR_USE_RAW 0 // Use raw codes
#ifndef IR_RX_RAW_MQTT_TOPIC
#define IR_RX_RAW_MQTT_TOPIC "irraw" // (boolean) MQTT topic magnitude to subscribe and publish RAW messages
#endif

#ifndef IR_BUFFER_SIZE
#define IR_BUFFER_SIZE 1024
#ifndef IR_TX_RAW_MQTT_TOPIC
#define IR_TX_RAW_MQTT_TOPIC "irraw" // (boolean) MQTT topic magnitude to subscribe and publish RAW messages
#endif

#ifndef IR_TIMEOUT
#define IR_TIMEOUT 15U
#ifndef IR_TX_SERIES
#define IR_TX_SERIES 1 // (number) default number of times that the message will be sent
// (can be overriden in the MQTT payload for the specific message)
#endif

#ifndef IR_REPEAT
#define IR_REPEAT 1
#ifndef IR_TX_DELAY
#define IR_TX_DELAY 100 // (ms) minimum amount of time to wait before transmitting another message
// (when using series >1, will also wait between the same message)
#endif

#ifndef IR_DELAY
#define IR_DELAY 100
#ifndef IR_RX_DELAY
#define IR_RX_DELAY 100 // (ms) minimum amount of time to wait before processing incomming message
#endif

#ifndef IR_DEBOUNCE
#define IR_DEBOUNCE 500 // IR debounce time in milliseconds
#ifndef IR_RX_PRESET
#define IR_RX_PRESET 0 // (number) IR-code-as-button preset to use
// 0 - disabled
// 1,2,5 - generic remote shipped with the RGB controller
// 3 - Samsung AA59-00608A for a generic 8CH module
// 4 - Remote for a generic 1CH module
// (~1Kb, see ir.cpp for more info about the presets)
#endif

#ifndef IR_BUTTON_SET
#define IR_BUTTON_SET 0 // IR button set to use (see ../ir_button.h)
#ifndef IR_TEST_SUPPORT
#define IR_TEST_SUPPORT 0 // (boolean) enables internal tests and sanity checks that will be called on boot
// (~5Kb, disabled by default and should only be enabled with debug support)
#endif

//--------------------------------------------------------------------------------
Expand Down
12 changes: 8 additions & 4 deletions code/espurna/config/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,8 @@
// IR
#define IR_SUPPORT 1
#define IR_RX_PIN 4
#define IR_BUTTON_SET 1
#define IR_TX_SUPPORT 0
#define IR_RX_PRESET 1

#elif defined(MAGICHOME_LED_CONTROLLER_20)

Expand All @@ -1326,7 +1327,8 @@
// IR
#define IR_SUPPORT 1
#define IR_RX_PIN 4
#define IR_BUTTON_SET 1
#define IR_TX_SUPPORT 0
#define IR_RX_PRESET 1

#elif defined(MAGICHOME_ZJ_WFMN_A_11)

Expand All @@ -1350,7 +1352,8 @@
// IR
#define IR_SUPPORT 1
#define IR_RX_PIN 4
#define IR_BUTTON_SET 1
#define IR_TX_SUPPORT 0
#define IR_RX_PRESET 1

#elif defined(MAGICHOME_ZJ_WFMN_B_11)

Expand Down Expand Up @@ -4742,7 +4745,8 @@
// IR
#define IR_SUPPORT 1
#define IR_RX_PIN 0
#define IR_BUTTON_SET 5
#define IR_TX_SUPPORT 0
#define IR_RX_PRESET 5

// -----------------------------------------------------------------------------
// eHomeDIY WT02
Expand Down
Loading

0 comments on commit 001ec79

Please sign in to comment.