Display.virtualPixel + AppDemo [mapping not completely correct]
This commit is contained in:
parent
b7c2899f3f
commit
3fad49cfb4
@ -71,7 +71,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
const DEV_HOST = "10.42.0.81";
|
const DEV_HOST = "10.0.0.119";
|
||||||
|
|
||||||
const S = 100 / 27;
|
const S = 100 / 27;
|
||||||
|
|
||||||
@ -144,8 +144,8 @@
|
|||||||
drawDigit(rasterX, rasterY);
|
drawDigit(rasterX, rasterY);
|
||||||
rasterX += 6;
|
rasterX += 6;
|
||||||
drawPixel(rasterX, rasterY, 0, 0);
|
drawPixel(rasterX, rasterY, 0, 0);
|
||||||
drawPixel(rasterX, rasterY + 2.5, 0, 0);
|
drawPixel(rasterX, rasterY + 2, 0, 0);
|
||||||
drawPixel(rasterX, rasterY + 5.5, 0, 0);
|
drawPixel(rasterX, rasterY + 6, 0, 0);
|
||||||
drawPixel(rasterX, rasterY + 8, 0, 0);
|
drawPixel(rasterX, rasterY + 8, 0, 0);
|
||||||
rasterX += 2;
|
rasterX += 2;
|
||||||
drawDigit(rasterX, rasterY);
|
drawDigit(rasterX, rasterY);
|
||||||
|
|||||||
@ -39,5 +39,5 @@ build_flags = ${common.build_flags}
|
|||||||
monitor_port = ${common.monitor_port}
|
monitor_port = ${common.monitor_port}
|
||||||
monitor_speed = ${common.monitor_speed}
|
monitor_speed = ${common.monitor_speed}
|
||||||
monitor_filters = ${common.monitor_filters}
|
monitor_filters = ${common.monitor_filters}
|
||||||
upload_port = /dev/ttyUSB0
|
upload_port = 10.0.0.119
|
||||||
upload_speed = 921600
|
upload_protocol = espota
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include "../core/log.h"
|
#include "../core/log.h"
|
||||||
|
|
||||||
#include "AppMatch.h"
|
#include "AppMatch.h"
|
||||||
|
#include "AppDemo.h"
|
||||||
|
|
||||||
App *app = nullptr;
|
App *app = nullptr;
|
||||||
|
|
||||||
@ -16,6 +17,8 @@ void appStart(const String& name) {
|
|||||||
|
|
||||||
if (name.equals(APP_MATCH_NAME)) {
|
if (name.equals(APP_MATCH_NAME)) {
|
||||||
app = new AppMatch();
|
app = new AppMatch();
|
||||||
|
} else if (name.equals(APP_DEMO_NAME)) {
|
||||||
|
app = new AppDemo();
|
||||||
} else {
|
} else {
|
||||||
error("No such app: \"%s\"\n", name.c_str());
|
error("No such app: \"%s\"\n", name.c_str());
|
||||||
return;
|
return;
|
||||||
|
|||||||
79
src/app/AppDemo.h
Normal file
79
src/app/AppDemo.h
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#ifndef SPORTTAFEL_APPDEMO_H
|
||||||
|
#define SPORTTAFEL_APPDEMO_H
|
||||||
|
|
||||||
|
#include "App.h"
|
||||||
|
|
||||||
|
#define APP_DEMO_NAME "demo"
|
||||||
|
#define STEP_INTERVAL_MILLIS 500
|
||||||
|
|
||||||
|
class AppDemo : public App {
|
||||||
|
|
||||||
|
uint8_t step = 0;
|
||||||
|
|
||||||
|
unsigned long sum = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit AppDemo() : App(APP_DEMO_NAME) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void _start() override {
|
||||||
|
step = 0;
|
||||||
|
sum = 0;
|
||||||
|
display.setColor(RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
void confirm() override {
|
||||||
|
up();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cancel() override {
|
||||||
|
_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void left() override {
|
||||||
|
down();
|
||||||
|
}
|
||||||
|
|
||||||
|
void right() override {
|
||||||
|
up();
|
||||||
|
}
|
||||||
|
|
||||||
|
void up() override {
|
||||||
|
step = (step + 4) % 5;
|
||||||
|
markDirty(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void down() override {
|
||||||
|
step = (step + 1) % 5;
|
||||||
|
markDirty(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// void _loop(unsigned long dtMillis) override {
|
||||||
|
// auto change = false;
|
||||||
|
// sum += dtMillis;
|
||||||
|
// while (sum > STEP_INTERVAL_MILLIS) {
|
||||||
|
// sum -= STEP_INTERVAL_MILLIS;
|
||||||
|
// step = (step + 1) % 4;
|
||||||
|
// change = true;
|
||||||
|
// }
|
||||||
|
// if (change) {
|
||||||
|
// markDirty(true);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
void draw() override {
|
||||||
|
display.clear();
|
||||||
|
display.strokeRect(step, step, DISPLAY_VIRTUAL_WIDTH - 1 - 2 * step, DISPLAY_VIRTUAL_HEIGHT - 1 - 2 * step);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -8,6 +8,7 @@
|
|||||||
#define MS_PER_SEC (1000L)
|
#define MS_PER_SEC (1000L)
|
||||||
|
|
||||||
#define APP_MATCH_NAME "match"
|
#define APP_MATCH_NAME "match"
|
||||||
|
|
||||||
#define MILLIS_STEP_UP_DOWN (60 * MS_PER_SEC)
|
#define MILLIS_STEP_UP_DOWN (60 * MS_PER_SEC)
|
||||||
#define MILLIS_STEP_LEFT_RIGHT (MS_PER_SEC)
|
#define MILLIS_STEP_LEFT_RIGHT (MS_PER_SEC)
|
||||||
#define MILLIS_MIN (MS_PER_SEC)
|
#define MILLIS_MIN (MS_PER_SEC)
|
||||||
@ -54,7 +55,7 @@ class AppMatch final : public App {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
explicit AppMatch()
|
explicit AppMatch()
|
||||||
: App(APP_MATCH_NAME) {
|
: App(APP_MATCH_NAME) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
// #include <Adafruit_NeoPixel.h>
|
// #include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
#include <AsyncWebSocket.h>
|
#include <AsyncWebSocket.h>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
@ -22,6 +23,9 @@
|
|||||||
#define TOTAL_PIXEL_BYTE_COUNT (TOTAL_PIXEL_COUNT * sizeof(Color))
|
#define TOTAL_PIXEL_BYTE_COUNT (TOTAL_PIXEL_COUNT * sizeof(Color))
|
||||||
#define HEX_BUFFER_SIZE (TOTAL_PIXEL_BYTE_COUNT + 1)
|
#define HEX_BUFFER_SIZE (TOTAL_PIXEL_BYTE_COUNT + 1)
|
||||||
|
|
||||||
|
#define DISPLAY_VIRTUAL_WIDTH 25
|
||||||
|
#define DISPLAY_VIRTUAL_HEIGHT 9
|
||||||
|
|
||||||
#define HEX_BUFFER_MIN_WAIT_MS 500
|
#define HEX_BUFFER_MIN_WAIT_MS 500
|
||||||
|
|
||||||
class Display {
|
class Display {
|
||||||
@ -34,6 +38,11 @@ class Display {
|
|||||||
|
|
||||||
char hexBuffer[HEX_BUFFER_SIZE] = "";
|
char hexBuffer[HEX_BUFFER_SIZE] = "";
|
||||||
|
|
||||||
|
struct Mapping {
|
||||||
|
uint8_t x;
|
||||||
|
uint8_t y;
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Display() /* : leds(PIXEL_COUNT, GPIO_NUM_13) */ {
|
Display() /* : leds(PIXEL_COUNT, GPIO_NUM_13) */ {
|
||||||
@ -150,15 +159,90 @@ public:
|
|||||||
client->text(hexBuffer);
|
client->text(hexBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fillRect(const uint8_t x, uint8_t y, uint8_t w, uint8_t h) {
|
||||||
|
for (int dx = 0; dx < w; ++dx) {
|
||||||
|
for (int dy = 0; dy < h; ++dy) {
|
||||||
|
drawVirtualPixel(x + dx, y + dy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void strokeRect(const uint8_t x, uint8_t y, uint8_t w, uint8_t h) {
|
||||||
|
for (int dx = 0; dx < w; ++dx) {
|
||||||
|
drawVirtualPixel(x + dx, y);
|
||||||
|
drawVirtualPixel(x + dx, y + h);
|
||||||
|
}
|
||||||
|
for (int dy = 0; dy < h; ++dy) {
|
||||||
|
drawVirtualPixel(x, y + dy);
|
||||||
|
drawVirtualPixel(x + w, y + dy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawVirtualPixel(const uint8_t x, const uint8_t y) {
|
||||||
|
const auto index = findIndexForVirtualCoordinates(x, y);
|
||||||
|
if (index >= 0) {
|
||||||
|
pixels[index] = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Mapping digitMapping[32] = {
|
||||||
|
// @formatter:off
|
||||||
|
{0, 3}, {0, 2}, {0, 1}, // top left
|
||||||
|
{1, 0}, {2, 0}, {3, 0}, // top
|
||||||
|
{4, 1}, {4, 2}, {4, 3}, // top right
|
||||||
|
{4, 5}, {4, 6}, {4, 7}, // bottom right
|
||||||
|
{3, 8}, {2, 8}, {1, 8}, // bottom
|
||||||
|
{0, 7}, {0, 6}, {0, 5}, // bottom left
|
||||||
|
{1, 4}, {2, 4}, {3, 4}, // middle
|
||||||
|
// @formatter:on
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t dotMapping[4] = {0, 2, 6, 8};
|
||||||
|
|
||||||
|
uint8_t findIndexForVirtualCoordinates(const uint8_t x, const uint8_t y) {
|
||||||
|
if (x < 0 || x > 24 || y < 0 || y > 8) {
|
||||||
|
return -1;
|
||||||
|
} else if (x >= 20) {
|
||||||
|
return _findIndexForVirtualCoordinates_digitRelative(x - 20, y) + 3 * PIXELS_PER_DIGIT + TOTAL_DOT_PIXEL_COUNT;
|
||||||
|
} else if (x >= 14) {
|
||||||
|
return _findIndexForVirtualCoordinates_digitRelative(x - 14, y) + 2 * PIXELS_PER_DIGIT + TOTAL_DOT_PIXEL_COUNT;
|
||||||
|
} else if (x == 12) {
|
||||||
|
return _findIndexForVirtualCoordinates_dotRelative(y) + 2 * PIXELS_PER_DIGIT;
|
||||||
|
} else if (x >= 6) {
|
||||||
|
return _findIndexForVirtualCoordinates_digitRelative(x - 6, y) + 1 * PIXELS_PER_DIGIT;
|
||||||
|
} else {
|
||||||
|
return _findIndexForVirtualCoordinates_digitRelative(x, y) + 0 * PIXELS_PER_DIGIT;;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t _findIndexForVirtualCoordinates_digitRelative(const uint8_t x, const uint8_t y) {
|
||||||
|
for (auto index = 0; index < PIXELS_PER_DIGIT; index++) {
|
||||||
|
auto item = digitMapping[index];
|
||||||
|
if (item.x == x && item.y == y) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t _findIndexForVirtualCoordinates_dotRelative(const uint8_t y) {
|
||||||
|
for (auto index = 0; index < DOT_COUNT; index++) {
|
||||||
|
auto dotY = dotMapping[index];
|
||||||
|
if (dotY == y) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void fillHexBuffer() {
|
void fillHexBuffer() {
|
||||||
auto b = hexBuffer;
|
auto b = hexBuffer;
|
||||||
for (const auto& pixel: pixels) {
|
for (const auto& pixel: pixels) {
|
||||||
b += snprintf(b, sizeof hexBuffer - (b - hexBuffer), "%X%X%X", pixel.r / 16, pixel.g / 16, pixel.b / 16);
|
b += snprintf(b, sizeof hexBuffer - (b - hexBuffer), "%X%X%X", pixel.r / 16, pixel.g / 16, pixel.b / 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Display display;
|
extern Display display;
|
||||||
|
|||||||
@ -5,13 +5,14 @@
|
|||||||
#include "core/wifi.h"
|
#include "core/wifi.h"
|
||||||
|
|
||||||
#include "app/AppMatch.h"
|
#include "app/AppMatch.h"
|
||||||
|
#include "app/AppDemo.h"
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
logSetup();
|
logSetup();
|
||||||
bootDelay();
|
bootDelay();
|
||||||
fsMount();
|
fsMount();
|
||||||
httpSetup();
|
httpSetup();
|
||||||
appStart(APP_MATCH_NAME);
|
appStart(APP_DEMO_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user