Skip to content

Commit 323f82c

Browse files
committed
fix delay/SerialBLE/MQTT bug
1 parent 8f87405 commit 323f82c

File tree

3 files changed

+23
-81
lines changed

3 files changed

+23
-81
lines changed

src/Adapters/BlinkerMQTT.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void BlinkerMQTT::connectServer() {
204204
}
205205
#endif
206206

207-
String url_iot = "/user/device/auth?yK6RNFrGRJl&authkey=" + String(authkey);
207+
String url_iot = "/api/v1/user/device/diy/auth?authkey=" + String(authkey);
208208
#ifdef BLINKER_DEBUG_ALL
209209
BLINKER_LOG2("requesting URL: ", url_iot);
210210
#endif

src/Adapters/BlinkerSerial.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class BlinkerTransportStream
2525
}
2626

2727
if (stream->available()) {
28-
strcpy(streamData, (stream->readString()).c_str());
28+
strcpy(streamData, (stream->readStringUntil('\n')).c_str());
2929
#ifdef BLINKER_DEBUG_ALL
3030
BLINKER_LOG2(BLINKER_F("handleSerial: "), streamData);
3131
#endif
@@ -138,13 +138,11 @@ class BlinkerSerail
138138
BLINKER_LOG1("SerialBLE Initialled...");
139139
}
140140
#else
141-
else {
142-
Base::begin();
143-
SSerialBLE = new SoftwareSerial(ss_rx_pin, ss_tx_pin);
144-
SSerialBLE->begin(ss_baud);
145-
this->conn.begin(*SSerialBLE, false);
146-
BLINKER_LOG1("SerialBLE Initialled...");
147-
}
141+
Base::begin();
142+
SSerialBLE = new SoftwareSerial(ss_rx_pin, ss_tx_pin);
143+
SSerialBLE->begin(ss_baud);
144+
this->conn.begin(*SSerialBLE, false);
145+
BLINKER_LOG1("SerialBLE Initialled...");
148146
#endif
149147
}
150148
};

src/Blinker/BlinkerApi.h

Lines changed: 16 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
enum b_widgettype_t {
99
W_BUTTON,
1010
W_SLIDER,
11-
W_TOGGLE,
12-
W_RGB
11+
W_TOGGLE
1312
};
1413

1514
enum b_joystickaxis_t {
@@ -37,7 +36,6 @@ enum b_rgb_t {
3736
static class BlinkerButton * _Button[BLINKER_MAX_WIDGET_SIZE];
3837
static class BlinkerSlider * _Slider[BLINKER_MAX_WIDGET_SIZE];
3938
static class BlinkerToggle * _Toggle[BLINKER_MAX_WIDGET_SIZE];
40-
static class BlinkerRGB * _RGB[BLINKER_MAX_WIDGET_SIZE];
4139

4240
class BlinkerButton
4341
{
@@ -93,24 +91,6 @@ class BlinkerToggle
9391
bool toggleState;
9492
};
9593

96-
class BlinkerRGB
97-
{
98-
public :
99-
BlinkerRGB()
100-
: rgbName(NULL)
101-
{}
102-
103-
void name(String name) { rgbName = name; }
104-
String getName() { return rgbName; }
105-
void freshValue(b_rgb_t color,uint8_t value) { rgbValue[color] = value; }
106-
uint8_t getValue(b_rgb_t color) { return rgbValue[color]; }
107-
bool checkName(String name) { return ((rgbName == name) ? true : false); }
108-
109-
private :
110-
String rgbName;
111-
uint8_t rgbValue[3];
112-
};
113-
11494
template <class T>
11595
int8_t checkNum(String name, T * c, uint8_t count)
11696
{
@@ -134,9 +114,9 @@ class BlinkerApi
134114
ahrsValue[Pitch] = 0;
135115
gpsValue[LONG] = "0.000000";
136116
gpsValue[LAT] = "0.000000";
137-
// rgbValue[R] = 0;
138-
// rgbValue[G] = 0;
139-
// rgbValue[B] = 0;
117+
rgbValue[R] = 0;
118+
rgbValue[G] = 0;
119+
rgbValue[B] = 0;
140120
}
141121

142122
void wInit(const String & _name, b_widgettype_t _type) {
@@ -168,15 +148,6 @@ class BlinkerApi
168148
}
169149
}
170150
break;
171-
case W_RGB :
172-
if (checkNum(_name, _RGB, _rgbCount) == BLINKER_OBJECT_NOT_AVAIL) {
173-
if ( _rgbCount < BLINKER_MAX_WIDGET_SIZE ) {
174-
_RGB[_rgbCount] = new BlinkerRGB();
175-
_RGB[_rgbCount]->name(_name);
176-
_rgbCount++;
177-
}
178-
}
179-
break;
180151
default :
181152
break;
182153
}
@@ -196,13 +167,11 @@ class BlinkerApi
196167
for (uint8_t kNum = 0; kNum < _tCount; kNum++) {
197168
toggle(_Toggle[kNum]->getName());
198169
}
199-
for (uint8_t rgbNum = 0; rgbNum < _rgbCount; rgbNum++) {
200-
rgb(_RGB[rgbNum]->getName(), R);
201-
}
202170

