Skip to content

Commit

Permalink
Add automatic provisioning of the frontboard, from mpy files in github
Browse files Browse the repository at this point in the history
TODO: This currently still builds the files into the firmware, the github action needs changing to mpy-cross these independently
  • Loading branch information
MatthewWilkes committed May 26, 2024
1 parent 9cde5dc commit 9b39b25
Show file tree
Hide file tree
Showing 12 changed files with 371 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ jobs:
micropython/ports/esp32/build-tildagon/partition_table/partition-table.bin
micropython/ports/esp32/build-tildagon/ota_data_initial.bin
micropython/ports/esp32/build-tildagon/tildagon.txt
micropython/ports/esp32/build-tildagon/frozen_mpy/frontboards/TwentyFour/app.mpy
micropython/ports/esp32/build-tildagon/frozen_mpy/frontboards/TwentyFour/tokens.mpy
- name: Create latest release for tags
uses: "marvinpinto/action-automatic-releases@latest"
if: github.event_name == 'push'
Expand Down
10 changes: 5 additions & 5 deletions modules/app_components/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from events.input import BUTTON_TYPES, ButtonDownEvent
from system.eventbus import eventbus

from .tokens import heading_font_size, label_font_size, line_height, set_color
from app_components import tokens


def ease_out_quart(x):
Expand All @@ -21,9 +21,9 @@ def __init__(
change_handler: Union[Callable[[str], Any], None] = None,
back_handler: Union[Callable, None] = None,
speed_ms=300,
item_font_size=label_font_size,
item_line_height=label_font_size * line_height,
focused_item_font_size=heading_font_size,
item_font_size=tokens.label_font_size,
item_line_height=tokens.label_font_size * tokens.line_height,
focused_item_font_size=tokens.heading_font_size,
focused_item_margin=20,
):
self.app = app
Expand Down Expand Up @@ -91,7 +91,7 @@ def draw(self, ctx):
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE

set_color(ctx, "label")
tokens.set_color(ctx, "label")
ctx.move_to(
0, animation_direction * -30 + animation_progress * animation_direction * 30
).text(self.menu_items[self.position % len(self.menu_items)])
Expand Down
6 changes: 6 additions & 0 deletions modules/app_components/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ def clear_background(ctx):

def set_color(ctx, color):
ctx.rgb(*ui_colors.get(color, colors.get(color, color)))


try:
from frontboard.tokens import * # noqa: F403
except ImportError:
pass
34 changes: 34 additions & 0 deletions modules/firmware_apps/poweroff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import app
from app_components.tokens import clear_background

from app_components.dialog import YesNoDialog


class PowerOff(app.App):
async def run(self, render_update):
# Render initial state
await render_update()

# Create a yes/no dialogue, add it to the overlays
dialog = YesNoDialog("Power off?", self)
self.overlays = [dialog]

# Wait for an answer from the dialogue, and if it was yes, randomise colour
if await dialog.run(render_update):
import machine
import bq25895

bq25895.bq25895(machine.I2C(7)).disconnect_battery()

# Remove the dialogue and re-render
self.overlays = []

while True:
await render_update()

def draw(self, ctx):
ctx.save()
clear_background()
ctx.restore()

self.draw_overlays(ctx)
Binary file added modules/frontboards/TwentyFour/EMFTwentyFour.bin
Binary file not shown.
139 changes: 139 additions & 0 deletions modules/frontboards/TwentyFour/FONTLOG.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
FONTLOG for the Raleway fonts

This file provides detailed information on the Raleway Font Software.

This information should be distributed along with the Raleway fonts and any
derivative works.

Basic Font Information

Raleway is an elegant sans-serif typeface family. Initially designed by
Matt McInerney as a single thin weight, it was expanded into a 9 weight family
by Pablo Impallari and Rodrigo Fuenzalida in 2012 and iKerned by Igino Marini.
In 2013 the Italics where added.

It is a display face and the download features both old style and lining
numerals, standard and discretionary ligatures, a pretty complete set of
diacritics, as well as a stylistic alternate inspired by more geometric
sans-serif typefaces than its neo-grotesque inspired default character
set.

It also has a sister display family, Raleway Dots.

