Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
coordinates.hpp
Go to the documentation of this file.
1
5#ifndef MODES_HARDWARE_COORDINATES_HPP
6#define MODES_HARDWARE_COORDINATES_HPP
7
8#include <array>
9
10namespace lampda::modes::hardware::details {
11
12// For each Y coord, return the apparent "LED shift required" to align to grid
13template<size_t maxOverflowHeight, typename _OutTy = std::array<uint16_t, maxOverflowHeight + 1>>
14static constexpr _OutTy computeResidues(float realExactWidth)
15{
16 uint16_t floorWidth = floor(realExactWidth);
17
18 _OutTy results {};
19 for (size_t Y = 0; Y < results.size(); ++Y)
20 {
21 results[Y] = ((float)Y) * realExactWidth - ((float)Y * floorWidth);
22 }
23
24 return results;
25}
26
27// For each Y coord, return True iff given row is 1 LED longer than the others
28template<size_t maxOverflowHeight, typename _OutTy = std::array<bool, maxOverflowHeight + 1>>
29static constexpr _OutTy computeDeltaResidues(float realExactWidth)
30{
31 auto allResiduesY = computeResidues<maxOverflowHeight>(realExactWidth);
32
33 _OutTy results {};
34 for (size_t Y = 0; Y < results.size(); ++Y)
35 {
36 if (Y + 1 < allResiduesY.size())
37 results[Y] = (bool)(allResiduesY[Y] != allResiduesY[Y + 1]);
38 else
39 results[Y] = false;
40 }
41
42 return results;
43}
44
45template<size_t maxOverflowHeight, typename _OutTy = std::array<int, maxOverflowHeight + 1>>
46static constexpr _OutTy computeExtraShiftResidues(float realExactWidth)
47{
48 auto allDeltaResiduesY = computeDeltaResidues<maxOverflowHeight>(realExactWidth);
49
50 int total = 0;
51 _OutTy results {};
52 for (size_t Y = 0; Y < results.size(); ++Y)
53 {
54 results[Y] = total;
55 if (Y + 1 >= allDeltaResiduesY.size())
56 continue;
57 if (allDeltaResiduesY[Y] && allDeltaResiduesY[Y + 1])
58 total += 1;
59 if (!allDeltaResiduesY[Y] && !allDeltaResiduesY[Y + 1])
60 total -= 1;
61 }
62
63 return results;
64}
65
66} // namespace lampda::modes::hardware::details
67
68#endif