8000 Add function and example to learn unknow ID · cezer-io/cezerio-blocks-arduino@2511335 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2511335

Browse files
committed
Add function and example to learn unknow ID
Add function and example to learn unknow ID
1 parent 206d0f7 commit 2511335

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "cezerioBlocks.h"
2+
3+
unsigned char timerFlag = 0;
4+
5+
void setup()
6+
{
7+
initCezerioBlocks();
8+
}
9+
10+
void loop()
11+
{
12+
#if defined(CAN_RECEIVE_INTERRUPT_ENABLE)
13+
if(!digitalRead(CAN_INT))
14+
{
15+
}
16+
#endif
17+
18+
if(timerFlag)
19+
{
20+
Serial.println(getBlockID(),HEX);
21+
timerFlag = 0;
22+
}
23+
}
24+
25+
#if defined(TIMER_INTERRUPT_ENABLE)
26+
ISR(TIMER1_COMPA_vect)
27+
{
28+
timerFlag = 1;
29+
}
30+
#endif

libraries/CezerioBlocks/src/cezerioBlocks.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,22 @@ void setBirrr(unsigned int birrrBlockID, unsigned char motorDirection, unsigned
793793
CAN.sendMsgBuf(birrrBlockID, 0, 7, sendData);
794794
}
795795

796+
void createBlockDataRequestPacket(unsigned int requestMessageId)
797+
{
798+
unsigned char sendData[4] = {SYNC_BYTE_START, 0x04, 0x00, SYNC_BYTE_STOP};
799+
CAN.sendMsgBuf(requestMessageId, 0, 4, sendData);
800+
}
801+
802+
uint16_t getBlockID()
803+
{
804+
createBlockDataRequestPacket(MESSAGE_ID_REQUEST);
805+
806+
CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
807+
unsigned char messageIDH = rxBuf[3];
808+
unsigned char messageIDL = rxBuf[4];
809+
810+
return (messageIDH << 8 | messageIDL);
811+
}
796812
/*********************************************************************************************************
797813
* END FILE
798814
*********************************************************************************************************/

libraries/CezerioBlocks/src/cezerioBlocks.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ unsigned char hexToAscii(unsigned char hexData);
9595
/* INIT FUNCTIONS */
9696
void initCezerioBlocks(void);
9797
void initSmartBlue(void);
98+
void createBlockDataRequestPacket(unsigned int requestMessageId);
99+
uint16_t getBlockID();
98100

99101
/* BLE FUNCTIONS */
100102
void getSmartBlueData(void);

0 commit comments

Comments
 (0)
0