-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlinktPlugin.cpp
102 lines (82 loc) · 2.75 KB
/
BlinktPlugin.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
/*
* Copyright (c) 2016-2017 Scott Mitchell.
* All rights reserved.
*
* Licenced under the BSD 3-Clause licence (the "Licence"); you may not use
* this file except in compliance with the Licence. You may obtain a copy of
* the Licence from the LICENCE file in the top level of this software
* distribution or from:
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
// See BlinktPlugin.h for details of the public API of this plugin.
#include "BlinktPlugin.h"
#include "blinkt_functions.h"
#include <wiringPi.h>
unsigned BlinktPlugin::RefCount = 0;
bool BlinktPlugin::ResetOnUnload = true;
std::mutex BlinktPlugin::Mutex;
BlinktPlugin::BlinktPlugin(): base_plugin_t("BlinktPlugin") {
// Nothing to do here except increment the reference count
std::lock_guard<std::mutex> lock(Mutex);
RefCount++;
}
BlinktPlugin::~BlinktPlugin() {
// Maybe reset Blinkt! if the reference count reaches zero
std::lock_guard<std::mutex> lock(Mutex);
if (RefCount > 0 && --RefCount == 0 && ResetOnUnload) {
blinkt_reset();
blinkt_refresh();
}
}
// Plugin functions available through EPL
// Mostly these just map through to wiringPi or blinkt_functions
void BlinktPlugin::setLED(int64_t num, int64_t red, int64_t green, int64_t blue, double intensity) {
std::lock_guard<std::mutex> lock(Mutex);
blinkt_set_led(num, red, green, blue, intensity);
}
void BlinktPlugin::setAll(int64_t red, int64_t green, int64_t blue, double intensity) {
std::lock_guard<std::mutex> lock(Mutex);
blinkt_set_all(red, green, blue, intensity);
}
void BlinktPlugin::setIntensity(int64_t num, double intensity) {
std::lock_guard<std::mutex> lock(Mutex);
blinkt_set_intensity(num, intensity);
}
void BlinktPlugin::setIntensityAll(double intensity) {
std::lock_guard<std::mutex> lock(Mutex);
blinkt_set_intensity(intensity);
}
void BlinktPlugin::refresh() {
std::lock_guard<std::mutex> lock(Mutex);
blinkt_refresh();
}
void BlinktPlugin::reset() {
std::lock_guard<std::mutex> lock(Mutex);
blinkt_reset();
}
void BlinktPlugin::delay(int64_t millis) {
::delay((unsigned)millis);
}
bool BlinktPlugin::enableDebug(bool enable) {
std::lock_guard<std::mutex> lock(Mutex);
return blinkt_enable_debug(enable);
}
bool BlinktPlugin::enableResetOnUnload(bool enable) {
std::lock_guard<std::mutex> lock(Mutex);
bool rval = ResetOnUnload;
ResetOnUnload = enable;
return rval;
}
int64_t BlinktPlugin::getDAT() {
return BLINKT_DAT;
}
int64_t BlinktPlugin::getCLK() {
return BLINKT_CLK;
}