This commit is contained in:
Félix Baylac Jacqué 2023-08-17 22:37:57 +02:00
commit a92acda560
4 changed files with 106 additions and 0 deletions

59
__init__.py Normal file
View File

@ -0,0 +1,59 @@
from st3m.application import Application, ApplicationContext
from st3m.goose import Dict, Any
from st3m.reactor import Responder
from st3m.ui.view import BaseView, ViewManager
from st3m.input import InputState
from ctx import Context
import st3m.run
import leds
import json
import math
class AlternativebitNick(Application):
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
self._led = 0.0
self._filename = "/flash/nick.json"
self._scale = 1.0
self._phase = 0.0
self._brightness = 0.0
self._brightness_time = 0.0
def draw(self, ctx: Context) -> None:
# Paint the background black
ctx.save()
ctx.scale(self._scale, 1)
ctx.rgb(0, 0, 0).rectangle(-120, -120, 240, 240).fill()
ctx.rgb(1,1,1).round_rectangle(10,0,70,70,2).fill()
ctx.rgb(1,1,1).round_rectangle(-80,0,70,70,2).fill()
ctx.rgb(1,1,1).round_rectangle(10,-90,70,70,2).fill()
ctx.restore()
leds.set_hsv(int(self._led), abs(self._scale) * 360, 1, 0.2)
leds.set_brightness(self._brightness)
leds.update()
def think(self, ins: InputState, delta_ms: int) -> None:
super().think(ins, delta_ms) # Let Application do its thing
self._led += delta_ms / 45
self._phase += delta_ms / 1000
# LED
self._brightness_time += delta_ms
if self._brightness_time < 50:
self._brightness = 0
else:
self._brightness = 69
if self._brightness_time > 1000:
self.brightness_time = 0
# Screen
self._scale = math.sin(self._phase)
if self._led >= 40:
self._led = 0
if __name__ == '__main__':
# Continue to make runnable via mpremote run.
st3m.run.run_view(AlternativebitNick(ApplicationContext))

11
alternativebit-logo.toml Normal file
View File

@ -0,0 +1,11 @@
[app]
name = "Alternativebit Logo"
menu = "Badge"
[entry]
class = "AlternativebitNick"
[metadata]
author = "Ninjatrappeur"
license = "AGPL"
url = "https://git.alternativebit.fr"

25
default.nix Normal file
View File

@ -0,0 +1,25 @@
{ pkgs ? import <nixpkgs> {} }:
let
custom-packages = ps: with ps; [
(
buildPythonPackage rec {
pname = "mpremote";
version = "1.20.0";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-XDQnYqBHkTCd1JvOY8cKB1qnxUixwAdiYrlvnMw5jKI=";
};
doCheck = false;
postPatch = ''
ln -s ${./setup-mpremote.py} setup.py
'';
propagatedBuildInputs = [
pyserial
importlib-metadata
];
}
)
];
my-python = pkgs.python3.withPackages custom-packages;
in my-python

11
setup-mpremote.py Normal file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(name='mpremote',
version='1.20.0',
# Modules to import from other scripts:
packages=find_packages(),
# Executables
scripts=["mpremote/main.py"],
)