Also, the characters set has been expanded to cover 104 Latin languages:
Afar, Afrikaans, Albanian, Azerbaijani, Basque, Belarusian, Bislama, Bosnian, Breton, Catalan, Chamorro, Chichewa, Comorian, Croatian, Czech, Danish, Dutch, English, Esperanto, Estonian, Faroese, Fijian, Filipino/Tagalog, Finnish, Flemish, French, Gaelic (Irish / Manx / Scottish), Gagauz, German, Gikuyu, Gilbertese/Kiribati, Greenlandic, Guarani, Haitian_Creole, Hawaiian, Hungarian, Icelandic, Igo/Igbo, Indonesian, Irish, Italian, Javanese, Kashubian, Kinyarwanda, Kirundi, Latin, Latvian, Lithuanian, Luba/Ciluba/Kasai, Luxembourgish, Malagasy, Malay, Maltese, Maori, Marquesan, Marshallese, Moldovan/Moldovian/Romanian, Montenegrin, Nauruan, Ndebele, Norwegian, Oromo, Palauan/Belauan, Polish, Portuguese, Quechua, Romanian, Romansh, Sami, Samoan, Sango, Serbian, Sesotho, Setswana/Sitswana/Tswana, Seychellois_Creole, SiSwati/Swati/Swazi, Silesian, Slovak, Slovenian, Somali, Sorbian, Sotho, Spanish, Swahili, Swedish, Tahitian, Tetum, Tok_Pisin, Tongan, Tsonga, Tswana, Tuareg/Berber, Turkish, Turkmen, Tuvaluan, Uzbek/Usbek, Wallisian, Walloon, Welsh, Xhosa, Yoruba, Zulu.

The Roman Styles also include support for the following 17 Cyrillic languages:
Balkar, Belarusian, Bosnian, Chukchi, Crimean_Tartar, Erzya, Karachay, Kumyk, Lak,
Macedonian, Moksha, Montenegrin, Nanai, Nogai, Rusyn, Serbian, Ukranian

Documentation can be found at https://www.theleagueofmoveabletype.com

To report issues or contribute to the project see the source repository:
https://github.com/theleagueof/raleway

ChangeLog

6 May 2024 (Tildagon Authors)
- Convert into ctx format for use in Tildagon badge
- Rename to comply with license terms

29 August 2020 (Caleb Maclennan) v4.101
- Repackage so license files get distributed properly

27 August 2020 (Caleb Maclennan) v4.100
- Re-release of the entire font family in more output formats
- Collect all the developments from various forks back to the original project repository
- Build and release using Fontship

10 Jul 2020 () v4.026
- Release on Google Fonts
- Add VTT hints
- Fixup Italic
- Fixup compose/decompose for several glyphs
- Fix diacritic placements

17 December 2016 (Alexei Vanyashin, Cyreal) v4.020
— Expanded glyph set to GF Cyrillic Pro

15 October 2016 (Alexei Vanyashin, Ivan Petrov, Cyreal) v.4.010
— Merged in Cyrillic in the GF Cyrillic Plus + localised variants range
— minor fixed: adjusted win ascender
— changed italic angle to 12 in Italic masters
— added Cyrillic kerning

24 Sept 2013 (Matt McInerney, Pablo Impallari, Rodrigo Fuenzalida) Raleway Family v3.0
- Added Cyrillic to the 9 Roman Weights

26 Jun 2013 (Matt McInerney, Pablo Impallari, Rodrigo Fuenzalida) Raleway Family v2.5
- Charset Extension, now covering 104 Latin Languages.
- Italics Added
- Re-mastered

27 May 2013 (Matt McInerney, Pablo Impallari, Rodrigo Fuenzalida) Raleway Family v2.4 (Beta)
- Italic Masters, ready for iKern

1 May 2013 (Matt McInerney, Pablo Impallari, Rodrigo Fuenzalida) Raleway Family v2.3 (Beta)
- More diactritics added, now supporting all 104 Latin languages
- Added /Delta /Omega /estimated /infinity /integral /lozenge /partialdiff /pi /product /radical /summation /uni0394 /uni03A9 /uni2113
- Lots of small bugs fixed

11 Nov 2012 (Matt McInerney, Pablo Impallari, Rodrigo Fuenzalida) Raleway Family v2.2
- Fixed Font Info and other small bugs.
- 'Heavy' style renamed as 'Black'
- Hinted using the latest version of TTFAutohint, currently v0.9.3.
- Removed the KERN table, now we are using GPOS based Kerning.
- Smaller file size for faster loading on the web.
- Al '-OT' sources files renamed as '-OTF'

7 Sept 2012 (Matt McInerney, Pablo Impallari, Rodrigo Fuenzalida) Raleway Family v2.1
- Fixed vertical metrics bug

11 May 2012 (Matt McInerney, Pablo Impallari, Rodrigo Fuenzalida) Raleway Family v2.0
- iKerned
- Remastered

