long ir learner

This commit is contained in:
Siwat Sirichai 2023-11-06 00:10:00 +07:00
parent abeaf96288
commit 75967bf1b3
10 changed files with 235 additions and 0 deletions

5
IRLearner/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

10
IRLearner/.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

39
IRLearner/include/README Normal file
View File

@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

46
IRLearner/lib/README Normal file
View File

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

17
IRLearner/platformio.ini Normal file
View File

@ -0,0 +1,17 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:wt32-eth01]
platform = espressif32
board = wt32-eth01
framework = arduino
lib_deps = siwats/ESPMegaPROR3@^1.3.0
z3t0/IRremote@^4.2.0
monitor_speed = 115200

32
IRLearner/src/main.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <ESPMegaPRO.h>
// Infrared Transciever
#define IR_RECIEVE_PIN 35
#define IR_SEND_PIN 17
//#define MARK_EXCESS_MICROS 20
#define RAW_BUFFER_LENGTH 1024
uint16_t rawTicks[] = {2404, 597, 1204, 596, 603, 597, 1203, 598, 603, 597, 1203, 597, 603, 597, 603, 597, 1203, 596, 604, 597, 604, 596, 603, 597, 603, 25810, 2402, 597, 1204, 596, 604, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 603, 597, 1203, 597, 603, 597, 603, 597, 603, 598, 602, 25804, 2404, 596, 1204, 597, 603, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 603, 597, 1204, 596, 603, 597, 603, 597, 603, 597, 604, 25803, 2404, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 603, 598, 1202, 598, 602, 597, 603, 598, 602, 598, 602, 25805, 2403, 597, 1203, 597, 603, 597, 1203, 597, 603, 598, 1202, 597, 603, 597, 603, 597, 1203, 597, 603, 598, 602, 598, 602, 598, 602, 25804, 2404, 597, 1202, 598, 602, 598, 1202, 598, 602, 598, 1202, 599, 602, 598, 601, 598, 1203, 597, 602, 599, 602, 598, 602, 598, 602, 25804, 2403, 598, 1202, 599, 601, 599, 1202, 598, 601, 598, 1202, 599, 601, 599, 602, 598, 1202, 598, 602, 598, 602, 597, 603, 598, 602, 25805, 2403, 598, 1201, 599, 601, 599, 1202, 598, 602, 598, 1202, 598, 602, 599, 601, 598, 1203, 597, 602, 599, 602, 598, 602, 597, 603};
#include <IRremote.hpp>
void setup()
{
Serial.begin(115200);
// IrReceiver.begin(IR_RECIEVE_PIN);
IrSender.begin(IR_SEND_PIN);
}
void loop()
{
// if (IrReceiver.decode())
// {
// Serial.println();
// IrReceiver.printIRSendUsage(&Serial);
// IrReceiver.compensateAndPrintIRResultAsCArray(&Serial, false);
// Serial.println();
// Serial.println();
// IrReceiver.resume();
// }
//IrSender.sendRaw(ir_code_a,sizeof(ir_code_a)/sizeof(ir_code_a[0]),NEC_KHZ);
// IrSender.sendRaw(ir_code_b,sizeof(ir_code_b)/sizeof(ir_code_b[0]),NEC_KHZ);
IrSender.sendRaw(rawTicks,sizeof(rawTicks)/sizeof(rawTicks[0]),NEC_KHZ);
//IrSender.sendSony(0x1, 0x15, 2, 12);
delay(500);
}

73
IRLearner/src/main.cpp.d Normal file
View File

