Align main with fix-DMA-and-Analyzer (encoder API, sketch, .gitignore)

Restore IR_SendResult + sendDataFULL, fix IR-protocol.ino, match .gitignore to analyzer branch.

Made-with: Cursor
This commit is contained in:
2026-04-17 15:07:54 +03:00
parent a75fd0c564
commit b4f644c258
4 changed files with 91 additions and 103 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.vscode/* .vscode/*
bin/* bin/*
!.vscode/launch.json
log/* log/*
/.vscode /.vscode
*.zip *.zip

View File

@ -2,16 +2,26 @@
#include "IR_Encoder.h" #include "IR_Encoder.h"
#include "TimerStatic.h" #include "TimerStatic.h"
#include "MemoryCheck.h" #include "MemoryCheck.h"
#include "CarCmdList.h"
/////////////// Pinout /////////////// /////////////// Pinout ///////////////
#define encForward_PIN 0 #define dec0_PIN PIN_KT1_IN
#define encBackward_PIN 5 #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 LoopOut 12 #define LoopOut PC13
#define ISR_Out 10
#define TestOut 13
//////////////// Ini ///////////////// //////////////// Ini /////////////////
@ -39,35 +49,13 @@ void EncoderISR()
IR_Encoder::isr(); IR_Encoder::isr();
} }
void decBackwardISR() { //-------------------------------------------------------------------
decBackward.isr();
}
static uint8_t* portOut; IR_Decoder dec0(dec0_PIN, 0);
ISR(TIMER2_COMPA_vect) { void dec_0_ISR() { dec0.isr(); }
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 };
uint32_t loopTimer; IR_Decoder dec1(dec1_PIN, 1);
uint8_t sig = 255; void dec_1_ISR() { dec1.isr(); }
uint16_t targetAddr = IR_Broadcast;
Timer t1(750, millis, []() {
IR_Decoder dec2(dec2_PIN, 2); IR_Decoder dec2(dec2_PIN, 2);
void dec_2_ISR() { dec2.isr(); } void dec_2_ISR() { dec2.isr(); }
@ -93,19 +81,8 @@ void dec_7_ISR() { dec7.isr(); }
// IR_Decoder dec9(dec9_PIN, 9); // IR_Decoder dec9(dec9_PIN, 9);
// void dec_9_ISR() { dec9.isr(); } // void dec_9_ISR() { dec9.isr(); }
default: // IR_Decoder dec10(dec10_PIN, 10);
break; // void dec_10_ISR() { dec10.isr(); }
}
// 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); // IR_Decoder dec11(dec11_PIN, 11);
// void dec_11_ISR() { dec11.isr(); } // void dec_11_ISR() { dec11.isr(); }
@ -123,14 +100,9 @@ uint8_t data2[] = {42, 127};
uint8_t data3[] = {42, 127, 137}; uint8_t data3[] = {42, 127, 137};
uint8_t data4[] = {42, 127, 137, 255}; uint8_t data4[] = {42, 127, 137, 255};
pinMode(8, OUTPUT); uint32_t loopTimer;
pinMode(9, OUTPUT); uint8_t sig = 0;
pinMode(11, OUTPUT); uint16_t targetAddr = IR_Broadcast;
pinMode(13, OUTPUT);
pinMode(encForward_PIN, OUTPUT);
pinMode(encBackward_PIN, OUTPUT);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
Timer t1(500, millis, []() Timer t1(500, millis, []()
{ {
@ -245,30 +217,61 @@ void setup()
pinMode(LoopOut, OUTPUT); pinMode(LoopOut, OUTPUT);
attachInterrupt(0, decForwardISR, CHANGE); // D2 pinMode(dec0_PIN, INPUT_PULLUP);
attachInterrupt(1, decBackwardISR, CHANGE); // D3 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);
} }
void loop()
bool testLed = false; {
uint32_t testLed_timer; digitalToggle(LoopOut);
void loop() {
// digitalToggle(LoopOut);
Timer::tick(); Timer::tick();
IR_Decoder::tick();
decForward.tick(); bool rx_flag = false;
decBackward.tick(); 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);
status(decForward); if (Serial.available())
status(decBackward); {
// Serial.println(micros() - loopTimer);
// loopTimer = micros();
// delayMicroseconds(120*5);
if (Serial.available()) {
uint8_t in = Serial.parseInt(); uint8_t in = Serial.parseInt();
switch (in) switch (in)
{ {
@ -286,13 +289,6 @@ void loop() {
break; break;
} }
} }
if(testLed && millis() - testLed_timer > 100){
testLed=false;
digitalWrite(12, LOW);
}
} }
@ -320,19 +316,13 @@ void detectSignal()
// { digitalWrite(SignalDetectLed, LOW); }); // { digitalWrite(SignalDetectLed, LOW); });
} }
// test
bool status(IR_Decoder &dec)
//test {
void status(IR_Decoder& dec) { if (dec.gotData.available())
if (dec.gotData.available() && dec.gotData.getAddrFrom() != 42) { {
detectSignal();
digitalWrite(12, HIGH); // Serial.println(micros());
testLed = true;
testLed_timer = millis();
encForward.sendData(IR_Broadcast, CarCmd::stop); //<<<<<<<<<<<<<<<<<<<<<<<<<<< CMD IS HERE
String str; String str;
if (/* dec.gotData.getDataPrt()[1] */ 1) if (/* dec.gotData.getDataPrt()[1] */ 1)
{ {

View File

@ -477,10 +477,7 @@ IR_SendResult IR_Encoder::sendData(uint16_t addrTo, uint8_t *data, uint8_t len,
return sendDataFULL(id, addrTo, data, len, needAccept); return sendDataFULL(id, addrTo, data, len, needAccept);
} }
void IR_Encoder::sendData(uint16_t addrTo, uint8_t *data = nullptr, uint8_t len = 0, bool needAccept = false){ IR_SendResult IR_Encoder::sendDataFULL(uint16_t addrFrom, uint16_t addrTo, uint8_t *data, uint8_t len, bool needAccept)
sendData(id, addrTo, data, len, needAccept);
}
void IR_Encoder::sendData(uint16_t addrFrom, uint16_t addrTo, uint8_t *data = nullptr, uint8_t len = 0, bool needAccept = false)
{ {
if (len > bytePerPack) if (len > bytePerPack)
{ {

View File

@ -21,8 +21,7 @@ class IR_Encoder : public IR_FOX
static IR_Encoder *last; static IR_Encoder *last;
IR_Encoder *next; IR_Encoder *next;
public: public:
private: static HardwareTimer* IR_Timer;
// uint16_t id; /// @brief Адрес передатчика
using IR_TxGateRun = IrTxGateRun; using IR_TxGateRun = IrTxGateRun;
@ -97,9 +96,10 @@ public:
} }
void rawSend(uint8_t *ptr, uint8_t len); void rawSend(uint8_t *ptr, uint8_t len);
void sendData(uint16_t addrTo, uint8_t dataByte, bool needAccept = false); IR_SendResult sendData(uint16_t addrTo, uint8_t dataByte, bool needAccept = false);
void sendData(uint16_t addrTo, uint8_t *data = nullptr, uint8_t len = 0, bool needAccept = false); IR_SendResult sendData(uint16_t addrTo, uint8_t *data = nullptr, uint8_t len = 0, bool needAccept = false);
void sendData(uint16_t addrFrom, uint16_t addrTo, uint8_t *data = nullptr, uint8_t len = 0, bool needAccept = false); IR_SendResult sendDataFULL(uint16_t addrFrom, uint16_t addrTo, uint8_t *data = nullptr, uint8_t len = 0, bool needAccept = false);
IR_SendResult sendAccept(uint16_t addrTo, uint8_t customByte = 0); IR_SendResult sendAccept(uint16_t addrTo, uint8_t customByte = 0);
IR_SendResult sendRequest(uint16_t addrTo); IR_SendResult sendRequest(uint16_t addrTo);