30 March 2012 (Matt McInerney, Pablo Impallari, Rodrigo Fuenzalida) Raleway Family Beta v1.06
- Initial Beta release of the family expansion - Not yet spaced or Kerned.
- 9 Weights: Thin, ExtraLight, Light, Regular, Medium, SemiBold, Bold, ExtraBold and Heavy weights.
- Characters set expanded to cover 95 languages
- For detailed inspection, please refer to the the FL source files (The OTF files where quickly generated using Ben Kiel's Font Generator macro, for testing purposes only).

20 Feb 2010 (Matt McInerney) Raleway Light v1.01
- Initial Release

Acknowledgements

If you make modifications be sure to add your name (N),
email (E), web-address (if you have one) (W) and
description (D). This list is in alphabetical order.

N: Caleb Maclennan
E: [email protected]
W: https://alerque.com
D: Fontship build system

N: Cyreal
E: [email protected]
W: http://cyreal.org
D: Cyrillic expansion

N: Matt McInerney
E: [email protected]
W: http://pixelspread.com/
D: Designer

N: Pablo Impallari
E: [email protected]
W: http://www.impallari.com
D: Designer

N: Rodrigo Fuenzalida
E: [email protected]
W: http://www.rfuenzalida.com
D: Designer

N: Tildagon Badge Authors
E: [email protected]
W: https://badge.emfcamp.org
D: Embedders
Empty file.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import asyncio

import display
from events.input import Button, BUTTON_TYPES, ButtonDownEvent, ButtonUpEvent
from system.eventbus import eventbus
from tildagonos import tildagonos
from . import FrontBoard
from frontboards import FrontBoard


BUTTONS = {
Expand All @@ -28,8 +27,6 @@ class TwentyTwentyFour(FrontBoard):
}

async def background_task(self):
display.gfx_init()

button_states = {button: False for button in self.BUTTON_PINS.keys()}
while True:
tildagonos.read_egpios()
Expand All @@ -41,3 +38,6 @@ async def background_task(self):
await eventbus.emit_async(ButtonUpEvent(button=button))
button_states[button] = button_down
await asyncio.sleep(0.01)


__app_export__ = TwentyTwentyFour
42 changes: 42 additions & 0 deletions modules/frontboards/TwentyFour/tokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# From https://www.emfcamp.org/about/branding

# Display
display_x = 240
display_y = 240
display_height_inches = 1.28
ppi = display_x / display_height_inches

# Font size
one_pt = ppi / 72
ten_pt = 10 * one_pt
twelve_pt = 12 * one_pt
eighteen_pt = 18 * one_pt
twentyfour_pt = 24 * one_pt
label_font_size = ten_pt
heading_font_size = eighteen_pt

line_height = 1.5

# Colors
colors = {
"pale_green": (175, 201, 68),
"mid_green": (82, 131, 41),
"dark_green": (33, 48, 24),
"yellow": (294, 226, 0),
"orange": (246, 127, 2),
"pink": (245, 80, 137),
"blue": (46, 173, 217),
"white": (232, 230, 227),
}

font_name = "Arimo Regular"

colors = {
name: (c[0] / 256.0, c[1] / 256.0, c[2] / 256.0) for (name, c) in colors.items()
}

ui_colors = {"background": colors["dark_green"], "label": colors["white"]}


def clear_background(ctx):
ctx.rgb(*colors["dark_green"]).rectangle(-120, -120, display_x, display_y).fill()
22 changes: 22 additions & 0 deletions modules/frontboards/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
from app import App
from system.hexpansion.util import read_hexpansion_header, get_hexpansion_block_devices
import vfs


class FrontBoard(App):
year: int


def mount_frontboard(i2c, readonly=True):
header = read_hexpansion_header(i2c, eeprom_addr=0x57)
if header is None:
return False

try:
eep, partition = get_hexpansion_block_devices(i2c, header, addr=0x57)
except Exception:
return False

mountpoint = "/frontboard"

try:
vfs.mount(partition, mountpoint, readonly=readonly)
except OSError:
return False

return True
45 changes: 37 additions & 8 deletions modules/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
# main.py -- put your code here!
from esp32 import Partition
import machine
import os

from system.scheduler import scheduler
from system.hexpansion.app import HexpansionManagerApp
from system.patterndisplay.app import PatternDisplay
from system.notification.app import NotificationService
from system.launcher.app import Launcher
import display
import frontboards
import tildagonos

from frontboards.twentyfour import TwentyTwentyFour

tildagonos.tildagonos.init_gpio()
display.gfx_init()

# Start front-board interface
scheduler.start_app(TwentyTwentyFour())

fb_i2c = machine.I2C(0)
frontboard = 0x57 in fb_i2c.scan()
if frontboard:
# We have a frontboard, try to mount it
mounted = frontboards.mount_frontboard(fb_i2c)
print(f"Frontboard mounted {mounted}")
if not mounted or "app.mpy" not in os.listdir("/frontboard"):
# Provision the board if not mountable
import provision_fb

provision_fb.populate_fb()


# Do main imports after mounting the frontboard so they can
# import the year's design tokens

from system.scheduler import scheduler # noqa: E402
from system.hexpansion.app import HexpansionManagerApp # noqa: E402
from system.patterndisplay.app import PatternDisplay # noqa: E402
from system.notification.app import NotificationService # noqa: E402
from system.launcher.app import Launcher # noqa: E402

# Start expansion interface
scheduler.start_app(HexpansionManagerApp())
Expand All @@ -24,7 +47,13 @@
# Start notification handler
scheduler.start_app(NotificationService(), always_on_top=True)

if frontboard:
# Import the interface and start the app
import frontboard.app

scheduler.start_app(frontboard.app.__app_export__())


Partition.mark_app_valid_cancel_rollback()

scheduler.run_forever()

Loading

0 comments on commit 9b39b25

Please sign in to comment.