Skip to content

Commit

Permalink
[#143] PinsModule namespaced as pins_module
Browse files Browse the repository at this point in the history
  • Loading branch information
susanw1 committed Nov 21, 2023
1 parent 451c92f commit f04e288
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class ArduinoZscriptBasicSetup {
Zscript::EthernetSystem<ZscriptParams>::setup();
#endif
#ifdef ZSCRIPT_HAVE_PIN_MODULE
Zscript::PinModule<ZscriptParams>::setup();
Zscript::pins_module::PinModule<ZscriptParams>::setup();
#endif
#ifdef ZSCRIPT_HAVE_SERVO_MODULE
Zscript::ZscriptServoModule<ZscriptParams>::setup();
Expand Down Expand Up @@ -173,7 +173,7 @@ class ArduinoZscriptBasicSetup {
notifSrcs[srcCount++] = &Zscript::I2cModule<ZscriptParams>::notifSrc;
#endif
#ifdef ZSCRIPT_PIN_SUPPORT_NOTIFICATIONS
notifSrcs[srcCount++] = &Zscript::PinModule<ZscriptParams>::notificationSource;
notifSrcs[srcCount++] = &Zscript::pins_module::PinModule<ZscriptParams>::notificationSource;
#endif
#if defined(ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS) || defined(ZSCRIPT_PIN_SUPPORT_NOTIFICATIONS)
Zscript::Zscript<ZscriptParams>::zscript.setNotificationSources(notifSrcs, srcCount);
Expand All @@ -196,7 +196,7 @@ class ArduinoZscriptBasicSetup {
Zscript::ZscriptServoModule<ZscriptParams>::moveAlongServos();
#endif
#ifdef ZSCRIPT_HAVE_PIN_MODULE
Zscript::PinModule<ZscriptParams>::poll();
Zscript::pins_module::PinModule<ZscriptParams>::poll();
#endif
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define SRC_MAIN_C___ARDUINO_PINS_MODULE_PINMANAGER_HPP_

#include <zscript/modules/ZscriptCommand.hpp>
#include <net/zscript/model/modules/base/PinsModule.hpp>

#ifndef digitalPinHasPWM
#ifdef ARDUINO_ARCH_NRF52840 // NANO 33 BLE apparently...
Expand Down Expand Up @@ -193,6 +194,8 @@

namespace Zscript {

namespace pins_module {

enum class PinNotificationType : uint8_t {
NONE,
ON_HIGH,
Expand Down Expand Up @@ -1408,6 +1411,9 @@ void (*PinManager<ZP>::onNotificationAnalog)(void);

#endif
#endif

}

}

#endif /* SRC_MAIN_C___ARDUINO_PINS_MODULE_PINMANAGER_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,40 @@
#include "commands/PinCapabilitiesCommand.hpp"

#define MODULE_EXISTS_004 EXISTENCE_MARKER_UTIL
#define MODULE_SWITCH_004 MODULE_SWITCH_UTIL(PinModule<ZP>::execute)
#define MODULE_SWITCH_004 MODULE_SWITCH_UTIL(pins_module::PinModule<ZP>::execute)

#ifdef ZSCRIPT_PIN_SUPPORT_NOTIFICATIONS
#define MODULE_NOTIFICATION_EXISTS_004 EXISTENCE_MARKER_UTIL
#define MODULE_NOTIFICATION_SWITCH_004 NOTIFICATION_SWITCH_UTIL(PinModule<ZP>::notification)
#define MODULE_NOTIFICATION_SWITCH_004 NOTIFICATION_SWITCH_UTIL(pins_module::PinModule<ZP>::notification)
#endif

namespace Zscript {

namespace pins_module {

template<class ZP>
class PinModule {
#ifdef ZSCRIPT_PIN_SUPPORT_NOTIFICATIONS
public:
static GenericCore::ZscriptNotificationSource<ZP> notificationSource;
public:
static GenericCore::ZscriptNotificationSource<ZP> notificationSource;

private:
static volatile bool hasDigitalNotificationWaiting;
private:
static volatile bool hasDigitalNotificationWaiting;

static void onNotificationNeededDigital() {
if (!notificationSource.setNotification(&GenericCore::LockSet<ZP>::Empty, 0x40)) {
hasDigitalNotificationWaiting = true;
static void onNotificationNeededDigital() {
if (!notificationSource.setNotification(&GenericCore::LockSet<ZP>::Empty, 0x40)) {
hasDigitalNotificationWaiting = true;
}
}
}

#ifdef ZSCRIPT_PIN_SUPPORT_ANALOG_NOTIFICATIONS
static volatile bool hasAnalogNotificationWaiting;
static volatile bool hasAnalogNotificationWaiting;

static void onNotificationNeededAnalog() {
if (!notificationSource.setNotification(&GenericCore::LockSet<ZP>::Empty, 0x41)) {
hasAnalogNotificationWaiting = true;
static void onNotificationNeededAnalog() {
if (!notificationSource.setNotification(&GenericCore::LockSet<ZP>::Empty, 0x41)) {
hasAnalogNotificationWaiting = true;
}
}
}

#endif

Expand Down Expand Up @@ -191,6 +193,9 @@ volatile bool PinModule<ZP>::hasAnalogNotificationWaiting = false;

#endif
#endif

}

}

#endif /* SRC_MAIN_CPP_ARDUINO_PINS_MODULE_ZSCRIPTPINMODULE_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
#define COMMAND_EXISTS_0035 EXISTENCE_MARKER_UTIL

namespace Zscript {
template<class ZP>
class AtoDPinReadCommand {
static constexpr char ParamPin__P = 'P';

static constexpr char RespValue__V = 'V';
namespace pins_module {

template<class ZP>
class AtoDPinReadCommand: public AnalogRead_CommandDefs {
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 @@ -39,8 +38,10 @@ class AtoDPinReadCommand {
out.writeField(RespValue__V, digitalRead(pin) == HIGH ? 0xffff : 0);
}
}

};

}

}

#endif /* SRC_MAIN_C___ARDUINO_PINS_MODULE_COMMANDS_ATODREADCOMMAND_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#define COMMAND_EXISTS_0034 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class AtoDPinSetupCommand {
static constexpr char ParamPin__P = 'P';
Expand Down Expand Up @@ -65,8 +68,10 @@ class AtoDPinSetupCommand {
out.writeField(RespBitCount__B, 1);
}
}

};

}

}

#endif /* SRC_MAIN_C___ARDUINO_PINS_MODULE_COMMANDS_ATODSETUPCOMMAND_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#define COMMAND_EXISTS_0033 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class DigitalPinReadCommand {
static constexpr char ParamPin__P = 'P';
Expand All @@ -35,8 +38,10 @@ class DigitalPinReadCommand {
CommandOutStream<ZP> out = ctx.getOutStream();
out.writeField(RespValue__V, digitalRead(pin) == HIGH ? 1 : 0);
}

};

}

}

#endif /* SRC_MAIN_C___ARDUINO_PINS_MODULE_COMMANDS_DIGITALPINREADCOMMAND_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#define COMMAND_EXISTS_0031 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class DigitalPinSetupCommand {
static constexpr char ParamPin__P = 'P';
Expand Down Expand Up @@ -59,7 +62,6 @@ class DigitalPinSetupCommand {
static constexpr uint16_t RespSupportedNotifications__OnChange = 0x10;

public:

static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t pin;
if (!ctx.getField(ParamPin__P, &pin)) {
Expand Down Expand Up @@ -113,7 +115,6 @@ class DigitalPinSetupCommand {
#ifdef ZSCRIPT_PIN_SUPPORT_NOTIFICATIONS
uint16_t notifMode;
if (ctx.getField(ParamNotificationSelect__N, &notifMode)) {

if (!PinManager<ZP>::supportsInterruptNotifications(pin)) {
if (notifMode != ParamNotificationSelect__None && notifMode != ParamNotificationSelect__OnHigh &&
notifMode != ParamNotificationSelect__OnLow) {
Expand Down Expand Up @@ -164,8 +165,10 @@ class DigitalPinSetupCommand {
}
#endif
}

};

}

}

#endif /* SRC_MAIN_C___ARDUINO_PINS_MODULE_COMMANDS_DIGITALPINSETUPCOMMAND_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#define COMMAND_EXISTS_0032 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class DigitalPinWriteCommand {
static constexpr char ParamPin__P = 'P';
Expand Down Expand Up @@ -50,8 +53,10 @@ class DigitalPinWriteCommand {
}
}
}

};

}

}

