Simulate your app
You can simulate your badge apps with the Tildagon badge simulator.
Installation
- Clone the badge-2024-software repo.
- Open a terminal and navigate to the sim folder.
- From there, run
pipenv install
to install all dependencies.
Not running as expected?
Check the known issues.
Simulate your app
The badge simulator simulates all apps in the sim/apps/
folder To test your app, place your app's python file into the sim/apps/
folder:
- Create a folder for your app, for example
MyApp
. - In the new folder (for example
sim/apps/MyApp/
), copy your app's python file. For example, this isapp.py
for an example app:
import app
from events.input import Buttons, BUTTON_TYPES
class ExampleApp(app.App):
def __init__(self):
self.button_states = Buttons(self)
def update(self, delta):
if self.button_states.get(BUTTON_TYPES["CANCEL"]):
# The button_states do not update while you are in the background.
# Calling clear() ensures the next time you open the app, it stays open.
# Without it the app would close again immediately.
self.button_states.clear()
self.minimise()
def draw(self, ctx):
ctx.save()
ctx.rgb(0.2, 0, 0).rectangle(-120, -120, 240, 240).fill()
ctx.rgb(1, 0, 0).move_to(-80, 0).text("Hello world")
ctx.restore()
__app_export__ = ExampleApp
- In the same folder, create a file called
__init__.py
and use it to import your app's class. If you called your python appapp.py
and the class for your app is calledExampleApp
, you would use the following content:
from .app import ExampleApp
- In the same folder, create a file called
metadata.json
and add your app's metadata. The file needs to contain:
- your app's name
- the category for the app
- the
callable
- which is the Python class for your app. When your app is run, this is the class that will be called to instantiate your app:
{
"callable": "ExampleApp",
"name": "Example app",
"category": "unknown",
"hidden": false
}
- Run the simulator an select your app to test it:
pipenv run python run.py
Troubleshooting
It runs in the simulator but not on the badge?
The simulator uses regular Python, while the badge runs apps with MicroPython. That means language specifics like match case statements will work in the simulator but not on the badge. To test whether your app runs on the badge, follow the instructions to debug your app on your badge.