-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBarDisplay.cpp
More file actions
67 lines (46 loc) · 1.29 KB
/
BarDisplay.cpp
File metadata and controls
67 lines (46 loc) · 1.29 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
#include "BarDisplay.h"
// Public Functions
// ============================================================================
BarDisplay::BarDisplay(LedDisplay& display):
m_display(display),
m_drawToken(0),
m_color(0x20) //default to the color blue
{
}//end constructor
BarDisplay::~BarDisplay()
{
}//end destructor
bool BarDisplay::activate()
{
m_drawToken = m_display.grabFocus();
return true;
}//end activate
bool BarDisplay::setLength(uint16_t newLength)
{
if(newLength > m_display.numOfPixels())
{
newLength = m_display.numOfPixels();
}
//Draw the new bar on the display of the specified length.
for(uint16_t i = 0; i < newLength; i++)
{
m_display.setPixel(m_drawToken, i, m_color);
}
//Turn off the remaining leds.
for(uint16_t i = newLength; i < m_display.numOfPixels(); i++)
{
m_display.setPixel(m_drawToken, i, 0);
}
//Push the new pixels on to the display.
m_display.refresh(m_drawToken);
return true;
}//end setLength
bool BarDisplay::setColor(uint32_t newColor)
{
m_color = newColor;
return true;
}//end setColor
uint16_t BarDisplay::maxLength()
{
return m_display.numOfPixels();
}//end setColor