#endif /* SRC_MAIN_C___ARDUINO_PINS_MODULE_COMMANDS_DIGITALPINWRITECOMMAND_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#define COMMAND_EXISTS_0036 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class DtoAPinSetupCommand {
static constexpr char ParamPin__P = 'P';
Expand All @@ -39,8 +42,10 @@ class DtoAPinSetupCommand {
out.writeField(RespBitCount__B, 1);
}
}

};

}

}

#endif /* SRC_MAIN_C___ARDUINO_PINS_MODULE_COMMANDS_DTOASETUPCOMMAND_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#define COMMAND_EXISTS_0037 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class DtoAPinWriteCommand {
static constexpr char ParamPin__P = 'P';
Expand Down Expand Up @@ -47,8 +50,10 @@ class DtoAPinWriteCommand {
}
}
}

};

}

}

#endif /* SRC_MAIN_C___ARDUINO_PINS_MODULE_COMMANDS_DTOAWRITECOMMAND_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#define COMMAND_EXISTS_0030 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class PinCapabilitiesCommand {
static constexpr char RespCommandsSet__C = 'C';
Expand All @@ -28,18 +31,20 @@ class PinCapabilitiesCommand {

static void execute(ZscriptCommandContext<ZP> ctx) {
CommandOutStream<ZP> out = ctx.getOutStream();
out.writeField(RespCommandsSet__C, MODULE_CAPABILITIES(003));
out.writeField(RespCommandsSet__C, MODULE_CAPABILITIES(004));
out.writeField(RespPinCount__P, ZP::pinCount);
out.writeField(RespAvailableControllersBitset__B, RespAvailableControllersBitset__Digital | RespAvailableControllersBitset__AtoD |

#ifdef DEVICE_SUPPORTS_ANALOG_WRITE
RespAvailableControllersBitset__DtoA |
#endif
#ifdef DEVICE_SUPPORTS_ANALOG_WRITE
RespAvailableControllersBitset__DtoA |
#endif

RespAvailableControllersBitset__PWM);
RespAvailableControllersBitset__PWM);
}

};

}

}

#endif /* SRC_MAIN_C___ARDUINO_PINS_MODULE_COMMANDS_PINCAPABILITIESCOMMAND_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
#define COMMAND_EXISTS_0038 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

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

static constexpr char RespBitCount__B = 'B';

public:

static void execute(ZscriptCommandContext<ZP> ctx) {
Expand All @@ -39,8 +41,10 @@ class PwmPinSetupCommand {
out.writeField(RespBitCount__B, 1);
}
}

};

}

}

#endif /* SRC_MAIN_C___ARDUINO_PINS_MODULE_COMMANDS_PWMPINSETUPCOMMAND_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#define COMMAND_EXISTS_0039 EXISTENCE_MARKER_UTIL

namespace Zscript {

namespace pins_module {

template<class ZP>
class PwmPinWriteCommand {
static constexpr char ParamPin__P = 'P';
Expand Down Expand Up @@ -47,8 +50,10 @@ class PwmPinWriteCommand {
}
}
}

};

}

}

#endif /* SRC_MAIN_C___ARDUINO_PINS_MODULE_COMMANDS_PWMPINWRITECOMMAND_HPP_ */
Loading

0 comments on commit f04e288

Please sign in to comment.