初始化提交
This commit is contained in:
125
arduino-cli/libraries/AppEsp32BtRec/AppEsp32BtRec.cpp
Normal file
125
arduino-cli/libraries/AppEsp32BtRec/AppEsp32BtRec.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
#include "AppEsp32BtRec.h"
|
||||
#if defined(ESP32)
|
||||
AppBtRec::AppBtRec(BluetoothSerial& _SerialBT,bool _monitorPRINT) {
|
||||
monitorPRINT=_monitorPRINT;
|
||||
IsStarts = false;
|
||||
IsVal = false;
|
||||
Mark = false;
|
||||
ValNum = 0;
|
||||
REceiveChar = "";
|
||||
SerialBT = &_SerialBT;
|
||||
}
|
||||
#elif defined(ESP8266)
|
||||
AppBtRec::AppBtRec(Stream& _SerialBT,bool _monitorPRINT) {
|
||||
monitorPRINT=_monitorPRINT;
|
||||
IsStarts = false;
|
||||
IsVal = false;
|
||||
Mark = false;
|
||||
ValNum = 0;
|
||||
REceiveChar = "";
|
||||
SerialBT = &_SerialBT;
|
||||
}
|
||||
#endif
|
||||
void AppBtRec::PortReceive() {
|
||||
if (SerialBT->available() > 0) {
|
||||
byte ReadByte = SerialBT->read();
|
||||
// if(monitorPRINT)
|
||||
// Serial.write(ReadByte);
|
||||
switch (ReadByte) {
|
||||
case ',':
|
||||
IsStarts = true;
|
||||
REceiveChar = "";
|
||||
break;
|
||||
case '.':
|
||||
if (IsVal) {
|
||||
switch (ValNum) {
|
||||
case 1:
|
||||
val1 = REceiveChar.toInt();
|
||||
if(monitorPRINT)
|
||||
Serial.println(String("val1:")+val1);
|
||||
break;
|
||||
case 2:
|
||||
val2 = REceiveChar.toInt();
|
||||
if(monitorPRINT)
|
||||
Serial.println(String("val2:")+val2);
|
||||
break;
|
||||
case 3:
|
||||
val3 = REceiveChar.toInt();
|
||||
if(monitorPRINT)
|
||||
Serial.println(String("val3:")+val3);
|
||||
break;
|
||||
case 4:
|
||||
val4 = REceiveChar.toInt();
|
||||
if(monitorPRINT)
|
||||
Serial.println(String("val4:")+val4);
|
||||
break;
|
||||
case 5:
|
||||
val5 = REceiveChar.toInt();
|
||||
if(monitorPRINT)
|
||||
Serial.println(String("val5:")+val5);
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
Last_Data = REceiveChar;
|
||||
if(monitorPRINT)
|
||||
Serial.println(String("REceiveChar:")+REceiveChar);
|
||||
}
|
||||
ValNum = 0;
|
||||
IsStarts = false;
|
||||
IsVal = false;
|
||||
Mark = false;
|
||||
break;
|
||||
case '!':
|
||||
IsVal = true;
|
||||
Mark = true;
|
||||
break;
|
||||
default:
|
||||
if (IsStarts) {
|
||||
if (IsVal) {
|
||||
if (Mark) {
|
||||
ValNum = ReadByte - '0';
|
||||
Mark = false;
|
||||
}
|
||||
else {
|
||||
REceiveChar += char(ReadByte);
|
||||
}
|
||||
} else {
|
||||
REceiveChar += char(ReadByte);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
bool AppBtRec::IsObject(String obj ) {
|
||||
if (obj == REceiveChar) {
|
||||
REceiveChar = "";
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
int AppBtRec::GetVal(uint8_t num) {
|
||||
switch (num) {
|
||||
case 1 :
|
||||
return val1;
|
||||
break;
|
||||
case 2 :
|
||||
return val2;
|
||||
break;
|
||||
case 3 :
|
||||
return val3;
|
||||
break;
|
||||
case 4 :
|
||||
return val4;
|
||||
break;
|
||||
case 5 :
|
||||
return val5;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
36
arduino-cli/libraries/AppEsp32BtRec/AppEsp32BtRec.h
Normal file
36
arduino-cli/libraries/AppEsp32BtRec/AppEsp32BtRec.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef AppBtRec_H
|
||||
#define AppBtRec_H
|
||||
#include <Arduino.h>
|
||||
|
||||
#if defined(ESP32)
|
||||
#include "BluetoothSerial.h"
|
||||
#elif defined(ESP8266)
|
||||
// ESP8266代码
|
||||
#endif
|
||||
|
||||
class AppBtRec {
|
||||
#if defined(ESP32)
|
||||
BluetoothSerial *SerialBT;
|
||||
#elif defined(ESP8266)
|
||||
Stream* SerialBT;
|
||||
#endif
|
||||
public:
|
||||
#if defined(ESP32)
|
||||
AppBtRec(BluetoothSerial& _SerialBT ,bool _monitorPRINT);
|
||||
#elif defined(ESP8266)
|
||||
AppBtRec(Stream& _SerialBT ,bool _monitorPRINT);
|
||||
#endif
|
||||
void PortReceive();
|
||||
bool IsObject(String obj);
|
||||
int GetVal(uint8_t num);
|
||||
private:
|
||||
int val1 = 0, val2 = 0, val3 = 0, val4 = 0, val5 = 0;
|
||||
String Last_Data,REceiveChar;
|
||||
bool IsStarts, IsVal, Mark,monitorPRINT;
|
||||
uint8_t ValNum;
|
||||
|
||||
};
|
||||
#ifdef APPBtREC_PRINT_
|
||||
#define APPBtREC_PRINT
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user