raspberry
This commit is contained in:
1 parent
84dfdf5210
commit
be436085b3
55 files changed
+2195
No files matched your search
@@ -0,0 +1,68 @@
|
||||
#include "/home/lucas/433Utils/rc-switch/RCSwitch.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
RCSwitch mySwitch;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// This pin is not the first pin on the RPi GPIO header!
|
||||
// Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/
|
||||
// for more information.
|
||||
int PIN = 2; //G27
|
||||
|
||||
if(wiringPiSetup() == -1) {
|
||||
printf("wiringPiSetup failed, exiting...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pulseLength = 0;
|
||||
if (argv[1] != NULL) pulseLength = atoi(argv[1]);
|
||||
|
||||
mySwitch = RCSwitch();
|
||||
if (pulseLength != 0) mySwitch.setPulseLength(pulseLength);
|
||||
mySwitch.enableReceive(PIN); // Receiver on interrupt 0 => that is pin #2
|
||||
unsigned long value;
|
||||
unsigned long previous=0;
|
||||
int length;
|
||||
int protocol;
|
||||
unsigned int* raw;
|
||||
struct timeval time1,time2;
|
||||
long long elapsedTime;
|
||||
int delay;
|
||||
printf("Stetup Finished, Start Sniffing\n");
|
||||
while(1) {
|
||||
|
||||
if (mySwitch.available()) {
|
||||
|
||||
value = mySwitch.getReceivedValue();
|
||||
length = mySwitch.getReceivedBitlength();
|
||||
protocol = mySwitch.getReceivedProtocol();
|
||||
raw = mySwitch.getReceivedRawdata();
|
||||
delay = mySwitch.getReceivedDelay();
|
||||
if (value == 0)
|
||||
{
|
||||
printf("Unknown encoding\n");
|
||||
}
|
||||
else if (value != previous)
|
||||
{
|
||||
gettimeofday(&time1,NULL);
|
||||
printf("Received %i\nLength: %i\nProtocol: %i\nDelay: %i\nRaw Data:\n", value,length,protocol, delay );
|
||||
for (int i=0; i<= length*2; i++)
|
||||
{
|
||||
printf("%i",raw[i]);
|
||||
printf(",");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
previous = value;
|
||||
mySwitch.resetAvailable();
|
||||
|
||||
}
|
||||
gettimeofday(&time2,NULL);
|
||||
if ((time2.tv_sec - time1.tv_sec) > 2) previous=0;
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user