Skip to content

Commit 2044971

Browse files
committed
fix gpio event, drop unnecessary overloads, formatting
1 parent 73b6392 commit 2044971

File tree

5 files changed

+37
-67
lines changed

5 files changed

+37
-67
lines changed

src/Wippersnapper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ void Wippersnapper::provision() {
100100

101101
// Board specific initializations
102102
#ifdef ARDUINO_ARDUINO_NESSO_N1
103-
battery.begin();
104-
delay(10);
105-
battery.enableCharge();
103+
battery.begin();
104+
delay(10);
105+
battery.enableCharge();
106106
#endif
107107

108108
// Initialize the status LED for signaling FS errors
@@ -1667,7 +1667,7 @@ void cbDisplayMessage(char *data, uint16_t len) {
16671667
/****************************************************************************/
16681668
bool Wippersnapper::encodePinEvent(
16691669
wippersnapper_signal_v1_CreateSignalRequest *outgoingSignalMsg,
1670-
uint8_t pinName, int pinVal) {
1670+
uint16_t pinName, int pinVal) {
16711671
bool is_success = true;
16721672
outgoingSignalMsg->which_payload =
16731673
wippersnapper_signal_v1_CreateSignalRequest_pin_event_tag;

src/Wippersnapper.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,10 @@ static NessoBattery battery; ///< Nesso-N1 Battery instance
254254
class WsExpanderPin : public ExpanderPin, public Printable {
255255
public:
256256
WsExpanderPin(uint16_t _pin) : ExpanderPin(_pin) {}
257-
WsExpanderPin(ExpanderPin ep) : ExpanderPin(ep.pin | (ep.address == 0x44 ? 0x100 : 0x200)) {}
258-
259-
size_t printTo(Print& p) const override {
257+
WsExpanderPin(ExpanderPin ep)
258+
: ExpanderPin(ep.pin | (ep.address == 0x44 ? 0x100 : 0x200)) {}
259+
260+
size_t printTo(Print &p) const override {
260261
size_t n = p.print("0x");
261262
n += p.print(address, HEX);
262263
n += p.print("_");
@@ -343,7 +344,7 @@ class Wippersnapper {
343344
// Encodes a pin event message
344345
bool
345346
encodePinEvent(wippersnapper_signal_v1_CreateSignalRequest *outgoingSignalMsg,
346-
uint8_t pinName, int pinVal);
347+
uint16_t pinName, int pinVal);
347348

348349
// Pin configure message
349350
bool configureDigitalPinReq(wippersnapper_pin_v1_ConfigurePinRequest *pinMsg);

src/Wippersnapper_Boards.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
#define BOARD_ID "arduino-nesso-n1"
171171
#define USE_LITTLEFS
172172
#define USE_STATUS_LED
173-
#define STATUS_LED_PIN LED_BUILTIN // can now be +512/+256 for expander (0x43/44)
173+
#define STATUS_LED_PIN LED_BUILTIN // can be +512/+256 as expander (0x43/44)
174174
#define STATUS_LED_INVERTED
175175
#elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32C6)
176176
#define BOARD_ID "feather-esp32c6"

src/components/digitalIO/Wippersnapper_DigitalGPIO.cpp

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void Wippersnapper_DigitalGPIO::initDigitalPin(
6666
WsExpanderPin flexPinName = (ExpanderPin)pinName;
6767
#else
6868
uint8_t flexPinName = (uint8_t)pinName;
69-
#endif
69+
#endif
7070
if (direction ==
7171
wippersnapper_pin_v1_ConfigurePinRequest_Direction_DIRECTION_OUTPUT) {
7272

@@ -96,20 +96,20 @@ void Wippersnapper_DigitalGPIO::initDigitalPin(
9696
digitalWrite(pinName, LOW);
9797
}
9898
#else
99-
pinMode(pinName, OUTPUT);
100-
digitalWrite(pinName, LOW); // initialize LOW
99+
pinMode(flexPinName, OUTPUT);
100+
digitalWrite(flexPinName, LOW); // initialize LOW
101101
#endif
102102
} else if (
103103
direction ==
104104
wippersnapper_pin_v1_ConfigurePinRequest_Direction_DIRECTION_INPUT) {
105105
WS_DEBUG_PRINT("Configuring digital input pin on D");
106-
WS_DEBUG_PRINT(pinName);
106+
WS_DEBUG_PRINT(flexPinName);
107107

108108
if (pull == wippersnapper_pin_v1_ConfigurePinRequest_Pull_PULL_UP) {
109109
WS_DEBUG_PRINTLN("with internal pull-up enabled");
110-
pinMode(pinName, INPUT_PULLUP);
110+
pinMode(flexPinName, INPUT_PULLUP);
111111
} else {
112-
pinMode(pinName, INPUT);
112+
pinMode(flexPinName, INPUT);
113113
WS_DEBUG_PRINT("\n");
114114
}
115115

@@ -187,24 +187,17 @@ void Wippersnapper_DigitalGPIO::deinitDigitalPin(
187187
*/
188188
/********************************************************************/
189189
int Wippersnapper_DigitalGPIO::digitalReadSvc(int pinName) {
190-
// Service using arduino `digitalRead`
191-
int pinVal = digitalRead(pinName);
192-
return pinVal;
193-
}
194-
195190
#if defined(ARDUINO_ARDUINO_NESSO_N1)
196-
/********************************************************************/
197-
/*!
198-
@brief High-level digitalRead service impl. which performs a
199-
digitalRead.
200-
@param pin
201-
The ExpanderPin instance
202-
@returns The pin's value.
203-
*/
204-
/********************************************************************/
205-
int Wippersnapper_DigitalGPIO::digitalReadSvc(ExpanderPin pin) {
191+
// probably this should be >255 instead for future use.
192+
if ((pinName & 0x100) || (pinName & 0x200)) {
193+
WsExpanderPin flexPinName = (ExpanderPin)pinName;
194+
// Service using expander `digitalRead`
195+
int pinVal = digitalRead(flexPinName);
196+
return pinVal;
197+
}
198+
#endif
206199
// Service using arduino `digitalRead`
207-
int pinVal = digitalRead(pin);
200+
int pinVal = digitalRead(pinName);
208201
return pinVal;
209202
}
210203

@@ -217,25 +210,8 @@ int Wippersnapper_DigitalGPIO::digitalReadSvc(ExpanderPin pin) {
217210
The pin's value.
218211
*/
219212
/*******************************************************************************/
220-
void Wippersnapper_DigitalGPIO::digitalWriteSvc(ExpanderPin pin, int pinValue) {
221-
WS_DEBUG_PRINT("Digital Pin Event: Set ");
222-
WS_DEBUG_PRINT(pin.pin);
223-
WS_DEBUG_PRINT(" to ");
224-
WS_DEBUG_PRINTLN(pinValue);
225-
digitalWrite(pin, pinValue);
226-
}
227-
#endif
228-
229-
/*******************************************************************************/
230-
/*!
231-
@brief Writes a value to a pin.
232-
@param pinName
233-
The pin's name.
234-
@param pinValue
235-
The pin's value.
236-
*/
237-
/*******************************************************************************/
238-
void Wippersnapper_DigitalGPIO::digitalWriteSvc(uint16_t pinName, int pinValue) {
213+
void Wippersnapper_DigitalGPIO::digitalWriteSvc(uint16_t pinName,
214+
int pinValue) {
239215
WS_DEBUG_PRINT("Digital Pin Event: Set ");
240216
WS_DEBUG_PRINT(pinName);
241217
WS_DEBUG_PRINT(" to ");
@@ -249,6 +225,13 @@ void Wippersnapper_DigitalGPIO::digitalWriteSvc(uint16_t pinName, int pinValue)
249225
digitalWrite(pinName, !pinValue);
250226
else
251227
digitalWrite(pinName, pinValue);
228+
#elif defined(ARDUINO_ARDUINO_NESSO_N1)
229+
if ((pinName & 0x100) || (pinName & 0x200)) {
230+
WsExpanderPin flexPinName = (ExpanderPin)pinName;
231+
digitalWrite(flexPinName, pinValue);
232+
} else {
233+
digitalWrite(pinName, pinValue);
234+
}
252235
#else
253236
digitalWrite(pinName, pinValue);
254237
#endif

src/components/digitalIO/Wippersnapper_DigitalGPIO.h

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
/** Holds data about a digital input pin */
2222
struct digitalInputPin {
2323
uint16_t pinName; ///< Pin name
24-
long period; ///< Timer interval, in millis, -1 if disabled.
25-
long prvPeriod; ///< When timer was previously serviced, in millis
26-
int prvPinVal; ///< Previous pin value
24+
long period; ///< Timer interval, in millis, -1 if disabled.
25+
long prvPeriod; ///< When timer was previously serviced, in millis
26+
int prvPinVal; ///< Previous pin value
2727
};
2828

2929
// forward decl.
@@ -49,20 +49,6 @@ class Wippersnapper_DigitalGPIO {
4949
uint16_t pinName);
5050
int digitalReadSvc(int pinName);
5151
void digitalWriteSvc(uint16_t pinName, int pinValue);
52-
#if defined(ARDUINO_ARDUINO_NESSO_N1)
53-
// void
54-
// initDigitalPin(wippersnapper_pin_v1_ConfigurePinRequest_Direction
55-
// direction,
56-
// ExpanderPin pinName, float period,
57-
// wippersnapper_pin_v1_ConfigurePinRequest_Pull pull);
58-
// void
59-
// deinitDigitalPin(wippersnapper_pin_v1_ConfigurePinRequest_Direction
60-
// direction,
61-
// ExpanderPin pinName);
62-
63-
int digitalReadSvc(ExpanderPin pinName);
64-
void digitalWriteSvc(ExpanderPin pinName, int pinValue);
65-
#endif
6652
void processDigitalInputs();
6753

6854
digitalInputPin *_digital_input_pins; /*!< Array of gpio pin objects */

0 commit comments

Comments
 (0)