This repository has been archived by the owner on Aug 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathir_replay.h
102 lines (92 loc) · 2.42 KB
/
ir_replay.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRsend.h>
#include "FS.h"
#include "SPIFFS.h"
#define MAX_RAWBUF_SIZE 100
decode_results results;
uint16_t* rawcode;
int rawDataLen;
IRrecv irrecv(IRRECV);
void setupReceiver() {
DISP.fillScreen(BGCOLOR);
DISP.setTextSize(BIG_TEXT);
DISP.setCursor(0, 0);
DISP.println("IR Replay");
irrecv.enableIRIn();
delay(500);
}
void receiveSignal() {
DISP.fillScreen(BGCOLOR);
DISP.setTextSize(BIG_TEXT);
DISP.setCursor(0, 0);
DISP.println("Receiver");
DISP.setTextSize(MEDIUM_TEXT);
DISP.println("Waiting...");
pinMode(IRRECV, INPUT);
while(true){
if (irrecv.decode(&results)) {
rawcode = new uint16_t[MAX_RAWBUF_SIZE];
memset(rawcode, 0, MAX_RAWBUF_SIZE * sizeof(uint16_t));
rawDataLen = results.rawlen;
DISP.fillScreen(BGCOLOR);
DISP.setTextSize(BIG_TEXT);
DISP.setCursor(0, 0);
DISP.println("Receiver");
DISP.setTextSize(MEDIUM_TEXT);
DISP.println("Recorded!");
DISP.print(results.value, HEX);
Serial.print("Raw Data ");
Serial.print(rawDataLen);
Serial.print(" : ");
//String RawString = "";
for (int i = 1; i < results.rawlen; i++) {
//RawString += String(results.rawbuf[i]);
Serial.print(results.rawbuf[i], DEC);
if (i < results.rawlen - 1){
Serial.print(", ");
//RawString += ", ";
}
rawcode[i - 1] = results.rawbuf[i] * 2;
}
//saveToSpiffs(RawString);
Serial.println();
Serial.print("Hex: ");
Serial.println(results.value, HEX);
irrecv.resume();
pinMode(IRRECV, OUTPUT);
delay(1000);
break;
}
}
}
void sendSignal() {
irsend.begin();
DISP.fillScreen(BGCOLOR);
DISP.setTextSize(BIG_TEXT);
DISP.setCursor(0, 0);
DISP.println("IR Sender");
DISP.setTextSize(MEDIUM_TEXT);
DISP.println("Sending...");
Serial.println("Sending Custom");
irsend.sendRaw(rawcode, rawDataLen, 38); // 38Khz
delay(1000);
}
void saveToSpiffs(String rawData){
if (!SPIFFS.begin()) {
Serial.println("Failed to mount SPIFFS");
return;
}
Serial.println("SPIFFS successfully mounted");
File file = SPIFFS.open("/FNemoIR.txt", FILE_WRITE);
if (!file) {
Serial.println("Error opening the file");
return;
}
if (file.println(rawData)) {
Serial.println("IR saved successfully");
} else {
Serial.println("Error saving IR");
}
file.close();
}