Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
strip_impl.hpp
Go to the documentation of this file.
1
5#ifndef PLATFORM_STRIPIMPL_HPP
6#define PLATFORM_STRIPIMPL_HPP
7
10
13
14#include <memory>
15#include <cassert>
16
17namespace lampda {
18namespace platform {
20namespace strip {
21
22template<size_t LedCount, uint8_t ChannelCount> bool LampdaStrip<LedCount, ChannelCount>::begin(void)
23{
24 if (pin < 0)
25 {
26 begun = false;
27 return false;
28 }
29 begun = true;
30 return true;
31}
32
33template<size_t LedCount, uint8_t ChannelCount>
34void LampdaStrip<LedCount, ChannelCount>::setPixelColor(uint16_t n, uint32_t c)
35{
36 if (n < numLEDs)
37 {
38 uint8_t *p, r = (uint8_t)(c >> 16), g = (uint8_t)(c >> 8), b = (uint8_t)c;
39 if (wOffset == rOffset)
40 {
41 p = &pixels[n * 3];
42 }
43 else
44 {
45 p = &pixels[n * 4];
46 uint8_t w = (uint8_t)(c >> 24);
47 p[wOffset] = w;
48 }
49 p[rOffset] = r;
50 p[gOffset] = g;
51 p[bOffset] = b;
52 }
53}
54
55template<size_t LedCount, uint8_t ChannelCount>
56uint32_t LampdaStrip<LedCount, ChannelCount>::getPixelColor(uint16_t n) const
57{
58 if (n >= numLEDs)
59 return 0; // Out of bounds, return no color.
60
61 if (wOffset == rOffset)
62 { // Is RGB-type device
63 uint8_t const* p = &pixels[n * 3];
64 // No b constrightness adjustment has been made -- return 'raw' color
65 return ((uint32_t)p[rOffset] << 16) | ((uint32_t)p[gOffset] << 8) | (uint32_t)p[bOffset];
66 }
67 else
68 { // Is RGBW-type device
69 uint8_t const* p = &pixels[n * 4];
70 return ((uint32_t)p[wOffset] << 24) | ((uint32_t)p[rOffset] << 16) | ((uint32_t)p[gOffset] << 8) |
71 (uint32_t)p[bOffset];
72 }
73}
74
75template<size_t LedCount, uint8_t ChannelCount> bool LampdaStrip<LedCount, ChannelCount>::canShow(void)
76{
77 // It's normal and possible for endTime to exceed micros() if the
78 // 32-bit clock counter has rolled over (about every 70 minutes).
79 // Since both are uint32_t, a negative delta correctly maps back to
80 // positive space, and it would seem like the subtraction below would
81 // suffice. But a problem arises if code invokes show() very
82 // infrequently...the micros() counter may roll over MULTIPLE times in
83 // that interval, the delta calculation is no longer correct and the
84 // next update may stall for a very long time. The check below resets
85 // the latch counter if a rollover has occurred. This can cause an
86 // extra delay of up to 300 microseconds in the rare case where a
87 // show() call happens precisely around the rollover, but that's
88 // neither likely nor especially harmful, vs. other code that might
89 // stall for 30+ minutes, or having to document and frequently remind
90 // and/or provide tech support explaining an unintuitive need for
91 // show() calls at least once an hour.
92 uint32_t now = platform::time_us();
93 if (endTime > now)
94 {
95 endTime = now;
96 }
97 return (now - endTime) >= 300L;
98}
99
100template<size_t LedCount, uint8_t ChannelCount> void LampdaStrip<LedCount, ChannelCount>::updateType(neoPixelType t)
101{
102 wOffset = (t >> 6) & 0b11; // See notes in header file
103 rOffset = (t >> 4) & 0b11; // regarding R/G/B/W offsets
104 gOffset = (t >> 2) & 0b11;
105 bOffset = t & 0b11;
106
107 if (wOffset == rOffset)
108 {
109 assert(ChannelCount == 3);
110 }
111 else
112 {
113 assert(ChannelCount == 4);
114 }
115}
116
117template<size_t LedCount, uint8_t ChannelCount> void LampdaStrip<LedCount, ChannelCount>::setPin(int16_t p) {}
118
119template<size_t LedCount, uint8_t ChannelCount> void LampdaStrip<LedCount, ChannelCount>::show(void)
120{
122}
123
124} // namespace strip
125} // namespace platform
126} // namespace lampda
127
128#endif
void show(void)
Definition: strip_impl.hpp:134
Define commonly used color spaces.
uint64_t time_us(void)
Returns the number of microseconds since the Arduino board began running the current program.
Definition: time.cpp:20
Program scope.
Definition: control_fixed_modes.hpp:12
Implement a led strip object.
uint8_t neoPixelType
3rd arg to Adafruit_NeoPixel constructor
Definition: strip_impl.h:17
Define all time related platform functions.
Define useful functions.