203171
joystick(J_Xaxis);
204172
ahrs(Yaw);
205173
gps(LONG, true);
174+
rgb(R);
206175

207176
if (_fresh) {
208177
static_cast<Proto*>(this)->isParsed();
@@ -465,45 +434,19 @@ class BlinkerApi
465434
}
466435
}
467436

468-
uint8_t rgb(const String & _rgbName, b_rgb_t color) {
469-
int8_t num = checkNum(_rgbName, _RGB, _rgbCount);
470-
int16_t value = STRING_find_array_numberic_value(static_cast<Proto*>(this)->dataParse(), _rgbName, color);
471-
472-
if (value != FIND_KEY_VALUE_FAILED) {
473-
uint8_t _rValue = STRING_find_array_numberic_value(static_cast<Proto*>(this)->dataParse(), _rgbName, R);
474-
uint8_t _gValue = STRING_find_array_numberic_value(static_cast<Proto*>(this)->dataParse(), _rgbName, G);
475-
uint8_t _bValue = STRING_find_array_numberic_value(static_cast<Proto*>(this)->dataParse(), _rgbName, B);
437+
uint8_t rgb(b_rgb_t color) {
438+
int16_t colorValue = STRING_find_array_numberic_value(static_cast<Proto*>(this)->dataParse(), BLINKER_CMD_RGB, color);
476439

477-
if( num == BLINKER_OBJECT_NOT_AVAIL ) {
478-
if ( _rgbCount < BLINKER_MAX_WIDGET_SIZE ) {
479-
_RGB[_rgbCount] = new BlinkerRGB();
480-
_RGB[_rgbCount]->name(_rgbName);
481-
_RGB[_rgbCount]->freshValue(R, _rValue);
482-
_RGB[_rgbCount]->freshValue(G, _gValue);
483-
_RGB[_rgbCount]->freshValue(B, _bValue);
484-
_rgbCount++;
485-
}
486-
}
487-
else {
488-
_RGB[num]->freshValue(R, _rValue);
489-
_RGB[num]->freshValue(G, _gValue);
490-
_RGB[num]->freshValue(B, _bValue);
491-
}
440+
if (colorValue != FIND_KEY_VALUE_FAILED) {
441+
rgbValue[R] = STRING_find_array_numberic_value(static_cast<Proto*>(this)->dataParse(), BLINKER_CMD_RGB, R);
442+
rgbValue[G] = STRING_find_array_numberic_value(static_cast<Proto*>(this)->dataParse(), BLINKER_CMD_RGB, G);
443+
rgbValue[B] = STRING_find_array_numberic_value(static_cast<Proto*>(this)->dataParse(), BLINKER_CMD_RGB, B);
492444

493445
_fresh = true;
494-
return value;
446+
return colorValue;
495447
}
496448
else {
497-
if( num == BLINKER_OBJECT_NOT_AVAIL ) {
498-
if ( _rgbCount < BLINKER_MAX_WIDGET_SIZE ) {
499-
_RGB[_rgbCount] = new BlinkerRGB();
500-
_RGB[_rgbCount]->name(_rgbName);
501-
_rgbCount++;
502-
}
503-
return 0;
504-
}
505-
506-
return _RGB[num]->getValue(color);
449+
return rgbValue[color];
507450
}
508451
}
509452

@@ -527,6 +470,8 @@ class BlinkerApi
527470
uint32_t start = micros();
528471
while (ms > 0) {
529472
static_cast<Proto*>(this)->run();
473+
474+
yield();
530475

531476
if ((micros() - start)/1000 >= ms) {
532477
ms = 0;
@@ -538,11 +483,10 @@ class BlinkerApi
538483
uint8_t _bCount = 0;
539484
uint8_t _sCount = 0;
540485
uint8_t _tCount = 0;
541-
uint8_t _rgbCount = 0;
542486
uint8_t joyValue[2];
543487
int16_t ahrsValue[3];
544488
String gpsValue[2];
545-
// uint8_t rgbValue[3];
489+
uint8_t rgbValue[3];
546490
bool _fresh = false;
547491

548492
bool buttonParse(const String & _bName)

0 commit comments

Comments
 (0)