-
Notifications
You must be signed in to change notification settings - Fork 0
/
KintoForIoT_Button.cpp
81 lines (60 loc) · 1.42 KB
/
KintoForIoT_Button.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
// KintoForIoT - Arduino library for prototyping connected devices with Kinto
// Copyright Julien Lebunetel 2018
// MIT License
// include Arduino core library
#include "Arduino.h"
// include this library's description file
#include "KintoForIoT_Button.h"
// Constructor /////////////////////////////////////////////////////////////////
// Function that handles the creation and setup of instances
Button::Button()
:Data()
{
};
// Public Methods //////////////////////////////////////////////////////////////
// Functions available in KintoForIoT sketches, this library, and other libraries
bool Button::read()
{
if (isLocal()) {
write(digitalRead(_pin));
}
return _status;
}
void Button::write(bool status)
{
_previousStatus = _status;
_status = status;
}
void Button::get()
{
Data::get();
char status[10];
Data::read("status", status);
if (strcmp(status, "on") == 0) {
on();
}
else {
off();
}
};
void Button::post()
{
if (isOn()) {
Data::write("status", "on");
}
else {
Data::write("status", "off");
}
Data::post();
};
void Button::begin(int pin, bool defaultStatus)
{
_pin = pin;
_status = defaultStatus;
_previousStatus = defaultStatus;
_defaultStatus = defaultStatus;
pinMode(_pin, INPUT);
Data::setLocal();
};
// Private Methods /////////////////////////////////////////////////////////////
// Functions only available to other functions in this library