Skip to content

Commit

Permalink
[P035] Add Inverted output option, as supported by the IRsend library
Browse files Browse the repository at this point in the history
  • Loading branch information
tonhuisman committed Jul 21, 2023
1 parent 680db27 commit 130a755
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
13 changes: 11 additions & 2 deletions src/_P035_IRTX.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
// #######################################################################################################
//
// Changelog:
// 2022-08-08, tonhuisman: Fix listProtocols()/listACProtocols() to ignore 1-character type names
// 2023-07-21, tonhuisman: Add 'Inverted output' option, as supported by the IRsend class.
// 2022-08-08, tonhuisman: Fix listProtocols()/listACProtocols() to ignore 1-character type names
// 2022-01-11, tonhuisman: Move all code and globals to PluginStructs/P035_data_struct to enable multi-instance use
// No previous changelog recorded.

Expand Down Expand Up @@ -75,6 +76,8 @@ boolean Plugin_035(uint8_t function, struct EventStruct *event, String& string)
}
case PLUGIN_WEBFORM_LOAD:
{
addFormCheckBox(F("Inverted output"), F("invert"), PCONFIG(0) == 1);

addRowLabel(F("Command"));
addHtml(F("IRSEND,[PROTOCOL],[DATA],[BITS optional],[REPEATS optional]<BR>BITS and REPEATS are optional and default to 0<BR/>"));
addHtml(F("IRSENDAC,{JSON formated AC command}"));
Expand All @@ -83,9 +86,15 @@ boolean Plugin_035(uint8_t function, struct EventStruct *event, String& string)
break;
}

case PLUGIN_WEBFORM_SAVE:
{
PCONFIG(0) = isFormItemChecked(F("invert")) ? 1 : 0;
break;
}

case PLUGIN_INIT:
{
initPluginTaskData(event->TaskIndex, new (std::nothrow) P035_data_struct(CONFIG_PIN1));
initPluginTaskData(event->TaskIndex, new (std::nothrow) P035_data_struct(CONFIG_PIN1, PCONFIG(0) == 1));
P035_data_struct *P035_data = static_cast<P035_data_struct *>(getPluginTaskData(event->TaskIndex));

if (nullptr == P035_data) {
Expand Down
6 changes: 3 additions & 3 deletions src/src/PluginStructs/P035_data_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// **************************************************************************/
// Constructor
// **************************************************************************/
P035_data_struct::P035_data_struct(int8_t gpioPin)
: _gpioPin(gpioPin) {}
P035_data_struct::P035_data_struct(int8_t gpioPin, bool inverted)
: _gpioPin(gpioPin), _inverted(inverted) {}

// **************************************************************************/
// Destructor
Expand Down Expand Up @@ -36,7 +36,7 @@ bool P035_data_struct::plugin_init(struct EventStruct *event) {
addLog(LOG_LEVEL_INFO, String(F("Supported Protocols by IRSEND: ")) + listProtocols());
# endif // ifdef P035_DEBUG_LOG
}
Plugin_035_irSender = new (std::nothrow) IRsend(_gpioPin);
Plugin_035_irSender = new (std::nothrow) IRsend(_gpioPin, _inverted);

if (Plugin_035_irSender != nullptr) {
Plugin_035_irSender->begin(); // Start the sender
Expand Down
4 changes: 3 additions & 1 deletion src/src/PluginStructs/P035_data_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ extern void enableIR_RX(boolean enable); // To be found in _P016_IR.ino
struct P035_data_struct : public PluginTaskData_base {
public:

P035_data_struct(int8_t gpioPin);
P035_data_struct(int8_t gpioPin,
bool inverted);

P035_data_struct() = delete;
virtual ~P035_data_struct();
Expand Down Expand Up @@ -66,6 +67,7 @@ struct P035_data_struct : public PluginTaskData_base {
const String str);

int8_t _gpioPin;
bool _inverted;
};
#endif // ifdef USES_P035
#endif // ifndef PLUGINSTRUCTS_P035_DATA_STRUCT_H

0 comments on commit 130a755

Please sign in to comment.