From 90a5cab876aa3a10d00700631a3f286859446cf5 Mon Sep 17 00:00:00 2001 From: MPK44 Date: Tue, 9 Feb 2021 18:45:09 +0100 Subject: [PATCH] added posibility to send raw data As not all protocolls are already identified a possibility to send data without decrypting a new protocoll is helpful. This commit adds the function sendraw so that a file storing pulselengths can be used to send commands. --- RCSwitch.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ RCSwitch.h | 1 + 2 files changed, 54 insertions(+) diff --git a/RCSwitch.cpp b/RCSwitch.cpp index 6c821cb..4758786 100644 --- a/RCSwitch.cpp +++ b/RCSwitch.cpp @@ -528,6 +528,59 @@ void RCSwitch::send(unsigned long code, unsigned int length) { #endif } +/** + * Use a file storing raw data to transmit codes with unknown protocols. + * Each line of the file stores the length of a high (odd linenumber) or a low (even linenumber) pulse in ms + */ +void RCSwitch::sendraw(const char* sFilename) { + int i=0; + int j; + int high, low; + FILE *file; + int array_l[1000]; + int array_h[1000]; + + if (this->nTransmitterPin == -1) + return; +#if not defined( RCSwitchDisableReceiving ) + // make sure the receiver is disabled while we transmit + int nReceiverInterrupt_backup = nReceiverInterrupt; + if (nReceiverInterrupt_backup != -1) { + this->disableReceive(); + } +#endif + + file=fopen(sFilename,"r"); + if(file==NULL){ + printf("%s not read", sFilename); + return; + } + + while (fscanf (file, "%d\n%d\n",&high, &low)>0) + { + array_h[i]=high; + array_l[i]=low; + i++; + } + + for(j=0; j<=i; j++){ + digitalWrite(this->nTransmitterPin, HIGH); + delayMicroseconds( array_h[j]); + digitalWrite(this->nTransmitterPin, LOW); + delayMicroseconds( array_l[j]); + } + + // Disable transmit after sending (i.e., for inverted protocols) + digitalWrite(this->nTransmitterPin, LOW); + +#if not defined( RCSwitchDisableReceiving ) + // enable receiver again if we just disabled it + if (nReceiverInterrupt_backup != -1) { + this->enableReceive(nReceiverInterrupt_backup); + } +#endif +} + /** * Transmit a single high-low pulse. */ diff --git a/RCSwitch.h b/RCSwitch.h index b7755e0..f2edce7 100644 --- a/RCSwitch.h +++ b/RCSwitch.h @@ -79,6 +79,7 @@ class RCSwitch { void sendTriState(const char* sCodeWord); void send(unsigned long code, unsigned int length); void send(const char* sCodeWord); + void sendraw(const char* sFilename); #if not defined( RCSwitchDisableReceiving ) void enableReceive(int interrupt);