Compare commits
30
Commits
v0.0.5
..
2f0dd1b59b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f0dd1b59b | ||
|
|
2c1d1e42bd | ||
|
|
e125aa5703 | ||
|
|
ec87e87fd1 | ||
|
|
76ea336d6f | ||
|
|
74be0b8a90 | ||
|
|
28bb8be8b2 | ||
|
|
225b231262 | ||
|
|
309266e8e7 | ||
|
|
0b6b3a021b | ||
|
|
d3022c010f | ||
|
|
116cc5ce51 | ||
|
|
6bab8ac3a9 | ||
|
|
f86c94ae99 | ||
|
|
b91ab5d603 | ||
|
|
c4017843ec | ||
|
|
b0a989109a | ||
|
|
e8b1556770 | ||
|
|
b990bf2b8f | ||
|
|
389b83c72f | ||
|
|
ee00ba9b34 | ||
|
|
fa68ab9bcc | ||
|
|
1bcf8e30a0 | ||
|
|
8189157608 | ||
|
|
3f9cee98f4 | ||
|
|
0c8a48cd41 | ||
|
|
09bdd39fd8 | ||
|
|
9506864c2d | ||
|
|
aca227bdc6 | ||
|
|
1020564f8f |
@@ -1,8 +1,7 @@
|
|||||||
name: Build image
|
name: Build image
|
||||||
on:
|
on:
|
||||||
push:
|
tags:
|
||||||
tags:
|
- 'v*'
|
||||||
- 'v*'
|
|
||||||
jobs:
|
jobs:
|
||||||
build-image:
|
build-image:
|
||||||
container:
|
container:
|
||||||
@@ -10,23 +9,18 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
# Required for installing nix
|
- run: apt-get update && apt-get install -y sudo
|
||||||
- name: Install sudo
|
|
||||||
run: apt-get update && apt-get install -y sudo
|
|
||||||
- name: Install Nix
|
- name: Install Nix
|
||||||
uses: cachix/install-nix-action@v31
|
uses: cachix/install-nix-action@v31
|
||||||
with:
|
with:
|
||||||
enable_kvm: false
|
enable_kvm: false
|
||||||
- name: Get image meta
|
- run: echo $GITHUB_REF_NAME
|
||||||
run: nix build .#image-meta -o image-meta
|
|
||||||
- name: Version check
|
|
||||||
run: |
|
|
||||||
VERSION=$(cat image-meta/version)
|
|
||||||
[ "$GITHUB_REF_NAME" = v"$VERSION" ]
|
|
||||||
- name: Build image
|
- name: Build image
|
||||||
run: nix build .#image -o image.tar.gz
|
run: nix build .#image -o image.tar.gz
|
||||||
|
- name: Get image name
|
||||||
|
run: nix build .#image-name -o image-name
|
||||||
- run: docker login -u paul -p "$PASSWORD" git.pbrinkmeier.de
|
- run: docker login -u paul -p "$PASSWORD" git.pbrinkmeier.de
|
||||||
env:
|
env:
|
||||||
PASSWORD: "${{ secrets.REGISTRY_PASSWORD }}"
|
PASSWORD: "${{ secrets.REGISTRY_PASSWORD }}"
|
||||||
- run: docker load < image.tar.gz
|
- run: docker load < image.tar.gz
|
||||||
- run: docker image push $(cat image-meta/name)
|
- run: docker image push $(cat image-name)
|
||||||
+74
-94
@@ -1,68 +1,37 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <Adafruit_GFX.h>
|
|
||||||
#include <Adafruit_ST7735.h>
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266HTTPClient.h>
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#include <ESP8266HTTPClient.h>
|
||||||
#include <WiFiClientSecureBearSSL.h>
|
#include <WiFiClientSecureBearSSL.h>
|
||||||
|
|
||||||
#include "bitmaps.h"
|
#include "bitmaps.h"
|
||||||
#include "wifi_credentials.h"
|
#include "wifi_credentials.h"
|
||||||
|
|
||||||
#define TFT_CS D8
|
// Screen stuff
|
||||||
#define TFT_DC D4
|
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||||
#define TFT_RESET D3
|
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
||||||
|
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
|
||||||
|
#define SCREEN_ADDRESS 0x3C
|
||||||
|
|
||||||
// Button stuff
|
// Button stuff
|
||||||
#define BUTTON_PIN D6
|
#define BUTTON_PIN D6
|
||||||
|
|
||||||
// Display stuff
|
|
||||||
#define FRAME_DELAY 80
|
#define FRAME_DELAY 80
|
||||||
#define COLOR_BG (rgb(0, 0, 0))
|
|
||||||
#define COLOR_DIVIDER (rgb(0xff, 0x60, 0x0d))
|
|
||||||
#define COLOR_TEXT (rgb(0xff, 0x60, 0x0d))
|
|
||||||
|
|
||||||
// Layout
|
|
||||||
|
|
||||||
#define WIDTH 160
|
|
||||||
#define HEIGHT 128
|
|
||||||
|
|
||||||
#define CX 6
|
|
||||||
#define CY 8
|
|
||||||
|
|
||||||
#define MARGIN_LEFT 5
|
|
||||||
#define MARGIN_RIGHT 5
|
|
||||||
|
|
||||||
#define MAIN_X MARGIN_LEFT
|
|
||||||
#define MAIN_Y 9
|
|
||||||
#define MAIN_WIDTH (WIDTH - 2 * MARGIN_LEFT)
|
|
||||||
#define MAIN_HEIGHT (8 * CY)
|
|
||||||
|
|
||||||
#define CLOCK_X MARGIN_LEFT
|
|
||||||
#define CLOCK_Y 113
|
|
||||||
|
|
||||||
#define STATUS_X 95
|
|
||||||
#define STATUS_Y CLOCK_Y
|
|
||||||
#define STATUS_WIDTH (10 * CX)
|
|
||||||
#define STATUS_HEIGHT CY
|
|
||||||
|
|
||||||
// Peripherals
|
// Peripherals
|
||||||
|
|
||||||
Adafruit_ST7735 display(TFT_CS, TFT_DC, TFT_RESET);
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
|
||||||
// App state
|
// App state
|
||||||
|
|
||||||
typedef enum {
|
enum {
|
||||||
CONNECTING,
|
CONNECTING,
|
||||||
SHOWING_DEPARTURES
|
SHOWING_DEPARTURES
|
||||||
} State;
|
} state = CONNECTING;
|
||||||
|
|
||||||
State state = CONNECTING;
|
|
||||||
State previous_state = state;
|
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
// Use this variable to trigger state enter effects
|
|
||||||
int state_changed = 1;
|
|
||||||
|
|
||||||
int buttonPushed = false;
|
int buttonPushed = false;
|
||||||
JsonDocument departures;
|
JsonDocument departures;
|
||||||
|
|
||||||
@@ -70,38 +39,27 @@ void ICACHE_RAM_ATTR onButtonFalling() {
|
|||||||
buttonPushed = true;
|
buttonPushed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t rgb(uint16_t r, uint16_t g, uint16_t b) {
|
|
||||||
// Color layout: RRRRRGGGGGGBBBBB (5, 6, 5)
|
|
||||||
return ((b >> 3) & 0b11111) << 11 | ((g >> 2) & 0b111111) << 5 | ((r >> 3) & 0b11111);
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawLayout() {
|
|
||||||
display.fillScreen(COLOR_BG);
|
|
||||||
display.drawFastHLine(5, 4, 150, COLOR_DIVIDER);
|
|
||||||
display.drawFastHLine(5, 109, 150, COLOR_DIVIDER);
|
|
||||||
display.drawFastHLine(5, 123, 150, COLOR_DIVIDER);
|
|
||||||
display.setCursor(CLOCK_X, CLOCK_Y);
|
|
||||||
display.print("13:12");
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
Serial.println("serial init");
|
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
|
||||||
display.initR();
|
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
||||||
display.setSPISpeed(40000000);
|
Serial.println("SSD1306 allocation failed");
|
||||||
display.setRotation(3);
|
for(;;); // Don't proceed, loop forever
|
||||||
Serial.println("display initialized");
|
}
|
||||||
Serial.printf("display dimensions: %" PRId16 "x%" PRId16 "\n", display.width(), display.height());
|
Serial.println("SSD1306 initialized");
|
||||||
|
display.clearDisplay();
|
||||||
display.setTextSize(1);
|
|
||||||
display.setTextColor(COLOR_TEXT);
|
|
||||||
drawLayout();
|
|
||||||
|
|
||||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||||
|
|
||||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||||
attachInterrupt(BUTTON_PIN, onButtonFalling, FALLING);
|
attachInterrupt(BUTTON_PIN, onButtonFalling, FALLING);
|
||||||
|
|
||||||
|
display.setTextColor(SSD1306_INVERSE);
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.printf("Connecting to\n%s\n", WIFI_SSID);
|
||||||
|
display.display();
|
||||||
/*
|
/*
|
||||||
display.print(" 5 Mannheim sofort\n"
|
display.print(" 5 Mannheim sofort\n"
|
||||||
"26 Kirchheim 9 min\n"
|
"26 Kirchheim 9 min\n"
|
||||||
@@ -109,6 +67,11 @@ void setup() {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawSpinner(int frame) {
|
||||||
|
display.fillRect(120, 56, spinny_dims[0], spinny_dims[1], SSD1306_BLACK);
|
||||||
|
display.drawBitmap(120, 56, spinny[frame % spinny_dims[2]], spinny_dims[0], spinny_dims[1], SSD1306_WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Error handling
|
// TODO: Error handling
|
||||||
String fetchDepartures() {
|
String fetchDepartures() {
|
||||||
std::unique_ptr<BearSSL::WiFiClientSecure> https(new BearSSL::WiFiClientSecure);
|
std::unique_ptr<BearSSL::WiFiClientSecure> https(new BearSSL::WiFiClientSecure);
|
||||||
@@ -116,9 +79,10 @@ String fetchDepartures() {
|
|||||||
|
|
||||||
HTTPClient client;
|
HTTPClient client;
|
||||||
if (!client.begin(*https, "vrnp.beany.club", 443, "/departures?stop_id=de:08221:1225&platform=A")) {
|
if (!client.begin(*https, "vrnp.beany.club", 443, "/departures?stop_id=de:08221:1225&platform=A")) {
|
||||||
display.fillScreen(COLOR_BG);
|
display.clearDisplay();
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.print("begin failed");
|
display.print("begin failed");
|
||||||
|
display.display();
|
||||||
for (;;);
|
for (;;);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,9 +90,10 @@ String fetchDepartures() {
|
|||||||
client.addHeader("Accept", "application/json");
|
client.addHeader("Accept", "application/json");
|
||||||
int statusCode = client.GET();
|
int statusCode = client.GET();
|
||||||
if (statusCode != 200) {
|
if (statusCode != 200) {
|
||||||
display.fillScreen(COLOR_BG);
|
display.clearDisplay();
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.printf("http non-ok: %d\n", statusCode);
|
display.printf("http non-ok: %d\n", statusCode);
|
||||||
|
display.display();
|
||||||
for (;;);
|
for (;;);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,29 +101,20 @@ String fetchDepartures() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (state != previous_state) {
|
|
||||||
state_changed = 1;
|
|
||||||
previous_state = state;
|
|
||||||
}
|
|
||||||
logic_loop();
|
|
||||||
frame++;
|
|
||||||
state_changed = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void logic_loop() {
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case CONNECTING: {
|
case CONNECTING: {
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
display.fillRect(STATUS_X, STATUS_Y, STATUS_WIDTH, STATUS_HEIGHT, COLOR_BG);
|
drawSpinner(frame++);
|
||||||
display.setCursor(STATUS_X, STATUS_Y);
|
display.display();
|
||||||
display.printf(" connect %c", "|/-\\"[frame % 4]);
|
|
||||||
delay(FRAME_DELAY);
|
delay(FRAME_DELAY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
display.fillRect(STATUS_X, STATUS_Y, STATUS_WIDTH, STATUS_HEIGHT, COLOR_BG);
|
display.clearDisplay();
|
||||||
display.setCursor(STATUS_X, STATUS_Y);
|
display.fillRect(0, 56, 128, 8, SSD1306_INVERSE);
|
||||||
display.print(" fetching");
|
display.setCursor(0, 56);
|
||||||
|
display.print("requesting departures");
|
||||||
|
display.display();
|
||||||
|
|
||||||
String departuresRaw = fetchDepartures();
|
String departuresRaw = fetchDepartures();
|
||||||
deserializeJson(departures, departuresRaw);
|
deserializeJson(departures, departuresRaw);
|
||||||
@@ -174,24 +130,48 @@ void logic_loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
display.fillRect(STATUS_X, STATUS_Y, STATUS_WIDTH, STATUS_HEIGHT, COLOR_BG);
|
/*
|
||||||
display.fillRect(MAIN_X, MAIN_Y, MAIN_WIDTH, MAIN_HEIGHT, COLOR_BG);
|
if (buttonPushed) {
|
||||||
|
buttonPushed = false;
|
||||||
|
delay(FRAME_DELAY);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
int line = 0;
|
// Marquee effect for direction strings longer than 11 characters
|
||||||
|
// Neither particularly efficient nor legible
|
||||||
|
// (This could use some love)
|
||||||
|
|
||||||
|
int availableWidth = 11;
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 0);
|
||||||
for (JsonVariant departure : departures["departures"].as<JsonArray>()) {
|
for (JsonVariant departure : departures["departures"].as<JsonArray>()) {
|
||||||
const char *directionStr = departure["direction"].as<const char *>();
|
const char *directionStr = departure["direction"].as<const char *>();
|
||||||
|
|
||||||
display.setCursor(MAIN_X, MAIN_Y + (CY + 3) * line);
|
char buf[128] = {0};
|
||||||
display.printf("%2s %-15.15s %6s",
|
const char *dirStart;
|
||||||
|
|
||||||
|
if (strlen(directionStr) <= availableWidth || (strlen(directionStr) + 3 + availableWidth) > 127) {
|
||||||
|
dirStart = directionStr;
|
||||||
|
} else {
|
||||||
|
memcpy(buf, directionStr, strlen(directionStr));
|
||||||
|
memcpy(buf + strlen(directionStr), " ", 3);
|
||||||
|
memcpy(buf + strlen(directionStr) + 3, directionStr, availableWidth);
|
||||||
|
buf[strlen(directionStr) + 3 + availableWidth] = '\0';
|
||||||
|
dirStart = buf + frame % (strlen(directionStr) + 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
display.printf("%2s %-11.11s %6s\n",
|
||||||
departure["symbol"].as<const char*>(),
|
departure["symbol"].as<const char*>(),
|
||||||
directionStr,
|
dirStart,
|
||||||
departure["leaving"].as<const char*>()
|
departure["leaving"].as<const char*>()
|
||||||
);
|
);
|
||||||
line++;
|
|
||||||
}
|
}
|
||||||
|
display.display();
|
||||||
|
|
||||||
delay(25000);
|
frame++;
|
||||||
state = CONNECTING;
|
delay(500);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
vrnp-static = pkgs.buildGoModule {
|
vrnp-static = pkgs.buildGoModule {
|
||||||
pname = "vrnp";
|
pname = "vrnp";
|
||||||
version = "0.0.5";
|
version = "0.0.4";
|
||||||
vendorHash = null;
|
vendorHash = null;
|
||||||
|
|
||||||
# For building the package, we use only the files not ignored by Git as inputs.
|
# For building the package, we use only the files not ignored by Git as inputs.
|
||||||
@@ -39,10 +39,8 @@
|
|||||||
};
|
};
|
||||||
packages.${system} = {
|
packages.${system} = {
|
||||||
default = vrnp-static;
|
default = vrnp-static;
|
||||||
image-meta = pkgs.runCommand "vrnp-version" {} ''
|
image-name = pkgs.runCommand "vrnp-version" {} ''
|
||||||
mkdir -p $out
|
echo -n git.pbrinkmeier.de/paul/vrnp:${vrnp-static.version} > $out
|
||||||
echo -n ${vrnp-static.version} > $out/version
|
|
||||||
echo -n git.pbrinkmeier.de/paul/vrnp:${vrnp-static.version} > $out/name
|
|
||||||
'';
|
'';
|
||||||
image = pkgs.dockerTools.buildImage {
|
image = pkgs.dockerTools.buildImage {
|
||||||
name = "git.pbrinkmeier.de/paul/vrnp";
|
name = "git.pbrinkmeier.de/paul/vrnp";
|
||||||
|
|||||||
@@ -117,12 +117,6 @@ func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures,
|
|||||||
return Departures{}, errors.New("could not parse countdown")
|
return Departures{}, errors.New("could not parse countdown")
|
||||||
}
|
}
|
||||||
|
|
||||||
matchesPlatform := allowedPlatform == nil || d.Platform == *allowedPlatform
|
|
||||||
isInThePast := countdown < 0
|
|
||||||
if !matchesPlatform || isInThePast {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if countdown == 0 {
|
if countdown == 0 {
|
||||||
leaving = "sofort"
|
leaving = "sofort"
|
||||||
}
|
}
|
||||||
@@ -134,6 +128,10 @@ func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures,
|
|||||||
leaving = fmt.Sprintf("%02s:%02s", dt.Hour, dt.Minute)
|
leaving = fmt.Sprintf("%02s:%02s", dt.Hour, dt.Minute)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if allowedPlatform != nil && d.Platform != *allowedPlatform {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
ds = append(ds, Departure{
|
ds = append(ds, Departure{
|
||||||
d.Platform,
|
d.Platform,
|
||||||
d.ServingLine.Symbol,
|
d.ServingLine.Symbol,
|
||||||
|
|||||||
Reference in New Issue
Block a user