@ -0,0 +1,73 @@
#include <ESPMegaPRO.h>
/*
Author: AnalysIR
Revision: 1.0
This code is provided to overcome an issue with Arduino IR libraries
It allows you to capture raw timings for signals longer than 255 marks & spaces.
Typical use case is for long Air conditioner signals.
You can use the output to plug back into IRremote, to resend the signal.
This Software was written by AnalysIR.
Usage: Free to use, subject to conditions posted on blog below.
Please credit AnalysIR and provide a link to our website/blog, where possible.
Copyright AnalysIR 2014
Please refer to the blog posting for conditions associated with use.
http://www.analysir.com/blog/2014/03/19/air-conditioners-problems-recording-long-infrared-remote-control-signals-arduino/
Connections:
IR Receiver Arduino
V+ -> +5v
GND -> GND
Signal Out -> Digital Pin 2
(If using a 3V Arduino, you may connect V+ to +3V)
*/
void rxIR_Interrupt_Handler();
#define LEDPIN 17
//you may increase this value on Arduinos with greater than 2k SRAM
#define maxLen 800
volatile unsigned int irBuffer[maxLen]; //stores timings - volatile because changed by ISR
volatile unsigned int x = 0; //Pointer thru irBuffer - volatile because changed by ISR
void setup() {
Serial.begin(115200); //change BAUD rate as required
attachInterrupt(digitalPinToInterrupt(35), rxIR_Interrupt_Handler, CHANGE);//set up ISR for receiving IR signal
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(F("Press the button on the remote now - once only"));
delay(5000); // pause 5 secs
if (x) { //if a signal is captured
digitalWrite(LEDPIN, HIGH);//visual indicator that signal received
Serial.println();
Serial.print(F("Raw: (")); //dump raw header format - for library
Serial.print((x - 1));
Serial.print(F(") "));
detachInterrupt(0);//stop interrupts & capture until finshed here
for (int i = 1; i < x; i++) { //now dump the times
if (!(i & 0x1)) Serial.print(F("-"));
Serial.print(irBuffer[i] - irBuffer[i - 1]);
Serial.print(F(", "));
}
x = 0;
Serial.println();
Serial.println();
digitalWrite(LEDPIN, LOW);//end of visual indicator, for this time
attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE);//re-enable ISR for receiving IR signal
}
}
void rxIR_Interrupt_Handler() {
if (x > maxLen) return; //ignore if irBuffer is already full
irBuffer[x++] = micros(); //just continually record the time-stamp of signal transitions
}

1
IRLearner/src/test.txt Normal file
View File

