From 94e76df2768c2115339e8472ceec55cc877a23c9 Mon Sep 17 00:00:00 2001 From: WillB97 Date: Tue, 6 Aug 2024 07:37:39 +0100 Subject: [PATCH 1/3] Check pin mode is set correctly for analog read and digital write --- src/src.ino | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/src.ino b/src/src.ino index 55c4216..27befc5 100644 --- a/src/src.ino +++ b/src/src.ino @@ -125,6 +125,17 @@ void processCommand() { } else if (current_arg.equals("SET")) { getSlice(); + // Check if the pin is in the correct mode + int mode = getPinMode(pin); + if (mode != OUTPUT) { + if (mode == INPUT) { + Serial.print("NACK:Digital write is not supported in INPUT\n"); + } else { + Serial.print("NACK:Digital write is not supported in INPUT_PULLUP\n"); + } + Serial.print("\n"); + return; + } if (current_arg.equals("1")) { // CMD: PIN::DIGITAL:SET:1 digitalWrite(pin, HIGH); @@ -144,6 +155,17 @@ void processCommand() { getSlice(); if (current_arg.equals("GET?")) { // CMD: PIN::ANALOG:GET? + // Check if the pin is in the correct mode + int mode = getPinMode(pin); + if (mode != INPUT) { + if (mode == OUTPUT) { + Serial.print("NACK:Analog read is not supported in OUTPUT\n"); + } else { + Serial.print("NACK:Analog read is not supported in INPUT_PULLUP\n"); + } + Serial.print("\n"); + return; + } Serial.print(analogRead(pin)); Serial.print("\n"); return; From ba9f43d0bbcd2f31069d15f839539a51cc8ee197 Mon Sep 17 00:00:00 2001 From: WillB97 Date: Tue, 6 Aug 2024 08:29:47 +0100 Subject: [PATCH 2/3] Remove extra newline --- src/src.ino | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/src.ino b/src/src.ino index 27befc5..cfd19fd 100644 --- a/src/src.ino +++ b/src/src.ino @@ -133,7 +133,6 @@ void processCommand() { } else { Serial.print("NACK:Digital write is not supported in INPUT_PULLUP\n"); } - Serial.print("\n"); return; } if (current_arg.equals("1")) { @@ -163,7 +162,6 @@ void processCommand() { } else { Serial.print("NACK:Analog read is not supported in INPUT_PULLUP\n"); } - Serial.print("\n"); return; } Serial.print(analogRead(pin)); From 6c9d73aee4a990a291273018fd2edb5600e1af3a Mon Sep 17 00:00:00 2001 From: WillB97 Date: Tue, 6 Aug 2024 08:35:51 +0100 Subject: [PATCH 3/3] Bump version number --- src/src.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/src.ino b/src/src.ino index cfd19fd..cb8d898 100644 --- a/src/src.ino +++ b/src/src.ino @@ -48,7 +48,7 @@ void processCommand() { if (current_arg.equals("*IDN?")) { // CMD: *IDN? - Serial.print("SourceBots:Arduino:X:2.0\n"); + Serial.print("SourceBots:Arduino:X:2.1\n"); return; }