Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • othr_flow3rgit/FLOW3RonICE
  • git-commit/FLOW3RonICE
  • rahix/FLOW3RonICE
3 results
Select Git revision
Loading items
Show changes
Commits on Source (1)
import gc import gc
import json
import math import math
import leds import leds
...@@ -14,15 +13,37 @@ from st3m.ui.colours import BLACK, GO_GREEN, PUSH_RED ...@@ -14,15 +13,37 @@ from st3m.ui.colours import BLACK, GO_GREEN, PUSH_RED
AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
# Set this to true to run without actually attempting WiFi connection.
FAKE = False
class TrainType(Enum): class TrainType(Enum):
ICE = 0 ICE = 0
RAILJET = 1 RAILJET = 1
# Set this to a train type to run without actually attempting WiFi connection. ALL_TRAIN_CONFIGS: Dict[TrainType, Dict[str, Any]] = {
# FAKE = TrainType.ICE TrainType.ICE: {
FAKE = None "name": "ICE",
"logo": "ICE-Logo.png",
"logo_location": (-35, -80, 70, 39),
"max_speed": 300, # 300km/h in germany, 320 in france
"theme": {
"background": (0.137, 0.161, 0.204),
"text": (1, 1, 1),
},
},
TrainType.RAILJET: {
"name": "Railjet",
"logo": "Railjet-Logo.png",
"logo_location": (-58, -80, 116, 30),
"max_speed": 260,
"theme": {
"background": (0.275, 0.275, 0.267),
"text": (0.969, 0.984, 0.961),
},
},
}
class AppState(Enum): class AppState(Enum):
...@@ -34,17 +55,24 @@ class AppState(Enum): ...@@ -34,17 +55,24 @@ class AppState(Enum):
RUN1 = 5 RUN1 = 5
TRAIN_TYPE = TrainType.ICE
TRAIN_CONFIG = ALL_TRAIN_CONFIGS[TRAIN_TYPE]
class App(Application): class App(Application):
def __init__(self, app_ctx: ApplicationContext) -> None: def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx) super().__init__(app_ctx)
self.nic = network.WLAN(network.STA_IF) self.nic = network.WLAN(network.STA_IF)
self.nic.active(True) self.nic.active(True)
if FAKE is None:
# Skip all the WiFi stuff if we're running in fake mode.
if not FAKE:
self.state: AppState = AppState.DETECTING self.state: AppState = AppState.DETECTING
self.train_type: Optional[TrainType] = None self.train_type: Optional[TrainType] = None
else: else:
self.state = AppState.RUN1 self.state = AppState.RUN1
self.train_type = FAKE self.train_type = FAKE
self.time = 0 self.time = 0
self.last_request_time = 0 self.last_request_time = 0
self.bundle_path = app_ctx.bundle_path self.bundle_path = app_ctx.bundle_path
...@@ -52,7 +80,7 @@ class App(Application): ...@@ -52,7 +80,7 @@ class App(Application):
def on_enter(self, vm: Optional[ViewManager]) -> None: def on_enter(self, vm: Optional[ViewManager]) -> None:
super().on_enter(vm) super().on_enter(vm)
if FAKE is None: if not FAKE:
self.state = AppState.DETECTING self.state = AppState.DETECTING
self.train_type = None self.train_type = None
else: else:
...@@ -60,12 +88,9 @@ class App(Application): ...@@ -60,12 +88,9 @@ class App(Application):
self.train_type = FAKE self.train_type = FAKE
def draw(self, ctx: Context) -> None: def draw(self, ctx: Context) -> None:
if self.train_type == TrainType.ICE: # Draw background
ctx.rgb(0.137, 0.161, 0.204) bg_color = TRAIN_CONFIG["theme"]["background"]
elif self.train_type == TrainType.RAILJET: ctx.rgb(bg_color[0], bg_color[1], bg_color[2])
ctx.rgb(0.275, 0.275, 0.267)
else:
ctx.rgb(0, 0, 0)
ctx.rectangle(-120, -120, 240, 240).fill() ctx.rectangle(-120, -120, 240, 240).fill()
if self.state in ( if self.state in (
...@@ -96,14 +121,10 @@ class App(Application): ...@@ -96,14 +121,10 @@ class App(Application):
ctx.font_size = 1 ctx.font_size = 1
ctx.font = ctx.get_font_name(1) ctx.font = ctx.get_font_name(1)
if self.train_type == TrainType.ICE: # Show Speed
ctx.rgb(1, 1, 1) speed_color = TRAIN_CONFIG["theme"]["text"]
ctx.rgb(speed_color[0], speed_color[1], speed_color[2])
text = f"{int(self.train_status['speed'])} km/h" text = f"{int(self.train_status['speed'])} km/h"
elif self.train_type == TrainType.RAILJET:
ctx.rgb(0.969, 0.984, 0.961)
text = f"{int(self.train_status['speed'])} km/h"
else:
text = "???"
scale = 1 / ctx.text_width(text) * 220 scale = 1 / ctx.text_width(text) * 220
ctx.save() ctx.save()
...@@ -123,18 +144,21 @@ class App(Application): ...@@ -123,18 +144,21 @@ class App(Application):
ctx.text("with Deutsche Bahn!") ctx.text("with Deutsche Bahn!")
ctx.restore() ctx.restore()
if self.train_type == TrainType.ICE: # Show Logo
ctx.image(self.bundle_path + "/ICE-Logo.png", -35, -80, 70, 39) image_name = TRAIN_CONFIG["logo"]
elif self.train_type == TrainType.RAILJET: image_location = TRAIN_CONFIG["logo_location"]
ctx.image(self.bundle_path + "/Railjet-Logo.png", -58, -80, 116, 30) ctx.image(
self.bundle_path + "/" + image_name,
image_location[0],
image_location[1],
image_location[2],
image_location[3],
)
# LED Speed Gauge # LED Speed Gauge
if self.train_type == TrainType.ICE: speed_percent = min(
speed_percent = min(self.train_status["speed"] / 260, 1.0) self.train_status["speed"] / TRAIN_CONFIG["max_speed"], 1.0
elif self.train_type == TrainType.RAILJET: )
speed_percent = min(self.train_status["speed"] / 260, 1.0)
else:
speed_percent = 0.0
for led in range(33): for led in range(33):
if speed_percent == 0: if speed_percent == 0:
value = 0.0 value = 0.0
...@@ -165,7 +189,7 @@ class App(Application): ...@@ -165,7 +189,7 @@ class App(Application):
self.train_type = TrainType.RAILJET self.train_type = TrainType.RAILJET
self.state = AppState.CONNECTING self.state = AppState.CONNECTING
break break
elif FAKE is None and not self.nic.isconnected(): elif not FAKE and not self.nic.isconnected():
self.state = AppState.CONNECTING self.state = AppState.CONNECTING
elif self.state == AppState.CONNECTING and self.nic.isconnected(): elif self.state == AppState.CONNECTING and self.nic.isconnected():
print("Connected!") print("Connected!")
...@@ -199,7 +223,7 @@ class App(Application): ...@@ -199,7 +223,7 @@ class App(Application):
elif self.state in (AppState.RUN, AppState.RUN1): elif self.state in (AppState.RUN, AppState.RUN1):
if (self.time - self.last_request_time) > 100 if FAKE else 2500: if (self.time - self.last_request_time) > 100 if FAKE else 2500:
self.last_request_time = self.time self.last_request_time = self.time
if FAKE is not None: if FAKE:
self.train_status = { self.train_status = {
"speed": ( "speed": (
math.sin(self.time / 1000 * math.pi * 2 / 10) * 0.5 + 0.5 math.sin(self.time / 1000 * math.pi * 2 / 10) * 0.5 + 0.5
......
...@@ -10,4 +10,4 @@ author = "rahix, git-commit, david" ...@@ -10,4 +10,4 @@ author = "rahix, git-commit, david"
license = "LGPL-3.0-only" license = "LGPL-3.0-only"
url = "https://git.flow3r.garden/rahix/FLOW3RonICE" url = "https://git.flow3r.garden/rahix/FLOW3RonICE"
description = "FLOW3RonICE - Show current speed of the ICE train you're riding! (Data from WIFIonICE)" description = "FLOW3RonICE - Show current speed of the ICE train you're riding! (Data from WIFIonICE)"
version = 8 version = 9