Skip to content

Commit 0f9f831

Browse files
committed
Implement digitalRead API which allows to read the status of a digital input pin from the host processor.
1 parent 6bb97b6 commit 0f9f831

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

main/CommandHandler.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,19 @@ int setAnalogWrite(const uint8_t command[], uint8_t response[])
11801180
return 6;
11811181
}
11821182

1183+
int getDigitalRead(const uint8_t command[], uint8_t response[])
1184+
{
1185+
uint8_t pin = command[4];
1186+
1187+
int const pin_status = digitalRead(pin);
1188+
1189+
response[2] = 1; // number of parameters
1190+
response[3] = 1; // parameter 1 length
1191+
response[4] = (uint8_t)pin_status;
1192+
1193+
return 6;
1194+
}
1195+
11831196
int writeFile(const uint8_t command[], uint8_t response[]) {
11841197
char filename[32 + 1];
11851198
size_t len;
@@ -1566,7 +1579,7 @@ const CommandHandlerType commandHandlers[] = {
15661579
setEnt, NULL, NULL, NULL, sendDataTcp, getDataBufTcp, insertDataBuf, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
15671580

15681581
// 0x50 -> 0x5f
1569-
setPinMode, setDigitalWrite, setAnalogWrite, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1582+
setPinMode, setDigitalWrite, setAnalogWrite, getDigitalRead, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
15701583

15711584
// 0x60 -> 0x6f
15721585
writeFile, readFile, deleteFile, existsFile, downloadFile, applyOTA, renameFile, downloadOTA, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,

0 commit comments

Comments
 (0)