Skip to content

Commit 533a936

Browse files
committed
Merge branch 'release/version-1.7.0'
2 parents 57335d2 + 59df262 commit 533a936

3 files changed

Lines changed: 34 additions & 11 deletions

File tree

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=GoGoBoard Arduino Library
2-
version=1.6.2
2+
version=1.7.0
33
author=P.Pongpakatien, T.Phoeyphon
44
maintainer=LILCMU <peeranut32@gmail.com>
55
sentence=A library for built-in STM32 arduino core on GoGoBoard to enabled fully functional of hardware along with the used of students.

src/GoGoBoardArduino.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ uint8_t GoGoBoardArduino::gblExtSerialCmdCounter = 0;
2626
bool GoGoBoardArduino::gblUseFirstExtCmdBuffer = false;
2727
bool GoGoBoardArduino::gblNewExtCmdReady = false;
2828
bool GoGoBoardArduino::gblRequestResponseAvailable = false;
29+
bool GoGoBoardArduino::gblResponseArduinoInit = false;
2930
uint8_t GoGoBoardArduino::gbl1stExtCMDBuffer[GOGO_DEFAULT_BUFFER_SIZE] = {0};
3031
uint8_t GoGoBoardArduino::gbl2ndExtCMDBuffer[GOGO_DEFAULT_BUFFER_SIZE] = {0};
3132
uint8_t *GoGoBoardArduino::gblActiveBuffer = NULL;
@@ -107,8 +108,20 @@ void GoGoBoardArduino::processPacket()
107108

108109
switch (gblExtSerialPacketType)
109110
{
110-
case ARDUINO_REQUEST_PACKET_TYPE:
111-
gblRequestResponseAvailable = true;
111+
case ARDUINO_REQUEST_PACKET_TYPE: //? response request packet type from gogoboard
112+
switch ((gblActiveBuffer[0]))
113+
{
114+
case REQ_READ_INPUT:
115+
gblRequestResponseAvailable = true;
116+
break;
117+
118+
case CMD_ARDUINO_INIT:
119+
gblResponseArduinoInit = true;
120+
break;
121+
122+
default:
123+
break;
124+
}
112125
break;
113126

114127
case ARDUINO_GMESSAGE_PACKET_TYPE:
@@ -183,8 +196,8 @@ void GoGoBoardArduino::begin(void)
183196
gogoTimer->resume();
184197
#endif
185198

186-
delay(3000); //? waiting for gogo to boot up
187-
sendCmdPacket((uint8_t)CMD_PACKET, (uint8_t)CMD_ARDUINO_INIT);
199+
delay(2000); //? waiting for gogo to boot up
200+
sendCmdPacket((uint8_t)CMD_PACKET, (uint8_t)CMD_ARDUINO_INIT, 0, 0, false);
188201
}
189202

