You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
3.3 KiB
145 lines
3.3 KiB
#include "enc.h"
|
|
#include <arduino.h>
|
|
#include <esp32-hal-adc.h>
|
|
#include <HardwareSerial.h>
|
|
#include "radDisplay.h"
|
|
#include "extDisplay.h"
|
|
|
|
const int input[] = {};
|
|
long inputCurrentValue[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
|
long inputPreviewValue[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
|
const int numPins = sizeof(input) / sizeof(input[0]);
|
|
|
|
const int buttonInput[2] = {36,39};
|
|
int buttonLastState[2] = {HIGH, HIGH};
|
|
int buttonCurrentState[2];
|
|
|
|
String inputBuffer = "";
|
|
|
|
#define RXD2 (16)
|
|
#define TXD2 (17)
|
|
|
|
//#define DEBUGIO
|
|
|
|
void setup() {
|
|
#ifdef DEBUGIO
|
|
Serial.begin(115200);
|
|
#else
|
|
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
|
|
#endif
|
|
|
|
setupEncoder();
|
|
initRadDisplay();
|
|
initExtDisplay();
|
|
|
|
pinMode(buttonInput[0], INPUT);
|
|
|
|
analogReadResolution(12);
|
|
analogSetAttenuation(ADC_11db);
|
|
}
|
|
|
|
void loop() {
|
|
for (int i = 0; i < 2; i++) {
|
|
buttonCurrentState[i] = digitalRead(buttonInput[i]);
|
|
if (buttonLastState[i] == LOW && buttonCurrentState[i]){
|
|
#ifdef DEBUGIO
|
|
Serial.print(1001+i);
|
|
Serial.print("*");
|
|
Serial.print(buttonCurrentState[i]);
|
|
Serial.print("\n");
|
|
#else
|
|
Serial2.print(1001+i);
|
|
Serial2.print("*");
|
|
Serial2.print(buttonCurrentState[i]);
|
|
Serial2.print("\n");
|
|
#endif
|
|
}
|
|
buttonLastState[i] = buttonCurrentState[i];
|
|
}
|
|
|
|
|
|
for (int i = 0; i < numPins; i++) {
|
|
inputCurrentValue[i] = map(analogRead(input[i]), 0, 4096, 0, 16);
|
|
if (inputCurrentValue[i] != inputPreviewValue[i]) {
|
|
inputPreviewValue[i] = inputCurrentValue[i];
|
|
#ifdef DEBUGIO
|
|
Serial.print(input[i]);
|
|
Serial.print("*");
|
|
Serial.print(inputCurrentValue[i]);
|
|
Serial.print("\n");
|
|
#else
|
|
Serial2.print(input[i]);
|
|
Serial2.print("*");
|
|
Serial2.print(inputCurrentValue[i]);
|
|
Serial2.print("\n");
|
|
#endif
|
|
}
|
|
}
|
|
|
|
for (int enc = 0; enc < ENCODER_COUNT; enc++) {
|
|
if (getOldencoderCount(enc) != getEncoderCount(enc)) {
|
|
#ifdef DEBUGIO
|
|
Serial.print(101+enc);
|
|
Serial.print("*");
|
|
Serial.println (getEncoderCount(enc));
|
|
#else
|
|
Serial2.print(101+enc);
|
|
Serial2.print("*");
|
|
Serial2.println (getEncoderCount(enc));
|
|
#endif
|
|
setOldencoderCount(enc, getEncoderCount(enc));
|
|
}
|
|
}
|
|
|
|
//читаем кал
|
|
#ifdef DEBUGIO
|
|
while (Serial.available() > 0) {
|
|
char chr = Serial.read();
|
|
if (chr == '\n') {
|
|
processInput(inputBuffer);
|
|
inputBuffer = "";
|
|
} else {
|
|
inputBuffer += chr;
|
|
}
|
|
}
|
|
#else
|
|
while (Serial2.available() > 0) {
|
|
char chr = Serial2.read();
|
|
if (chr == '\n') {
|
|
processInput(inputBuffer);
|
|
inputBuffer = "";
|
|
} else {
|
|
inputBuffer += chr;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
delay(50);
|
|
}
|
|
|
|
void processInput(String input) {
|
|
input.trim();
|
|
|
|
int firstSpace = input.indexOf(' ');
|
|
int secondSpace = input.indexOf(' ', firstSpace + 1);
|
|
|
|
if (firstSpace == -1 || secondSpace == -1) {
|
|
return;
|
|
}
|
|
|
|
String n1 = input.substring(0, firstSpace);
|
|
String n2 = input.substring(firstSpace + 1, secondSpace);
|
|
String n3 = input.substring(secondSpace + 1);
|
|
|
|
int anyVar = n1.toInt();
|
|
int x = n2.toInt();
|
|
int y = n3.toInt();
|
|
|
|
if (anyVar == 10002) {
|
|
changeRad(n2.toFloat());
|
|
}
|
|
|
|
if (anyVar == 10001) {
|
|
changeExt(n2.toFloat());
|
|
}
|
|
}
|