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

added posibility to send raw data #406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions RCSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
1 change: 1 addition & 0 deletions RCSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down