Expand digital/PWM support, add validation and robust SCPI parsing, update README - #2
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: da3bd3c8c0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if(isValidDigitalChannel(parsed)) | ||
| { | ||
| channel = parsed; | ||
| return true; |
There was a problem hiding this comment.
Prefer physical pin matches before treating
<ch> as index
resolveDigitalChannel accepts any token in 0..9 as a SCPI index before it ever checks digitalPins, so the new pin-number addressing described in README.md:155-157 is wrong for overlapping values. On Uno, DIG:OUT 2,1 drives digitalPins[2] (D4) instead of physical D2, and DIG:OUT 9,1 hits digitalPins[9] (D13) instead of D9. As written, physical D2-D9 can never be addressed even though this commit advertises that they can.
Useful? React with 👍 / 👎.
| pwmValue[ch] = val; | ||
| analogWrite(pwmPins[ch], val); | ||
| Serial.println("OK"); |
There was a problem hiding this comment.
Synchronize
DIG:OUT? state when PWM drives D9/D10
Now that D9/D10 are exposed through the digital channel map, SOUR:PWM also needs to keep digitalState consistent. This block only updates pwmValue and the hardware pin, so after SOUR:PWM 0,255 a subsequent DIG:OUT? 7 still returns the stale boolean from the last DIG:OUT call (typically 0 after reset) even though D9 is being held HIGH. The shared digital/PWM behavior documented in README.md:157-163 therefore does not round-trip for the PWM pins.
Useful? React with 👍 / 👎.
Motivation
LED_BUILTIN) and make PWM/servo handling more robust and safe.Description
digitalPinsto includeD2..D10andLED_BUILTINand computedigitalPinCountandpwmPinCountdynamically.isValidAnalogChannel,isValidDigitalChannel,isValidPwmChannel,findPwmChannelByPin,parseChannel,resolveDigitalChannel) to validate and parse channel arguments.processCommandby validating inputs, returningERRon invalid parameters, and supporting pin-number addressing forDIG:OUTqueries and commands.pwmValueandservoAttached, detaching servos before setting PWM, and attaching servos only whenSOUR:SERVOis used.resetDeviceto correctly reset/detach servos, clear PWM and digital states, and use the new counts; bumped identification string version to1.2.READ?,ROUT:SCAN?,MEAS:VOLT?,MEAS:RAW?and related parsing to use the new validation and parsing helpers.README.mdto document the expanded digital pin mapping, new examples showingDIG:OUTwith pin numbers, and clarify PWM pins behavior.Testing
avr:unoto verify it compiles successfully.Codex Task