config: first version of storing pixel maps and configs in SPIFFS
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
80
src/Config.h
80
src/Config.h
@@ -1,78 +1,12 @@
|
||||
#pragma once
|
||||
#include <Figments.h>
|
||||
|
||||
struct MaskCoordinateMapping : CoordinateMapping {
|
||||
struct Span {
|
||||
int length = 0;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
Span(int length, int x, int y) : length(length), x(x), y(y) {}
|
||||
};
|
||||
|
||||
Span displayMap[13] = {
|
||||
{6, 0, 6},
|
||||
{6, 1, 6},
|
||||
{7, 2, 6},
|
||||
{9, 3, 4},
|
||||
{14, 4, 4},
|
||||
{17, 5, 0},
|
||||
{12, 6, 2},
|
||||
{18, 7, 0},
|
||||
{14, 8, 4},
|
||||
{9, 9, 5},
|
||||
{7, 10, 4},
|
||||
{6, 11, 5},
|
||||
{6, 12, 5}
|
||||
};
|
||||
|
||||
VirtualCoordinates physicalToVirtualCoords(const PhysicalCoordinates localCoords) const override {
|
||||
int offset = localCoords.x;
|
||||
for(int i = 0; i < 12; i++) {
|
||||
if (offset > displayMap[i].length) {
|
||||
offset -= displayMap[i].length;
|
||||
} else {
|
||||
return VirtualCoordinates{i, offset};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PhysicalCoordinates virtualToPhysicalCoords(const VirtualCoordinates virtualCoords) const override {
|
||||
const uint8_t spanIdx = scale8(12, virtualCoords.x);
|
||||
const uint8_t spanOffset = scale8(17, virtualCoords.y);
|
||||
return PhysicalCoordinates{spanIdx, spanOffset};
|
||||
}
|
||||
|
||||
int physicalCoordsToIndex(const PhysicalCoordinates localCoords) const override {
|
||||
uint8_t idx = 0;
|
||||
bool inverse = false;
|
||||
for(int i = 0; i < localCoords.x; i++) {
|
||||
idx += displayMap[i].length;
|
||||
inverse = !inverse;
|
||||
}
|
||||
if (inverse) {
|
||||
idx += std::max(0, displayMap[localCoords.x].length - 1 - std::max(0, (int)localCoords.y - displayMap[localCoords.x].y));
|
||||
} else {
|
||||
idx += std::min((int)displayMap[localCoords.x].length - 1, std::max(0, (int)localCoords.y - displayMap[localCoords.x].y));
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
unsigned int physicalPixelCount() const override {
|
||||
int total = 0;
|
||||
for(int i = 0; i < 13; i++) {
|
||||
total += displayMap[i].length;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
};
|
||||
#include "JsonCoordinateMapping.h"
|
||||
|
||||
struct HardwareConfig {
|
||||
uint8_t version = 3;
|
||||
uint8_t checksum = 0;
|
||||
struct Data {
|
||||
uint16_t pixelCount = 255;
|
||||
uint16_t startPixel = 0;
|
||||
char loadedProfile[16] = {0};
|
||||
uint8_t lastRed = 255;
|
||||
uint8_t lastGreen = 255;
|
||||
uint8_t lastBlue = 255;
|
||||
@@ -84,7 +18,6 @@ struct HardwareConfig {
|
||||
void save();
|
||||
bool isValid() const;
|
||||
|
||||
LinearCoordinateMapping toCoordMap() const;
|
||||
static constexpr uint16_t MAX_LED_NUM = 255;
|
||||
|
||||
private:
|
||||
@@ -101,10 +34,13 @@ struct ConfigService: public Task {
|
||||
void onStart();
|
||||
void loop() override;
|
||||
void handleEvent(const InputEvent &evt) override;
|
||||
const CoordinateMapping* coordMap() const { return /*&m_maskMap;*/ &m_coordMap; }
|
||||
const CoordinateMapping* coordMap() const { return &m_jsonMap; }
|
||||
const char* loadedProfile() const;
|
||||
|
||||
private:
|
||||
HardwareConfig m_config;
|
||||
MaskCoordinateMapping m_maskMap;
|
||||
LinearCoordinateMapping m_coordMap;
|
||||
JsonCoordinateMapping m_jsonMap;
|
||||
|
||||
void loadProfile(const char* name);
|
||||
void loadMap(const String& mapName);
|
||||
};
|
||||
|
Reference in New Issue
Block a user