Skip to content

Commit

Permalink
[#143] PinsModule commands extend defs and use new constants
Browse files Browse the repository at this point in the history
  • Loading branch information
susanw1 committed Nov 21, 2023
1 parent 4aa35d2 commit 45b1b95
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ commands:
description: whether the device supports AtoDs on the pins
- name: DtoA
description: whether the device supports DtoAs on the pins
- name: PWM
- name: pwm
description: whether the device supports PWM on the pins
- name: digitalNotification
description: whether the device supports notifications for digital pin control
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ template<class ZP>
class PinManager {

#ifdef ZSCRIPT_PIN_SUPPORT_NOTIFICATIONS

static void pinInterrupt_00() {
pinInterrupt(0);
}
Expand Down Expand Up @@ -1156,7 +1155,6 @@ class PinManager {
public:
AnalogPinNotificationSetup(uint8_t pin) : notifState(false), notif(false), enabled(false), pinNum(pin), maxVal(0xfff),
minVal(0x000), last(0x800) {

}
};

Expand Down Expand Up @@ -1209,10 +1207,7 @@ class PinManager {
#endif

public:

#ifdef ZSCRIPT_PIN_SUPPORT_NOTIFICATIONS


static void setOnNotificationDigital(void (*onNotificationDigital)(void)) {
PinManager<ZP>::onNotificationDigital = onNotificationDigital;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <zscript/modules/ZscriptCommand.hpp>
#include "../PinManager.hpp"

#define COMMAND_EXISTS_0035 EXISTENCE_MARKER_UTIL
#define COMMAND_EXISTS_0045 EXISTENCE_MARKER_UTIL

namespace Zscript {

Expand All @@ -20,7 +20,6 @@ namespace pins_module {
template<class ZP>
class AtoDPinReadCommand: public AnalogRead_CommandDefs {
public:

static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ReqPin__P, &pin)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,18 @@
#include <zscript/modules/ZscriptCommand.hpp>
#include "../PinManager.hpp"

#define COMMAND_EXISTS_0034 EXISTENCE_MARKER_UTIL
#define COMMAND_EXISTS_0044 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class AtoDPinSetupCommand: public AToDSetup_CommandDefs {
static constexpr char ParamPin__P = 'P';
static constexpr char ParamEnableNotifications__N = 'N';
static constexpr char ParamLowerLimit__L = 'L';
static constexpr char ParamUpperLimit__U = 'U';

static constexpr char RespBitCount__B = 'B';
static constexpr char RespSupportsNotifications__N = 'N';

public:

static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ParamPin__P, &pin)) {
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
Expand All @@ -42,25 +33,25 @@ class AtoDPinSetupCommand: public AToDSetup_CommandDefs {
#ifdef ZSCRIPT_PIN_SUPPORT_ANALOG_NOTIFICATIONS
uint8_t index = PinManager<ZP>::getAnalogIndex(pin);
uint16_t enableNotifications;
if (ctx.getField(ParamEnableNotifications__N, &enableNotifications)) {
if (ctx.getField(ReqEnableNotifications__N, &enableNotifications)) {
if (enableNotifications != 0) {
PinManager<ZP>::enableAnalogNotification(index);
} else {
PinManager<ZP>::disableAnalogNotification(index);
}
}
uint16_t notificationLower;
if (ctx.getField(ParamLowerLimit__L, &notificationLower)) {
if (ctx.getField(ReqLowerLimitNotify__L, &notificationLower)) {
PinManager<ZP>::setAnalogNotificationLower(index, notificationLower);
}
uint16_t notificationUpper;
if (ctx.getField(ParamUpperLimit__U, &notificationUpper)) {
if (ctx.getField(ReqUpperLimitNotify__U, &notificationUpper)) {
PinManager<ZP>::setAnalogNotificationUpper(index, notificationUpper);
}
#endif
CommandOutStream<ZP> out = ctx.getOutStream();
#ifdef ZSCRIPT_PIN_SUPPORT_ANALOG_NOTIFICATIONS
out.writeField(RespSupportsNotifications__N, 0);
out.writeField(RespSupportedNotifications__N, 0);
#endif
if (PIN_SUPPORTS_ANALOG_READ(pin)) {
out.writeField(RespBitCount__B, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,18 @@
#include <zscript/modules/ZscriptCommand.hpp>
#include "../PinManager.hpp"

#define COMMAND_EXISTS_0033 EXISTENCE_MARKER_UTIL
#define COMMAND_EXISTS_0043 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class DigitalPinReadCommand: public DigitalRead_CommandDefs {
static constexpr char ParamPin__P = 'P';

static constexpr char RespValue__V = 'V';

public:

static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ParamPin__P, &pin)) {
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
Expand All @@ -36,7 +31,7 @@ class DigitalPinReadCommand: public DigitalRead_CommandDefs {
return;
}
CommandOutStream<ZP> out = ctx.getOutStream();
out.writeField(RespValue__V, digitalRead(pin) == HIGH ? 1 : 0);
out.writeField(RespValue__V, digitalRead(pin) == HIGH ? high_value : low_value);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <zscript/modules/ZscriptCommand.hpp>
#include "../PinManager.hpp"

#define COMMAND_EXISTS_0031 EXISTENCE_MARKER_UTIL
#define COMMAND_EXISTS_0041 EXISTENCE_MARKER_UTIL

namespace Zscript {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@
#include <zscript/modules/ZscriptCommand.hpp>
#include "../PinManager.hpp"

#define COMMAND_EXISTS_0032 EXISTENCE_MARKER_UTIL
#define COMMAND_EXISTS_0042 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class DigitalPinWriteCommand: public DigitalWrite_CommandDefs {
static constexpr char ParamPin__P = 'P';
static constexpr char ParamValue__V = 'V';

public:

static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ParamPin__P, &pin)) {
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
Expand All @@ -35,14 +31,14 @@ class DigitalPinWriteCommand: public DigitalWrite_CommandDefs {
return;
}
uint16_t value;
if (!ctx.getField(ParamValue__V, &value)) {
if (!ctx.getField(ReqValue__V, &value)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
if (!PinManager<ZP>::isModeActivated(pin)) {
digitalWrite(pin, value ? HIGH : LOW);
digitalWrite(pin, value != low_Value ? HIGH : LOW);
} else {
if ((value != 0) == PinManager<ZP>::isCollectorNDrain(pin)) {
if ((value != low_Value) == PinManager<ZP>::isCollectorNDrain(pin)) {
pinMode(pin, OUTPUT);
} else {
if (PinManager<ZP>::isPullup(pin)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,18 @@
#include <zscript/modules/ZscriptCommand.hpp>
#include "../PinManager.hpp"

#define COMMAND_EXISTS_0036 EXISTENCE_MARKER_UTIL
#define COMMAND_EXISTS_0046 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class DtoAPinSetupCommand: public DToASetup_CommandDefs {
static constexpr char ParamPin__P = 'P';

static constexpr char RespBitCount__B = 'B';

public:

static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ParamPin__P, &pin)) {
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@
#include <zscript/modules/ZscriptCommand.hpp>
#include "../PinManager.hpp"

#define COMMAND_EXISTS_0037 EXISTENCE_MARKER_UTIL
#define COMMAND_EXISTS_0047 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class DtoAPinWriteCommand: public AnalogWrite_CommandDefs {
static constexpr char ParamPin__P = 'P';
static constexpr char ParamValue__V = 'V';

public:
static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ParamPin__P, &pin)) {
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
Expand All @@ -34,7 +31,7 @@ class DtoAPinWriteCommand: public AnalogWrite_CommandDefs {
return;
}
uint16_t value;
if (!ctx.getField(ParamValue__V, &value)) {
if (!ctx.getField(ReqValue__V, &value)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PinCapabilitiesCommand : public Capabilities_CommandDefs {
#ifdef DEVICE_SUPPORTS_ANALOG_WRITE
| RespAvailableControllers_Values::dtoA_field
#endif
| RespAvailableControllers_Values::pWM_field);
| RespAvailableControllers_Values::pwm_field);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@
#include <zscript/modules/ZscriptCommand.hpp>
#include "../PinManager.hpp"

#define COMMAND_EXISTS_0038 EXISTENCE_MARKER_UTIL
#define COMMAND_EXISTS_0048 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class PwmPinSetupCommand: public PwmSetup_CommandDefs {
static constexpr char ParamPin__P = 'P';

static constexpr char RespBitCount__B = 'B';
public:

static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ParamPin__P, &pin)) {
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@
#include <zscript/modules/ZscriptCommand.hpp>
#include "../PinManager.hpp"

#define COMMAND_EXISTS_0039 EXISTENCE_MARKER_UTIL
#define COMMAND_EXISTS_0049 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class PwmPinWriteCommand: public PwmWrite_CommandDefs {
static constexpr char ParamPin__P = 'P';
static constexpr char ParamValue__V = 'V';

public:

static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ParamPin__P, &pin)) {
if (!ctx.getField(ReqPin__P, &pin)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
Expand All @@ -35,7 +31,7 @@ class PwmPinWriteCommand: public PwmWrite_CommandDefs {
return;
}
uint16_t value;
if (!ctx.getField(ParamValue__V, &value)) {
if (!ctx.getField(ReqValue__V, &value)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
}
Expand Down

0 comments on commit 45b1b95

Please sign in to comment.