190203
int GoGoBoardArduino::readInput(uint8_t port)
@@ -199,7 +212,7 @@ int GoGoBoardArduino::readInput(uint8_t port)
199212
{
200213
gblRequestResponseAvailable = false;
201214

202-
return (int)gblActiveBuffer[0] << 8 | gblActiveBuffer[1];
215+
return (int)gblActiveBuffer[1] << 8 | gblActiveBuffer[2];
203216
}
204217
else
205218
{
@@ -393,7 +406,8 @@ void GoGoBoardArduino::setBroadcastPassword(const String &password)
393406

394407
void GoGoBoardArduino::sendBroadcast(const String &topic)
395408
{
396-
sendIoTPacket(CATEGORY_IOT_BROADCAST, IOT_BROADCAST_SEND, (uint8_t *)topic.c_str(), topic.length());
409+
if (gblResponseArduinoInit)
410+
sendIoTPacket(CATEGORY_IOT_BROADCAST, IOT_BROADCAST_SEND, (uint8_t *)topic.c_str(), topic.length());
397411
}
398412

399413
bool GoGoBoardArduino::receiveBroadcast(const String &topic)
@@ -408,7 +422,8 @@ bool GoGoBoardArduino::receiveBroadcast(const String &topic)
408422
}
409423
else //? may not subscribe broadcast topic yet
410424
{
411-
sendIoTPacket(CATEGORY_IOT_BROADCAST, IOT_BROADCAST_RECEIVE, (uint8_t *)topic.c_str(), topic.length());
425+
if (gblResponseArduinoInit)
426+
sendIoTPacket(CATEGORY_IOT_BROADCAST, IOT_BROADCAST_RECEIVE, (uint8_t *)topic.c_str(), topic.length());
412427
}
413428
return false;
414429
}
@@ -417,14 +432,16 @@ void GoGoBoardArduino::sendCloudMessage(const String &topic, const float payload
417432
{
418433
_dataStr = topic + "," + String(payload);
419434

420-
sendIoTPacket(CATEGORY_IOT_CLOUD_MESSAGE, IOT_CLOUD_MESSAGE_PUBLISH, (uint8_t *)_dataStr.c_str(), _dataStr.length());
435+
if (gblResponseArduinoInit)
436+
sendIoTPacket(CATEGORY_IOT_CLOUD_MESSAGE, IOT_CLOUD_MESSAGE_PUBLISH, (uint8_t *)_dataStr.c_str(), _dataStr.length());
421437
}
422438

423439
void GoGoBoardArduino::sendCloudMessage(const String &topic, const String &payload)
424440
{
425441
_dataStr = topic + "," + payload;
426442

427-
sendIoTPacket(CATEGORY_IOT_CLOUD_MESSAGE, IOT_CLOUD_MESSAGE_PUBLISH, (uint8_t *)_dataStr.c_str(), _dataStr.length());
443+
if (gblResponseArduinoInit)
444+
sendIoTPacket(CATEGORY_IOT_CLOUD_MESSAGE, IOT_CLOUD_MESSAGE_PUBLISH, (uint8_t *)_dataStr.c_str(), _dataStr.length());
428445
}
429446

430447
bool GoGoBoardArduino::isCloudMessageAvailable(const String &topic)
@@ -436,7 +453,8 @@ bool GoGoBoardArduino::isCloudMessageAvailable(const String &topic)
436453
}
437454
else //? may not subscribe cloudmessage topic yet
438455
{
439-
sendIoTPacket(CATEGORY_IOT_CLOUD_MESSAGE, IOT_CLOUD_MESSAGE_SUBSCRIBE, (uint8_t *)topic.c_str(), topic.length());
456+
if (gblResponseArduinoInit)
457+
sendIoTPacket(CATEGORY_IOT_CLOUD_MESSAGE, IOT_CLOUD_MESSAGE_SUBSCRIBE, (uint8_t *)topic.c_str(), topic.length());
440458
}
441459
return false;
442460
}

src/GoGoBoardArduino.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
#define GOGO_GPIO_SCL PB6
3838
#define GOGO_GPIO_SDA PB7
3939

40+
#define ARDUINO_INIT_DEFAULT 0
41+
#define ARDUINO_INIT_IOT 1
42+
4043
#define ARDUINO_CMD_PACKET_TYPE 30
4144
#define ARDUINO_GMESSAGE_PACKET_TYPE 31
4245
#define ARDUINO_REQUEST_PACKET_TYPE 32
@@ -221,6 +224,7 @@ class GoGoBoardArduino
221224
static void gogoSerialEvent(void);
222225
static void processPacket(void);
223226

227+
224228
static uint8_t gblExtSerialState;
225229
static uint8_t gblExtSerialPacketType;
226230
static uint8_t gblExtSerialCmdChecksum;
@@ -229,6 +233,7 @@ class GoGoBoardArduino
229233
static bool gblUseFirstExtCmdBuffer;
230234
static bool gblNewExtCmdReady;
231235
static bool gblRequestResponseAvailable;
236+
static bool gblResponseArduinoInit;
232237
static uint8_t gbl1stExtCMDBuffer[];
233238
static uint8_t gbl2ndExtCMDBuffer[];
234239
static uint8_t *gblActiveBuffer;

0 commit comments

Comments
 (0)