Skip to content

Commit 75a5ff2

Browse files
Rocketctfacchinm
authored andcommitted
added new relay management for new release
1 parent bcbd106 commit 75a5ff2

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/Arduino_MKRIoTCarrier_Relay.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,34 @@
1919

2020

2121
#include "Arduino_MKRIoTCarrier_Relay.h"
22+
#include "MKRIoTCarrierDefines.h"
2223

23-
MKRIoTCarrier_Relay::MKRIoTCarrier_Relay(int pin):_pin{pin}
24+
MKRIoTCarrier_Relay::MKRIoTCarrier_Relay(int index, getRev_t getRev):_index{index}
2425
{
26+
board_revision = getRev;
2527
}
2628
void MKRIoTCarrier_Relay::begin(){
29+
30+
_revision = board_revision();
31+
32+
if(_revision == BOARD_REVISION_1)
33+
{
34+
if(_index == 1) {
35+
_pin = mkr_iot_carrier_rev1::RELAY1;
36+
}
37+
else if(_index == 2) {
38+
_pin = mkr_iot_carrier_rev1::RELAY2;
39+
}
40+
}
41+
else {
42+
/*carrier's revision 2 with pull down on AREF */
43+
if(_index == 1) {
44+
_pin = mkr_iot_carrier_rev2::RELAY1;
45+
}
46+
else if(_index == 2) {
47+
_pin = mkr_iot_carrier_rev2::RELAY2;
48+
}
49+
}
2750
pinMode(_pin ,OUTPUT);
2851
close();
2952
}
@@ -44,7 +67,6 @@ void MKRIoTCarrier_Relay::open(){
4467
}
4568

4669
int MKRIoTCarrier_Relay::getStatus(){
47-
//Serial.println("status");
48-
//Serial.println(_status , BIN);
70+
4971
return (int)_status;
5072
}

src/Arduino_MKRIoTCarrier_Relay.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,23 @@
2222
#define ARDUINO_MKRIoTCarrier_Relay
2323

2424
#include "Arduino.h"
25+
using getRev_t = int (*)();
2526

2627
class MKRIoTCarrier_Relay{
2728
public:
28-
MKRIoTCarrier_Relay(int pin);
29+
MKRIoTCarrier_Relay(int index, getRev_t getRev);
2930
void begin();
3031
void open();
3132
void close();
3233
int getPin();
3334
int getStatus();
3435

3536
private:
36-
const int _pin;
37+
int _pin;
3738
int _status;
39+
int _index;
40+
int (*board_revision)(void);
41+
int _revision;
3842
};
3943

4044
#endif

0 commit comments

Comments
 (0)