Skip to content

Commit 9bbfaaa

Browse files
committed
refactor: fix some ui bugs and remove not needed cache
1 parent d5ce869 commit 9bbfaaa

File tree

8 files changed

+842
-875
lines changed

8 files changed

+842
-875
lines changed

frontend/src/app.tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export const App: Component = () => {
2424
| "led"
2525
| "persist-plugin"
2626
| "artnet"
27-
| "brightness",
27+
| "brightness"
28+
| "goldelay",
2829
data?: Record<string, string | number> | { data: number[] },
2930
) =>
3031
actions.send(
@@ -119,23 +120,18 @@ export const App: Component = () => {
119120
</Show>
120121
}
121122
>
122-
<div
123-
style={{
124-
opacity: (store.brightness || 255) / 255,
123+
<LedMatrix
124+
disabled={store.plugin !== 1}
125+
data={store.leds || []}
126+
indexData={rotatedMatrix()}
127+
brightness={store.brightness ?? 255}
128+
onSetLed={(data) => {
129+
wsMessage("led", data);
125130
}}
126-
>
127-
<LedMatrix
128-
disabled={store.plugin !== 1}
129-
data={store.leds || []}
130-
indexData={rotatedMatrix()}
131-
onSetLed={(data) => {
132-
wsMessage("led", data);
133-
}}
134-
onSetMatrix={(data) => {
135-
actions?.setLeds([...data]);
136-
}}
137-
/>
138-
</div>
131+
onSetMatrix={(data) => {
132+
actions?.setLeds([...data]);
133+
}}
134+
/>
139135
</Show>
140136
</div>
141137
);

frontend/src/components/layout/sidebar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ export const Sidebar: Component<SidebarProps> = (props) => {
102102
value={store?.brightness}
103103
class="w-full"
104104
onInput={(e) => props.onBrightnessChange(parseInt(e.currentTarget.value, 10))}
105-
onPointerUp={() => props.onBrightnessChange(store.brightness, true)}
105+
onPointerUp={(e) => props.onBrightnessChange(parseInt(e.currentTarget.value, 10), true)}
106106
/>
107107
<div class="text-sm text-gray-600 text-right">
108-
{Math.round(((store?.brightness || 255) / 255) * 100)}%
108+
{Math.round(((store?.brightness ?? 255) / 255) * 100)}%
109109
</div>
110110
</div>
111111
</SidebarSection>
@@ -122,7 +122,7 @@ export const Sidebar: Component<SidebarProps> = (props) => {
122122
value={store?.artnetUniverse}
123123
class="w-full"
124124
onInput={(e) => props.onArtnetChange(parseInt(e.currentTarget.value, 10))}
125-
onPointerUp={() => props.onArtnetChange(store.artnetUniverse, true)}
125+
onPointerUp={(e) => props.onArtnetChange(parseInt(e.currentTarget.value, 10), true)}
126126
/>
127127
<div class="text-sm text-gray-600 text-right">{store?.artnetUniverse}</div>
128128
</div>
@@ -141,7 +141,7 @@ export const Sidebar: Component<SidebarProps> = (props) => {
141141
value={store?.GOLDelay}
142142
class="w-full"
143143
onInput={(e) => props.onGOLDelayChange(parseInt(e.currentTarget.value, 10))}
144-
onPointerUp={() => props.onGOLDelayChange(store.GOLDelay, true)}
144+
onPointerUp={(e) => props.onGOLDelayChange(parseInt(e.currentTarget.value, 10), true)}
145145
/>
146146
<div class="text-sm text-gray-600 text-right">{store?.GOLDelay}</div>
147147
</div>

frontend/src/components/led-matrix.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface Props {
77
onSetMatrix?: (data: number[]) => void;
88
data: number[];
99
indexData: number[];
10+
brightness: number;
1011
}
1112

1213
export const LedMatrix: Component<Props> = (props) => {
@@ -17,18 +18,18 @@ export const LedMatrix: Component<Props> = (props) => {
1718

1819
const MATRIX_SIZE = 16;
1920
const LED_COLORS = {
20-
OFF: "#333333",
21+
OFF: "#000000",
2122
BACKGROUND: "#111111",
2223
};
2324

2425
const useVisibilityObserver = createVisibilityObserver({ threshold: 0.9 });
2526
const visible = useVisibilityObserver(() => containerRef);
2627

27-
const getLedColor = (brightness: number) => {
28-
if (brightness <= 0) return LED_COLORS.OFF;
29-
30-
const intensity = Math.min(255, Math.max(0, brightness));
31-
return `rgb(${intensity}, ${intensity}, ${intensity})`;
28+
const getLedColor = (ledBrightness: number) => {
29+
const brightnessFactor = props.brightness / 255;
30+
const intensity = Math.round(Math.min(255, Math.max(0, ledBrightness * brightnessFactor)));
31+
const displayIntensity = Math.round(51 + (intensity * 204) / 255);
32+
return `rgb(${displayIntensity}, ${displayIntensity}, ${displayIntensity})`;
3233
};
3334

3435
const drawMatrix = (data: number[], indexData: number[]) => {
@@ -151,6 +152,7 @@ export const LedMatrix: Component<Props> = (props) => {
151152
createEffect(() => {
152153
const data = props.data;
153154
const indexData = props.indexData;
155+
const brightness = props.brightness;
154156

155157
if (canvasRef && data.length && indexData.length) {
156158
drawMatrix(data, indexData);

frontend/src/creator.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,11 @@ export const Creator: Component = () => {
383383
when={!isPlaying()}
384384
fallback={
385385
<div class="animate-fade-in">
386-
<LedMatrix data={currentFrame()} indexData={store.indexMatrix} />
386+
<LedMatrix
387+
data={currentFrame()}
388+
indexData={store.indexMatrix}
389+
brightness={store.brightness || 255}
390+
/>
387391
</div>
388392
}
389393
>
@@ -403,6 +407,7 @@ export const Creator: Component = () => {
403407
<LedMatrix
404408
data={frameSignals()[0]()}
405409
indexData={store.indexMatrix}
410+
brightness={store.brightness || 255}
406411
onSetLed={(data) => {
407412
const [screen, setScreen] = frameSignals();
408413
const currentScreen = [...screen()];

include/plugins/DrawPlugin.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class DrawPlugin : public Plugin
66
{
77
public:
88
void setup() override;
9-
void teardown() override;
109
const char *getName() const override;
1110
void websocketHook(DynamicJsonDocument &request) override;
1211
};

include/screen.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class Screen_
1414
uint8_t brightness_ = 255;
1515
uint8_t renderBuffer_[ROWS * COLS];
1616
uint8_t rotatedRenderBuffer_[ROWS * COLS];
17-
uint8_t cache_[ROWS * COLS];
1817
uint8_t positions[ROWS * COLS] = {
1918
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2019
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
@@ -63,9 +62,6 @@ class Screen_
6362

6463
void loadFromStorage();
6564
void persist();
66-
bool isCacheEmpty() const;
67-
void cacheCurrent();
68-
void restoreCache();
6965
uint8_t getBufferIndex(int index);
7066

7167
void drawLine(int x1, int y1, int x2, int y2, int ledStatus, uint8_t brightness = 255);

src/screen.cpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -86,44 +86,14 @@ void Screen_::clearRect(int x, int y, int width, int height)
8686
}
8787
}
8888

89-
// CACHE START
90-
bool Screen_::isCacheEmpty() const
91-
{
92-
for (int i = 0; i < ROWS * COLS; i++)
93-
{
94-
if (cache_[i] != 0)
95-
return false;
96-
}
97-
return true;
98-
}
99-
100-
void Screen_::cacheCurrent()
101-
{
102-
memcpy(cache_, renderBuffer_, ROWS * COLS);
103-
}
104-
105-
void Screen_::restoreCache()
106-
{
107-
setRenderBuffer(cache_, true);
108-
}
109-
// CACHE END
110-
11189
// STORAGE START
11290
void Screen_::loadFromStorage()
11391
{
11492
#ifdef ENABLE_STORAGE
11593
storage.begin("led-wall", true);
116-
setBrightness(255);
11794

118-
if (currentStatus == NONE)
119-
{
120-
clear();
121-
storage.getBytes("data", renderBuffer_, ROWS * COLS);
122-
}
123-
else
124-
{
125-
storage.getBytes("data", cache_, ROWS * COLS);
126-
}
95+
clear();
96+
storage.getBytes("data", renderBuffer_, ROWS * COLS);
12797

12898
setBrightness(storage.getUInt("brightness", 255));
12999
setCurrentRotation(storage.getUInt("rotation", 0));

0 commit comments

Comments
 (0)