-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutPin.h
More file actions
143 lines (115 loc) · 2.75 KB
/
OutPin.h
File metadata and controls
143 lines (115 loc) · 2.75 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* InPin.h
*/
#ifndef OutPin_h
#define OutPin_h
#include <Arduino.h>
#include <vector>
#include <Runnable.h>
inline void digitalWriteF( uint8_t ulPin, uint8_t ulVal ) {
/*
//Specifico per Nordic nrf5x: //0.021us
///if (ulPin >= PINS_COUNT) { return; }
ulPin = g_ADigitalPinMap[ulPin];
NRF_GPIO_Type * port = nrf_gpio_pin_port_decode(&ulPin);
switch ( ulVal ) {
case LOW: port->OUTCLR = (1UL << ulPin);
break;
default: port->OUTSET = (1UL << ulPin);
break;
}
*/
digitalWrite( ulPin, ulVal );
}
enum OutType {
Out_ActiveHigh = 0x00,
Out_ActiveLow = 0x01,
};
class OutPin : public Runnable {
private:
char simbolStr[2];
const char* name;
const byte pin;
const bool activeLow;
bool oldState;
bool actualState; //Stato Logico
bool changed;
ulong t_Change;
public:
static std::vector<OutPin*> OutPins;
/*
OutPin(const char* aName, byte aPin, boolean activeLow) :
name(aName),
pin(aPin),
activeLow(activeLow)
{
OutPins.push_back( this );
}
*/
OutPin(const char aSimbol, const char* aName, byte aPin, boolean aActiveLow) :
simbolStr("o"),
name(aName),
pin(aPin),
activeLow(aActiveLow)
{
simbolStr[0] = aSimbol;
OutPins.push_back( this );
}
char* getSimbolStr() { return( simbolStr ); }
char getSimbol() { return( simbolStr[0] ); }
bool isActive() { return( actualState ); }
bool isChanged() {
changed = (oldState != actualState);
oldState = actualState;
return (changed);
}
ulong getChangeT() {
return( t_Change );
}
void set( bool state ) {
if( state != oldState ) { t_Change = millis(); }
actualState = state;
digitalWriteF(pin, actualState ^activeLow);
}
/*
void invert->Toggle() {
actualState = !actualState;
digitalWriteF(pin, actualState);
}
*/
void activate() { set( true ); }
void deactivate() { set( false ); }
/*
void activate() {
if( activeLow ) {
actualState = LOW;
} else {
actualState = HIGH;
}
digitalWriteF(pin, actualState);
}
void deactivate() {
if( activeLow ) {
actualState = HIGH;
} else {
actualState = LOW;
}
digitalWriteF(pin, actualState);
}
*/
void setup() {
pinMode(pin, OUTPUT);
/*
if( activeLow ) {
actualState = HIGH;
} else {
actualState = LOW;
}
digitalWriteF(pin, actualState);
*/
set( false ); //Logicamente Disattivo al Setup
}
void loop() {
} //EndOf loop
};
#endif