Skip to content

Commit

Permalink
Implemented brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
endes0 committed Apr 2, 2023
1 parent 3ec9ff4 commit 93e2060
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 375 deletions.
17 changes: 14 additions & 3 deletions frontend/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const App: Component = () => {
| 'mode'
| 'screen'
| 'led'
| 'persist-mode',
| 'persist-mode'
| 'brightness',
data?: any
) =>
store?.send(
Expand Down Expand Up @@ -57,8 +58,8 @@ export const App: Component = () => {
? 1
: currentRotation + 1
: currentRotation <= 0
? 3
: currentRotation - 1;
? 3
: currentRotation - 1;

store?.setRotation(currentRotation);

Expand All @@ -72,6 +73,8 @@ export const App: Component = () => {

const sendMode = (mode: MODE) => wsMessage('mode', { mode });

const sendBrightness = (brightness: number) => wsMessage('brightness', { brightness });

return (
<Show
when={store?.connectionState() === 1}
Expand Down Expand Up @@ -153,6 +156,14 @@ export const App: Component = () => {
</Button>
</div>

<div class={controlColumn}>
<input type="range" min="0" max="255" value={store?.brightness()} onInput={(e) => {
const brightness = parseInt(e.currentTarget.value);
store?.setBrightness(brightness);
sendBrightness(brightness);
}} />
</div>

<div class={controlColumn}>
{store?.mode() === MODE.NONE && (
<>
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const StoreProvider: ParentComponent = (props) => {
duration: number;
} | null>(null);
const [rotation, setRotation] = createSignal(0);
const [brightness, setBrightness] = createSignal(0);
const [indexMatrix, setIndexMatrix] = createSignal(
[...new Array(256)].map((_, i) => i)
);
Expand All @@ -42,6 +43,7 @@ export const StoreProvider: ParentComponent = (props) => {
case 'info':
setMode(Object.values(MODE)[json.mode as number]);
setRotation(json.rotation);
setBrightness(json.brightness);

setIndexMatrix([...new Array(256)].map((_, i) => i));

Expand Down Expand Up @@ -79,10 +81,12 @@ export const StoreProvider: ParentComponent = (props) => {

const store = {
rotation,
brightness,
indexMatrix,
leds,
mode,
setRotation,
setBrightness,
setIndexMatrix,
setLeds,
setMode,
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export enum MODE {

export interface Store {
rotation: () => number;
brightness: () => number;
indexMatrix: () => number[];
leds: () => number[];
mode: () => MODE;

setRotation: Setter<number>;
setBrightness: Setter<number>;
setIndexMatrix: Setter<number[]>;
setLeds: Setter<number[]>;
setMode: Setter<MODE>;
Expand Down
4 changes: 4 additions & 0 deletions include/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Screen_
Screen_() = default;
int findPosition(uint8_t count);
void rotate();
unsigned int brightness = 255;
uint8_t renderBuffer_[ROWS * COLS];
uint8_t rotatedRenderBuffer_[ROWS * COLS];
uint8_t cache[ROWS * COLS];
Expand Down Expand Up @@ -42,6 +43,9 @@ class Screen_
public:
int currentRotation;

unsigned int getCurrentBrightness() const;
void setBrightness(unsigned int brightness);

void setRenderBuffer(const uint8_t *renderBuffer);
uint8_t *getRenderBuffer();
uint8_t *getRotatedRenderBuffer();
Expand Down
13 changes: 13 additions & 0 deletions src/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void Screen_::loadFromStorage()
{
storage.getBytes("data", this->cache, ROWS * COLS);
}
this->setBrightness(storage.getUInt("brightness", 255));
storage.end();
#endif
}
Expand Down Expand Up @@ -82,6 +83,7 @@ void Screen_::persist()
#ifdef ENABLE_STORAGE
storage.begin("led-wall", false);
storage.putBytes("data", this->renderBuffer_, ROWS * COLS);
storage.putUInt("brightness", this->brightness);
storage.end();
#endif
}
Expand Down Expand Up @@ -218,6 +220,17 @@ void Screen_::drawNumbers(int x, int y, std::vector<int> numbers)
}
}

unsigned int Screen_::getCurrentBrightness() const
{
return this->brightness;
}

void Screen_::setBrightness(unsigned int brightness)
{
this->brightness = brightness;
analogWrite(PIN_ENABLE, 255 - brightness);
}

Screen_ &Screen_::getInstance()
{
static Screen_ instance;
Expand Down
Loading

0 comments on commit 93e2060

Please sign in to comment.