File tree Expand file tree Collapse file tree 2 files changed +21
-10
lines changed Expand file tree Collapse file tree 2 files changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ class BlinkerProtocol
24
24
, state(CONNECTING)
25
25
, isFresh(false )
26
26
, isAvail(false )
27
+ , availState(false )
27
28
, canParse(false )
28
29
{}
29
30
@@ -49,7 +50,11 @@ class BlinkerProtocol
49
50
50
51
void run ();
51
52
52
- bool available () { return isFresh; }
53
+ bool available () {
54
+ bool _avail = availState;
55
+ availState = false ;
56
+ return _avail;
57
+ }
53
58
54
59
String readString ()
55
60
{
@@ -103,6 +108,7 @@ class BlinkerProtocol
103
108
104
109
void flush () {
105
110
isFresh = false ;
111
+ availState = false ;
106
112
}
107
113
108
114
private :
@@ -112,6 +118,7 @@ class BlinkerProtocol
112
118
if (isAvail) {
113
119
isFresh = true ;
114
120
canParse = true ;
121
+ availState = true ;
115
122
}
116
123
return isAvail;
117
124
}
@@ -126,7 +133,7 @@ class BlinkerProtocol
126
133
}
127
134
}
128
135
129
- void isParsed () { isFresh = false ; canParse = false ; }// BLINKER_LOG1("isParsed");
136
+ void isParsed () { isFresh = false ; canParse = false ; availState = false ; }// BLINKER_LOG1("isParsed");
130
137
131
138
bool parseState () { return canParse; }
132
139
@@ -135,6 +142,7 @@ class BlinkerProtocol
135
142
BlinkerState state;
136
143
bool isFresh;
137
144
bool isAvail;
145
+ bool availState;
138
146
bool canParse;
139
147
140
148
void begin ()
Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ class BlinkerTransportESP32_BLE
110
110
char BLEBuf[BLINKER_BUFFER_SIZE];
111
111
bool isAvail;
112
112
bool isFresh;
113
+ uint32_t _bufLen;
113
114
uint32_t freshTime;
114
115
BLEServer *pServer;
115
116
BLEService *pService;
@@ -133,27 +134,29 @@ class BlinkerTransportESP32_BLE
133
134
134
135
void onWrite (BLECharacteristic *pCharacteristic) {
135
136
std::string value = pCharacteristic->getValue ();
137
+ int vlen = value.length ();
136
138
137
- if (value. length () > 0 ) {
139
+ if (vlen > 0 ) {
138
140
freshTime = millis ();
139
141
140
- if (!isFresh) {
141
- strcpy (BLEBuf, value.c_str ());
142
- isFresh = true ;
143
- }
144
- else {
145
- strcat (BLEBuf, value.c_str ());
142
+ for (uint8_t _num = 0 ; _num < vlen; _num++) {
143
+ BLEBuf[_bufLen] = value[_num];
144
+ _bufLen++;
146
145
}
147
146
148
- if (String (value.c_str ()).endsWith (" \n " )) {
147
+ isFresh = true ;
148
+
149
+ if (value[vlen-1 ] == ' \n ' ) {
149
150
isAvail = true ;
151
+ _bufLen = 0 ;
150
152
}
151
153
}
152
154
}
153
155
154
156
void checkTimeOut () {
155
157
if (isFresh && !isAvail && (millis () - freshTime) > BLINKER_STREAM_TIMEOUT) {
156
158
isAvail = true ;
159
+ _bufLen = 0 ;
157
160
}
158
161
}
159
162
};
You can’t perform that action at this time.
0 commit comments