-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRpiPower.h
69 lines (51 loc) · 1.87 KB
/
RpiPower.h
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
/*
RpiPower.h - Library defining a Raspberry Pi power connection
Created by Scott Webster Wood, August 7, 2016
Released into the public domain.
*/
#ifndef RpiPower_h
#define RpiPower_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#define SEG_DIP_ON 0b01100011
#define SEG_DIP_OFF 0b01011100
class RpiPower {
public:
RpiPower();
RpiPower(uint8_t pin, uint8_t id1, uint8_t id2, const char * id, const char *name);
void setPin(uint8_t p) { _pin = p; };
uint8_t getPin() { return _pin; };
void setId(const char *i) { strncpy(_id, i, 2); _id[2] = 0; };
void copyId(char *i) { strncpy(i, (char*)_id, 2); i[2] = 0; };
void setIdc1(uint8_t d) { _idc2 = d; };
uint8_t getIdc1() { return _idc1; };
void setIdc2(uint8_t d) { _idc2 = d; };
uint8_t getIdc2() { return _idc2; };
void setName(const char *n) { strncpy(_name, n, 8); _name[8] = 0; };
void copyName(char *n) { strncpy(n, _name, 8); n[8] = 0; };
String getInfoJSON();
String getStatus();
uint8_t getStatusDigit();
void initRelay(uint8_t rPin, bool rState);
void turnRelayOn();
void turnRelayOff();
void toggleRelay();
bool getRelayState() { return _relayState; };
bool relayIsOn() { return (_relayState == true); };
bool relayIsOff() { return (_relayState == false); };
void setDefined() { _def = true; };
void setUndefined() { _def = false; };
bool isDefined() { return _def; };
private:
bool _def = false;
uint8_t _pin; // relay pin
uint8_t _idc1; // first character id to display
uint8_t _idc2; // second character id to display
char _id[3] = {0};
char _name[9] = {0}; // user friendly name
bool _relayState;
};
#endif