-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoftatadevice_relay.cpp
107 lines (88 loc) · 2.07 KB
/
softatadevice_relay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <Arduino.h>
#include "SoftataDevice_actuator.h"
SoftataDevice_Relay::SoftataDevice_Relay()
{
}
SoftataDevice_Relay::SoftataDevice_Relay(int pin)
{
byte _relayPin = pin;
Setup(&_relayPin,1);
}
bool SoftataDevice_Relay::Setup()
{
byte _relayPin = 16;
Setup(&_relayPin,1);
return true;
}
bool SoftataDevice_Relay::Setup(byte * settings, byte numSettings)
{
if(numSettings>0)
{
relayPin = settings[0];
}
else
{
Serial.print("Setting up Relay FAILED: No settings (pin no.)");
return false;
}
Serial.print("Setting up relay on pin: ");
Serial.println(relayPin);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, false);
return true;
}
int SoftataDevice_Relay::GetNumBits()
{
Serial.println("SoftataDevice_Relay::GetNumBits()");
return num_bits;
}
int SoftataDevice_Relay::GetInstanceValueRange()
{
return RELAY_MAX;
}
byte SoftataDevice_Relay::GetActuatorCapabilities()
{
return (byte)(a_none);
}
/*String SoftataDevice_Relay::GetPins()
{
String msg = "Relay Pins";
msg.concat(RELAY_PINOUT);
return msg;
}*/
// Index for if there are an array of actuators here.
// Instance of is collected elsewhere.
// No longer need. 2Do Remove
Tristate SoftataDevice_Relay::Write(double value, int index)
{
return notImplemented;
}
Tristate SoftataDevice_Relay::Write(int value, int index, int numBytes )
{
return notImplemented;
}
Tristate SoftataDevice_Relay::SetBitState(bool state,int bitNo)
{
Serial.println("Setting relay state");
digitalWrite(relayPin, state);
return (Tristate)true;
}
Tristate SoftataDevice_Relay::SetBit(int bitNo )
{
Serial.println("Setting relay");
digitalWrite(relayPin, true);
return (Tristate)true;
}
Tristate SoftataDevice_Relay::ClearBit(int bitNo)
{
Serial.println("Clearing relay");
digitalWrite(relayPin, false);
return (Tristate)true;
}
Tristate SoftataDevice_Relay::ToggleBit(int bitNo)
{
Serial.println("Toggling relay");
bool state = digitalRead(relayPin);
digitalWrite(relayPin, !state);
return (Tristate)true;
}