@ -0,0 +1 @@
{438, 430, 435, 430, 436, 430, 435, 430, 436, 430, 435, 25095, 3467, 1727, 436, 1295, 436, 430, 435, 430, 436, 430, 435, 1295, 436, 430, 436, 430, 436, 429, 435, 431, 436, 1294, 436, 429, 436, 1295, 437, 1294, 437, 429, 436, 1295, 437, 1294, 436, 1295, 436, 1296, 435, 1295, 436, 430, 436, 429, 436, 1295, 436, 432, 434, 429, 436, 429, 436, 430, 436, 429, 436, 431, 434, 431, 435, 430, 436, 430, 436, 429, 436, 1295, 436, 429, 436, 1296, 435, 430, 436, 430, 436, 429, 436, 1295, 436, 1295, 435, 430, 436, 430, 436, 429, 436, 430, 436, 1295, 436, 429, 436, 430, 435, 430, 436, 430, 435, 430, 436, 429, 436, 430, 436, 430, 435, 429, 437, 429, 436, 430, 436, 1295, 436, 1295, 435, 1296, 436, 430, 435, 430, 435, 1296, 436, 1295, 436, 1296, 435, 35481, 3466, 1728, 436, 1296, 435, 429, 436, 430, 436, 429, 436, 1295, 436, 429, 436, 430, 436, 430, 435, 430, 436, 1295, 436, 429, 436, 1295, 436, 1295, 436, 430, 436, 1295, 436, 1295, 436, 1295, 436, 1295, 436, 1295, 436, 429, 436, 430, 436, 1295, 436, 429, 436, 429, 436, 430, 436, 430, 436, 429, 436, 430, 435, 430, 436, 430, 435, 430, 436, 430, 435, 430, 436, 1294, 437, 430, 436, 429, 436, 429, 436, 430, 436, 1295, 436, 429, 437, 429, 436, 430, 435, 431, 435, 429, 436, 430, 436, 430, 436, 429, 436, 430, 435, 430, 436, 430, 436, 429, 435, 430, 437, 1295, 435, 430, 436, 430, 435, 431, 435, 429, 437, 429, 436, 1295, 436, 429, 436, 429, 437, 1295, 436, 1295, 436, 429, 436, 35481, 3466, 1728, 436, 1295, 436, 429, 436, 430, 436, 430, 435, 1296, 436, 429, 436, 429, 436, 430, 436, 429, 436, 1295, 436, 430, 436, 1294, 437, 1296, 435, 429, 436, 1294, 437, 1295, 436, 1295, 436, 1296, 435, 1295, 436, 430, 436, 429, 436, 1295, 435, 431, 435, 430, 436, 430, 435, 430, 436, 430, 435, 430, 436, 430, 435, 430, 436, 430, 435, 430, 436, 429, 437, 429, 436, 429, 437, 429, 436, 429, 436, 430, 435, 430, 436, 429, 436, 1296, 435, 430, 436, 430, 436, 1295, 436, 1295, 436, 1294, 437, 429, 436, 431, 434, 430, 436, 430, 436, 1295, 436, 429, 436, 1295, 436, 1295, 436, 430, 435, 430, 436, 430, 435, 430, 436, 430, 435, 430, 436, 429, 436, 429, 437, 430, 436, 429, 436, 1295, 435, 1296, 436, 1295, 436, 1295, 436, 1295, 436, 1295, 436, 1295, 436, 430, 435, 430, 436, 430, 435, 429, 437, 429, 436, 430, 436, 429, 436, 430, 436, 429, 436, 430, 435, 431, 435, 429, 436, 430, 436, 429, 436, 430, 436, 430, 435, 430, 436, 429, 436, 1295, 436, 1296, 435, 430, 436, 430, 436, 430, 435, 430, 435, 430, 436, 430, 436, 429, 436, 429, 436, 430, 436, 429, 436, 1296, 435, 1295, 437, 429, 436, 429, 437, 429, 436, 429, 437, 429, 436, 430, 435, 430, 436, 429, 436, 430, 436, 429, 436, 430, 436, 429, 436, 429, 436, 430, 436, 430, 437, 427, 437, 430, 435, 1296, 436, 429, 436, 1295, 436, 430, 435, 430, 436, 430, 436, 1295, 435, 1296, 435, 430, 436, 430, 435, 430, 436, 430, 436, 429, 436, 430, 435, 430, 436, 430, 435, 430, 436, 429, 436, 430, 436, 1295, 436, 430, 436, 430, 435, 430, 435, 430, 436, 1295, 436, 430, 436, 430, 435, 430, 435, 1295, 436, 1295, 436, 430, 436, 429, 436}

1
IRLearner/src/test2.txt Normal file
View File

@ -0,0 +1 @@
2404, 597, 1204, 596, 603, 597, 1203, 598, 603, 597, 1203, 597, 603, 597, 603, 597, 1203, 596, 604, 597, 604, 596, 603, 597, 603, 25810, 2402, 597, 1204, 596, 604, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 603, 597, 1203, 597, 603, 597, 603, 597, 603, 598, 602, 25804, 2404, 596, 1204, 597, 603, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 603, 597, 1204, 596, 603, 597, 603, 597, 603, 597, 604, 25803, 2404, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 603, 598, 1202, 598, 602, 597, 603, 598, 602, 598, 602, 25805, 2403, 597, 1203, 597, 603, 597, 1203, 597, 603, 598, 1202, 597, 603, 597, 603, 597, 1203, 597, 603, 598, 602, 598, 602, 598, 602, 25804, 2404, 597, 1202, 598, 602, 598, 1202, 598, 602, 598, 1202, 599, 602, 598, 601, 598, 1203, 597, 602, 599, 602, 598, 602, 598, 602, 25804, 2403, 598, 1202, 599, 601, 599, 1202, 598, 601, 598, 1202, 599, 601, 599, 602, 598, 1202, 598, 602, 598, 602, 597, 603, 598, 602, 25805, 2403, 598, 1201, 599, 601, 599, 1202, 598, 602, 598, 1202, 598, 602, 599, 601, 598, 1203, 597, 602, 599, 602, 598, 602, 597, 603,

11
IRLearner/test/README Normal file
View File

@ -0,0 +1,11 @@
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html