-
Notifications
You must be signed in to change notification settings - Fork 17
/
StringBlade.cpp
151 lines (124 loc) · 2.65 KB
/
StringBlade.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
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
143
144
145
146
147
148
149
150
151
/*
This file is part of the Universal Saber library.
The Universal Saber library is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
The Universal Saber library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Universal Saber library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* StringBlade.cpp
*
* Created on: Mar 7, 2016
* Author: JakeSoft <http://forum.arduino.cc/index.php?topic=261980.0>
*/
#include "blade/StringBlade.h"
#include <Arduino.h>
StringBlade::StringBlade(int aSeg1, int aSeg2, int aSeg3,
int aSeg4, int aSeg5, int aSeg6)
{
mChannelPins[0] = aSeg1;
mChannelPins[1] = aSeg2;
mChannelPins[2] = aSeg3;
mChannelPins[3] = aSeg4;
mChannelPins[4] = aSeg5;
mChannelPins[5] = aSeg6;
for(int lIdx = 0; lIdx < 6; lIdx++)
{
mPowerLevels[lIdx] = 0;
}
mIsOn = false;
}
StringBlade::~StringBlade()
{
Off();
}
void StringBlade::Init()
{
for(int lIdx = 0; lIdx < 6; lIdx++)
{
pinMode(mChannelPins[lIdx], OUTPUT);
}
PerformIO();
}
void StringBlade::SetChannel(unsigned char aPower, int aChannel)
{
if(aChannel < 6)
{
mPowerLevels[aChannel] = aPower;
}
}
void StringBlade::On()
{
for(int lIdx = 0; lIdx < 6; lIdx++)
{
mPowerLevels[lIdx] = 255;
}
PerformIO();
mIsOn = true;
}
void StringBlade::Off()
{
for(int lIdx = 0; lIdx < 6; lIdx++)
{
mPowerLevels[lIdx] = 0;
}
PerformIO();
mIsOn = false;
}
bool StringBlade::PowerUp(int aRampTime)
{
int lDelay = aRampTime/6;
for(int lPin = 0; lPin <= 6; lPin++)
{
analogWrite(mChannelPins[lPin], 255);
if(lPin < 6)
{
analogWrite(mChannelPins[lPin+1], 128);
}
delay(lDelay);
}
On();
return true;
}
bool StringBlade::PowerDown(int aRampTime)
{
int lDelay = aRampTime/6;
for(int lPin = 6; lPin >= 0; lPin--)
{
analogWrite(mChannelPins[lPin], 0);
if(lPin > 0)
{
analogWrite(mChannelPins[lPin-1], 128);
}
delay(lDelay);
}
Off();
return true;
}
void StringBlade::ApplyFlicker(int aType)
{
//Do nothing
}
void StringBlade::PerformIO()
{
for(int lIdx = 0; lIdx < 6; lIdx++)
{
if(mChannelPins[lIdx] > 0)
{
analogWrite(mChannelPins[lIdx], mPowerLevels[lIdx]);
}
}
}
BladeMetadata StringBlade::GetFeatures()
{
BladeMetadata lData;
lData.Channels = 6;
lData.Flickers = 0;
return lData;
}