Compare commits
15
Commits
a175ad22ae
...
v0.0.5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16f7d80677 | ||
|
|
cf7bb96517 | ||
|
|
f0c94d8d7d | ||
|
|
9f26a280cd | ||
|
|
1eedb2a113 | ||
|
|
b77a2d908d | ||
|
|
2abfb10605 | ||
|
|
c98044dbbc | ||
|
|
831d3765ef | ||
|
|
1cc660dbf2 | ||
|
|
9e5c73e3db | ||
|
|
b15f0b08a1 | ||
|
|
4e6e4f91e0 | ||
|
|
0b1a6699bb | ||
|
|
9c51fb65f1 |
@@ -0,0 +1,32 @@
|
||||
name: Build image
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
jobs:
|
||||
build-image:
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v4
|
||||
# Required for installing nix
|
||||
- name: Install sudo
|
||||
run: apt-get update && apt-get install -y sudo
|
||||
- name: Install Nix
|
||||
uses: cachix/install-nix-action@v31
|
||||
with:
|
||||
enable_kvm: false
|
||||
- name: Get image meta
|
||||
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
|
||||
run: nix build .#image -o image.tar.gz
|
||||
- run: docker login -u paul -p "$PASSWORD" git.pbrinkmeier.de
|
||||
env:
|
||||
PASSWORD: "${{ secrets.REGISTRY_PASSWORD }}"
|
||||
- run: docker load < image.tar.gz
|
||||
- run: docker image push $(cat image-meta/name)
|
||||
+94
-74
@@ -1,37 +1,68 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include <Adafruit_ST7735.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <SPI.h>
|
||||
#include <WiFiClientSecureBearSSL.h>
|
||||
|
||||
#include "bitmaps.h"
|
||||
#include "wifi_credentials.h"
|
||||
|
||||
// Screen stuff
|
||||
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||
#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
|
||||
#define TFT_CS D8
|
||||
#define TFT_DC D4
|
||||
#define TFT_RESET D3
|
||||
|
||||
// Button stuff
|
||||
#define BUTTON_PIN D6
|
||||
|
||||
// Display stuff
|
||||
#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
|
||||
|
||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
Adafruit_ST7735 display(TFT_CS, TFT_DC, TFT_RESET);
|
||||
|
||||
// App state
|
||||
|
||||
enum {
|
||||
typedef enum {
|
||||
CONNECTING,
|
||||
SHOWING_DEPARTURES
|
||||
} state = CONNECTING;
|
||||
} State;
|
||||
|
||||
State state = CONNECTING;
|
||||
State previous_state = state;
|
||||
int frame = 0;
|
||||
// Use this variable to trigger state enter effects
|
||||
int state_changed = 1;
|
||||
|
||||
int buttonPushed = false;
|
||||
JsonDocument departures;
|
||||
|
||||
@@ -39,27 +70,38 @@ void ICACHE_RAM_ATTR onButtonFalling() {
|
||||
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() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
|
||||
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
||||
Serial.println("SSD1306 allocation failed");
|
||||
for(;;); // Don't proceed, loop forever
|
||||
}
|
||||
Serial.println("SSD1306 initialized");
|
||||
display.clearDisplay();
|
||||
Serial.println("serial init");
|
||||
display.initR();
|
||||
display.setSPISpeed(40000000);
|
||||
display.setRotation(3);
|
||||
Serial.println("display initialized");
|
||||
Serial.printf("display dimensions: %" PRId16 "x%" PRId16 "\n", display.width(), display.height());
|
||||
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(COLOR_TEXT);
|
||||
drawLayout();
|
||||
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||
|
||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||
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"
|
||||
"26 Kirchheim 9 min\n"
|
||||
@@ -67,11 +109,6 @@ 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
|
||||
String fetchDepartures() {
|
||||
std::unique_ptr<BearSSL::WiFiClientSecure> https(new BearSSL::WiFiClientSecure);
|
||||
@@ -79,10 +116,9 @@ String fetchDepartures() {
|
||||
|
||||
HTTPClient client;
|
||||
if (!client.begin(*https, "vrnp.beany.club", 443, "/departures?stop_id=de:08221:1225&platform=A")) {
|
||||
display.clearDisplay();
|
||||
display.fillScreen(COLOR_BG);
|
||||
display.setCursor(0, 0);
|
||||
display.print("begin failed");
|
||||
display.display();
|
||||
for (;;);
|
||||
}
|
||||
|
||||
@@ -90,10 +126,9 @@ String fetchDepartures() {
|
||||
client.addHeader("Accept", "application/json");
|
||||
int statusCode = client.GET();
|
||||
if (statusCode != 200) {
|
||||
display.clearDisplay();
|
||||
display.fillScreen(COLOR_BG);
|
||||
display.setCursor(0, 0);
|
||||
display.printf("http non-ok: %d\n", statusCode);
|
||||
display.display();
|
||||
for (;;);
|
||||
}
|
||||
|
||||
@@ -101,20 +136,29 @@ String fetchDepartures() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (state != previous_state) {
|
||||
state_changed = 1;
|
||||
previous_state = state;
|
||||
}
|
||||
logic_loop();
|
||||
frame++;
|
||||
state_changed = 0;
|
||||
}
|
||||
|
||||
void logic_loop() {
|
||||
switch (state) {
|
||||
case CONNECTING: {
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
drawSpinner(frame++);
|
||||
display.display();
|
||||
display.fillRect(STATUS_X, STATUS_Y, STATUS_WIDTH, STATUS_HEIGHT, COLOR_BG);
|
||||
display.setCursor(STATUS_X, STATUS_Y);
|
||||
display.printf(" connect %c", "|/-\\"[frame % 4]);
|
||||
delay(FRAME_DELAY);
|
||||
return;
|
||||
}
|
||||
|
||||
display.clearDisplay();
|
||||
display.fillRect(0, 56, 128, 8, SSD1306_INVERSE);
|
||||
display.setCursor(0, 56);
|
||||
display.print("requesting departures");
|
||||
display.display();
|
||||
display.fillRect(STATUS_X, STATUS_Y, STATUS_WIDTH, STATUS_HEIGHT, COLOR_BG);
|
||||
display.setCursor(STATUS_X, STATUS_Y);
|
||||
display.print(" fetching");
|
||||
|
||||
String departuresRaw = fetchDepartures();
|
||||
deserializeJson(departures, departuresRaw);
|
||||
@@ -130,48 +174,24 @@ void loop() {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
if (buttonPushed) {
|
||||
buttonPushed = false;
|
||||
delay(FRAME_DELAY);
|
||||
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);
|
||||
|
||||
// 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);
|
||||
int line = 0;
|
||||
for (JsonVariant departure : departures["departures"].as<JsonArray>()) {
|
||||
const char *directionStr = departure["direction"].as<const char *>();
|
||||
|
||||
char buf[128] = {0};
|
||||
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",
|
||||
display.setCursor(MAIN_X, MAIN_Y + (CY + 3) * line);
|
||||
display.printf("%2s %-15.15s %6s",
|
||||
departure["symbol"].as<const char*>(),
|
||||
dirStart,
|
||||
directionStr,
|
||||
departure["leaving"].as<const char*>()
|
||||
);
|
||||
line++;
|
||||
}
|
||||
display.display();
|
||||
|
||||
frame++;
|
||||
delay(500);
|
||||
delay(25000);
|
||||
state = CONNECTING;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
vrnp-static = pkgs.buildGoModule {
|
||||
pname = "vrnp";
|
||||
version = "0.0.4";
|
||||
version = "0.0.5";
|
||||
vendorHash = null;
|
||||
|
||||
# For building the package, we use only the files not ignored by Git as inputs.
|
||||
@@ -39,7 +39,12 @@
|
||||
};
|
||||
packages.${system} = {
|
||||
default = vrnp-static;
|
||||
docker = pkgs.dockerTools.buildImage {
|
||||
image-meta = pkgs.runCommand "vrnp-version" {} ''
|
||||
mkdir -p $out
|
||||
echo -n ${vrnp-static.version} > $out/version
|
||||
echo -n git.pbrinkmeier.de/paul/vrnp:${vrnp-static.version} > $out/name
|
||||
'';
|
||||
image = pkgs.dockerTools.buildImage {
|
||||
name = "git.pbrinkmeier.de/paul/vrnp";
|
||||
tag = vrnp-static.version;
|
||||
copyToRoot = pkgs.buildEnv {
|
||||
|
||||
@@ -117,6 +117,12 @@ func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures,
|
||||
return Departures{}, errors.New("could not parse countdown")
|
||||
}
|
||||
|
||||
matchesPlatform := allowedPlatform == nil || d.Platform == *allowedPlatform
|
||||
isInThePast := countdown < 0
|
||||
if !matchesPlatform || isInThePast {
|
||||
continue
|
||||
}
|
||||
|
||||
if countdown == 0 {
|
||||
leaving = "sofort"
|
||||
}
|
||||
@@ -128,10 +134,6 @@ func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures,
|
||||
leaving = fmt.Sprintf("%02s:%02s", dt.Hour, dt.Minute)
|
||||
}
|
||||
|
||||
if allowedPlatform != nil && d.Platform != *allowedPlatform {
|
||||
continue
|
||||
}
|
||||
|
||||
ds = append(ds, Departure{
|
||||
d.Platform,
|
||||
d.ServingLine.Symbol,
|
||||
|
||||
Reference in New Issue
Block a user