mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2026-03-13 04:44:44 +00:00
Merge branch 'main' into STM32
This commit is contained in:
178
IR-protocol.ino
178
IR-protocol.ino
@ -2,26 +2,16 @@
|
||||
#include "IR_Encoder.h"
|
||||
#include "TimerStatic.h"
|
||||
#include "MemoryCheck.h"
|
||||
#include "CarCmdList.h"
|
||||
/////////////// Pinout ///////////////
|
||||
|
||||
#define dec0_PIN PIN_KT1_IN
|
||||
#define dec1_PIN PIN_KT2_IN
|
||||
#define dec2_PIN PIN_KT3_IN
|
||||
#define dec3_PIN PIN_KT4_IN
|
||||
#define dec4_PIN PIN_KT5_IN
|
||||
#define dec5_PIN PIN_KT6_IN
|
||||
#define dec6_PIN PIN_KT7_IN
|
||||
#define dec7_PIN PIN_KT8_IN
|
||||
// #define dec8_PIN PB8
|
||||
// #define dec9_PIN PB9
|
||||
// #define dec10_PIN PB10
|
||||
// #define dec11_PIN PB11
|
||||
// #define dec12_PIN PB12
|
||||
// #define dec13_PIN PB13
|
||||
// #define dec14_PIN PB14
|
||||
// #define dec15_PIN PB15
|
||||
#define encForward_PIN 0
|
||||
#define encBackward_PIN 5
|
||||
|
||||
#define LoopOut PC13
|
||||
#define LoopOut 12
|
||||
#define ISR_Out 10
|
||||
|
||||
#define TestOut 13
|
||||
|
||||
//////////////// Ini /////////////////
|
||||
|
||||
@ -49,13 +39,35 @@ void EncoderISR()
|
||||
IR_Encoder::isr();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
void decBackwardISR() {
|
||||
decBackward.isr();
|
||||
}
|
||||
|
||||
IR_Decoder dec0(dec0_PIN, 0);
|
||||
void dec_0_ISR() { dec0.isr(); }
|
||||
static uint8_t* portOut;
|
||||
ISR(TIMER2_COMPA_vect) {
|
||||
encForward.isr();
|
||||
// encBackward.isr();
|
||||
// encTree.isr();
|
||||
//TODO: Сделать выбор порта
|
||||
*portOut = (*portOut & 0b11111110) |
|
||||
(
|
||||
encForward.ir_out_virtual << 0U
|
||||
// | encBackward.ir_out_virtual << 6U
|
||||
// | encTree.ir_out_virtual << 2U
|
||||
);
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
uint8_t data0 [] = { };
|
||||
uint8_t data1 [] = { 42 };
|
||||
uint8_t data2 [] = { 42 , 127 };
|
||||
uint8_t data3 [] = { 42 , 127, 137 };
|
||||
uint8_t data4 [] = { 42 , 127, 137, 255 };
|
||||
|
||||
IR_Decoder dec1(dec1_PIN, 1);
|
||||
void dec_1_ISR() { dec1.isr(); }
|
||||
uint32_t loopTimer;
|
||||
uint8_t sig = 255;
|
||||
|
||||
uint16_t targetAddr = IR_Broadcast;
|
||||
Timer t1(750, millis, []() {
|
||||
|
||||
IR_Decoder dec2(dec2_PIN, 2);
|
||||
void dec_2_ISR() { dec2.isr(); }
|
||||
@ -81,8 +93,19 @@ void dec_7_ISR() { dec7.isr(); }
|
||||
// IR_Decoder dec9(dec9_PIN, 9);
|
||||
// void dec_9_ISR() { dec9.isr(); }
|
||||
|
||||
// IR_Decoder dec10(dec10_PIN, 10);
|
||||
// void dec_10_ISR() { dec10.isr(); }
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// encBackward.sendData(IR_Broadcast, data2);
|
||||
// encTree.sendData(IR_Broadcast, rawData3);
|
||||
});
|
||||
Timer t2(500, millis, []() {
|
||||
digitalToggle(13);
|
||||
});
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
void setup() {
|
||||
IR_Encoder::timerSetup();
|
||||
portOut = &PORTB;
|
||||
|
||||
// IR_Decoder dec11(dec11_PIN, 11);
|
||||
// void dec_11_ISR() { dec11.isr(); }
|
||||
@ -100,9 +123,14 @@ uint8_t data2[] = {42, 127};
|
||||
uint8_t data3[] = {42, 127, 137};
|
||||
uint8_t data4[] = {42, 127, 137, 255};
|
||||
|
||||
uint32_t loopTimer;
|
||||
uint8_t sig = 0;
|
||||
uint16_t targetAddr = IR_Broadcast;
|
||||
pinMode(8, OUTPUT);
|
||||
pinMode(9, OUTPUT);
|
||||
pinMode(11, OUTPUT);
|
||||
pinMode(13, OUTPUT);
|
||||
pinMode(encForward_PIN, OUTPUT);
|
||||
pinMode(encBackward_PIN, OUTPUT);
|
||||
pinMode(13, OUTPUT);
|
||||
pinMode(12, OUTPUT);
|
||||
|
||||
Timer t1(500, millis, []()
|
||||
{
|
||||
@ -217,61 +245,30 @@ void setup()
|
||||
|
||||
pinMode(LoopOut, OUTPUT);
|
||||
|
||||
pinMode(dec0_PIN, INPUT_PULLUP);
|
||||
pinMode(dec1_PIN, INPUT_PULLUP);
|
||||
pinMode(dec2_PIN, INPUT_PULLUP);
|
||||
pinMode(dec3_PIN, INPUT_PULLUP);
|
||||
pinMode(dec4_PIN, INPUT_PULLUP);
|
||||
pinMode(dec5_PIN, INPUT_PULLUP);
|
||||
pinMode(dec6_PIN, INPUT_PULLUP);
|
||||
pinMode(dec7_PIN, INPUT_PULLUP);
|
||||
// pinMode(dec8_PIN, INPUT_PULLUP);
|
||||
// pinMode(dec9_PIN, INPUT_PULLUP);
|
||||
// pinMode(dec10_PIN, INPUT_PULLUP);
|
||||
// pinMode(dec11_PIN, INPUT_PULLUP);
|
||||
// pinMode(dec12_PIN, INPUT_PULLUP);
|
||||
// pinMode(dec13_PIN, INPUT_PULLUP);
|
||||
|
||||
attachInterrupt(dec0_PIN, dec_0_ISR, CHANGE);
|
||||
attachInterrupt(dec1_PIN, dec_1_ISR, CHANGE);
|
||||
attachInterrupt(dec2_PIN, dec_2_ISR, CHANGE);
|
||||
attachInterrupt(dec3_PIN, dec_3_ISR, CHANGE);
|
||||
attachInterrupt(dec4_PIN, dec_4_ISR, CHANGE);
|
||||
attachInterrupt(dec5_PIN, dec_5_ISR, CHANGE);
|
||||
attachInterrupt(dec6_PIN, dec_6_ISR, CHANGE);
|
||||
attachInterrupt(dec7_PIN, dec_7_ISR, CHANGE);
|
||||
// attachInterrupt(dec8_PIN, dec_8_ISR, CHANGE);
|
||||
// attachInterrupt(dec9_PIN, dec_9_ISR, CHANGE);
|
||||
// attachInterrupt(dec10_PIN, dec_10_ISR, CHANGE);
|
||||
// attachInterrupt(dec11_PIN, dec_11_ISR, CHANGE);
|
||||
// attachInterrupt(dec12_PIN, dec_12_ISR, CHANGE);
|
||||
// attachInterrupt(dec13_PIN, dec_13_ISR, CHANGE);
|
||||
attachInterrupt(0, decForwardISR, CHANGE); // D2
|
||||
attachInterrupt(1, decBackwardISR, CHANGE); // D3
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
digitalToggle(LoopOut);
|
||||
|
||||
bool testLed = false;
|
||||
uint32_t testLed_timer;
|
||||
|
||||
void loop() {
|
||||
// digitalToggle(LoopOut);
|
||||
Timer::tick();
|
||||
IR_Decoder::tick();
|
||||
|
||||
bool rx_flag = false;
|
||||
rx_flag |= status(dec0);
|
||||
rx_flag |= status(dec1);
|
||||
rx_flag |= status(dec2);
|
||||
rx_flag |= status(dec3);
|
||||
rx_flag |= status(dec4);
|
||||
rx_flag |= status(dec5);
|
||||
rx_flag |= status(dec6);
|
||||
rx_flag |= status(dec7);
|
||||
// rx_flag |= status(dec8);
|
||||
// rx_flag |= status(dec9);
|
||||
// rx_flag |= status(dec10);
|
||||
// rx_flag |= status(dec11);
|
||||
// rx_flag |= status(dec12);
|
||||
// rx_flag |= status(dec13);
|
||||
decForward.tick();
|
||||
decBackward.tick();
|
||||
|
||||
if (Serial.available())
|
||||
{
|
||||
status(decForward);
|
||||
status(decBackward);
|
||||
|
||||
|
||||
// Serial.println(micros() - loopTimer);
|
||||
// loopTimer = micros();
|
||||
// delayMicroseconds(120*5);
|
||||
|
||||
if (Serial.available()) {
|
||||
uint8_t in = Serial.parseInt();
|
||||
switch (in)
|
||||
{
|
||||
@ -289,6 +286,13 @@ void loop()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(testLed && millis() - testLed_timer > 100){
|
||||
testLed=false;
|
||||
digitalWrite(12, LOW);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -316,13 +320,19 @@ void detectSignal()
|
||||
// { digitalWrite(SignalDetectLed, LOW); });
|
||||
}
|
||||
|
||||
// test
|
||||
bool status(IR_Decoder &dec)
|
||||
{
|
||||
if (dec.gotData.available())
|
||||
{
|
||||
detectSignal();
|
||||
// Serial.println(micros());
|
||||
|
||||
|
||||
//test
|
||||
void status(IR_Decoder& dec) {
|
||||
if (dec.gotData.available() && dec.gotData.getAddrFrom() != 42) {
|
||||
|
||||
digitalWrite(12, HIGH);
|
||||
testLed = true;
|
||||
testLed_timer = millis();
|
||||
|
||||
encForward.sendData(IR_Broadcast, CarCmd::stop); //<<<<<<<<<<<<<<<<<<<<<<<<<<< CMD IS HERE
|
||||
|
||||
|
||||
String str;
|
||||
if (/* dec.gotData.getDataPrt()[1] */ 1)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user