Slave device registration

This commit is contained in:
cyp0633 2022-08-26 17:09:22 +08:00
parent d2c5de05c5
commit f8a2ffdb91
Signed by: cyp0633
GPG Key ID: CF90D09FB1FDCE45
2 changed files with 30 additions and 1 deletions

View File

@ -7,6 +7,7 @@
// key selection
#define KEY_TEST_CONNECTION 0x00
#define KEY_REGISTER_SLAVE 0x01
#define KEY1 0x01
#define KEY2 0x02
#define KEY3 0x03
@ -19,6 +20,8 @@
// key action
#define KEY_ACTION_REQUIRE_TEST 0x00
#define KEY_ACTION_CONNECTION_OK 0x01
#define KEY_ACTION_SLAVE_REQUEST 0x00
#define KEY_ACTION_SLAVE_OK 0x01
#define KEY_ACTION_PRESS 0x01
#define KEY_ACTION_RELEASE 0x02

28
main.c
View File

@ -39,6 +39,32 @@ void uart1Process()
void uart2Process()
{
if (buf2[1] == DEVICE_SPECIAL_PROTOCOL)
{
switch (buf2[2])
{
case KEY_REGISTER_SLAVE: // register slave
if (buf2[3] != KEY_ACTION_SLAVE_REQUEST || buf2[4] > 0x08 || buf2[4] < 0x02)
{
return;
}
buf3[0] = PROTOCOL_HEADER;
buf3[1] = DEVICE_SPECIAL_PROTOCOL;
buf3[2] = KEY_REGISTER_SLAVE;
buf3[3] = KEY_ACTION_SLAVE_OK;
buf3[4] = buf2[4];
buf3[5] = 0x00;
buf3[6] = 0x00;
buf3[7] = 0x00;
onlineStatus = onlineStatus & (1 << buf2[4]);
Uart2Print(buf3, 8);
break;
}
}
else // slave device key action; pass it along to uart1
{
Uart1Print(buf3, 8);
}
return;
}
@ -182,7 +208,7 @@ keySend:
void onlineProcess()
{
LedPrint(onlineStatus);
LedPrint(onlineStatus & 0x0f);
return;
}