Skip to content

Commit

Permalink
[#143] PinsModule commands reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
susanw1 committed Nov 21, 2023
1 parent 45b1b95 commit 0a3f02a
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class AtoDPinReadCommand: public AnalogRead_CommandDefs {
public:
static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
if (pin >= ZP::pinCount) {
ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
if (!ctx.getReqdFieldCheckLimit(ReqPin__P, ZP::pinCount, &pin)) {
return;
}
CommandOutStream<ZP> out = ctx.getOutStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class AtoDPinSetupCommand: public AToDSetup_CommandDefs {
public:
static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
if (pin >= ZP::pinCount) {
ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
if (!ctx.getReqdFieldCheckLimit(ReqPin__P, ZP::pinCount, &pin)) {
return;
}
#ifdef ZSCRIPT_PIN_SUPPORT_ANALOG_NOTIFICATIONS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class DigitalPinReadCommand: public DigitalRead_CommandDefs {
public:
static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
if (pin >= ZP::pinCount) {
ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
if (!ctx.getReqdFieldCheckLimit(ReqPin__P, ZP::pinCount, &pin)) {
return;
}
CommandOutStream<ZP> out = ctx.getOutStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class DigitalPinSetupCommand : public DigitalSetup_CommandDefs {
public:
static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
if (pin >= ZP::pinCount) {
ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
if (!ctx.getReqdFieldCheckLimit(ReqPin__P, ZP::pinCount, &pin)) {
return;
}
uint16_t mode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class DigitalPinWriteCommand: public DigitalWrite_CommandDefs {
public:
static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
if (pin >= ZP::pinCount) {
ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
if (!ctx.getReqdFieldCheckLimit(ReqPin__P, ZP::pinCount, &pin)) {
return;
}
uint16_t value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class DtoAPinSetupCommand: public DToASetup_CommandDefs {
public:
static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
if (pin >= ZP::pinCount) {
ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
if (!ctx.getReqdFieldCheckLimit(ReqPin__P, ZP::pinCount, &pin)) {
return;
}
CommandOutStream<ZP> out = ctx.getOutStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class DtoAPinWriteCommand: public AnalogWrite_CommandDefs {
public:
static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
if (pin >= ZP::pinCount) {
ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
if (!ctx.getReqdFieldCheckLimit(ReqPin__P, ZP::pinCount, &pin)) {
return;
}
uint16_t value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class PwmPinSetupCommand: public PwmSetup_CommandDefs {
public:
static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
if (pin >= ZP::pinCount) {
ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
if (!ctx.getReqdFieldCheckLimit(ReqPin__P, ZP::pinCount, &pin)) {
return;
}
CommandOutStream<ZP> out = ctx.getOutStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class PwmPinWriteCommand: public PwmWrite_CommandDefs {
public:
static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
if (pin >= ZP::pinCount) {
ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
if (!ctx.getReqdFieldCheckLimit(ReqPin__P, ZP::pinCount, &pin)) {
return;
}
uint16_t value;
Expand Down

0 comments on commit 0a3f02a

Please sign in to comment.