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