Skip to content

Commit

Permalink
Multiple features (watchdog disable, sd hot-plug) (#186)
Browse files Browse the repository at this point in the history
* 99 D6 rolls for 24 words
match seedsigner/coldcard 99 D6 rolls
100th can be discarted as a full byte is used for checksum

* Make cameras independent from boards
"sensor" no longer needed in board.py
"orientation" also no longer needed

* revert 24w D6 dice rolls to 100

* minimiza camera code changes

* typo

* pylint fix - unused import

* No value error raise when printer is not connected

* Shutdown confirmation

* auto-Go and word delete

* remove del word feature
Add prompt to new words when loading seed

* make simulator compatible with Compact SeedQRs

* standard prompt to print QR

* Export compact Seed QR
Seed QR simulator compatibility
QR grids
Standard prompt for printing
Pylint, black

* 24 words grid grid fix, translations, tests

* missing part of test

* more adjustments

* translations adjust

* a touch press will also confirm firmware update

* assure responsiveness when camera is activated

* Battery voltage indicator

* anti-glare and camera tweaks

* cyclic imports removed

* Tiny Seed, Stackbit 1248 import and export

* Fit more transaction addresses at screen

* Touch press position filter, faster rotary encoder

* Denser PSBT QR codes, QR adjustaments

* Remove part of dice roll count restrictions
from #174

* PR fixes

* Thermal print tiny seed

* Fix single-sig wallet import from Blue and Nunchuk

* Warning on wallet incomplete descriptor import

* Tiny Seed Scanner
some pylint and black cleanup

* Code clean up, black, pylint

* Code cleanup
Code is easier to understand and edit, but got slower framerate

* Tiny seed grayscale scan - faster

* single state check button pull
for better compatibility with event based modes

* debounce for touch

* stackbit word confirmation step

* nostr pubkey event sign - early tests

* Standard SeedQR export

* Update installing.en.md

Fix ktool install instructions for maixpy_dock (`-B dan` parameter)

* Seed QR code optimization
Seed QR display modes
black formatting

* thermal printing optimizations
and bug fixes

* lint black and translations

* black translations

* SeedQR modes - buttons UX fix

* Update README.md

Info about MaixPy IDE terminal

* Update README.md

Explaining MaixPy wdt watchdog

* Update README.md

Added the code to disable krux watchdog

* Update wdt.py

Added code to check if user wanted to disable the watchdog

* Update README.md

added reset() to the end of the code to disable watchdog, this makes krux read the new config file right away

* now wdt.py checks for user configuration for disabling the watchdog

* fixing test_format to be able to run just this file

* Tests for config file that disables krux watchdog

* runned poetry run black

* Creating a constant for WATCHDOG_DISABLE

* Adding extra info regarding running simulator

* Adding info regarding krux bash script helper

* wdt fix const name and json import

* creating helper class to handle SD usage and allow hot-plugging

* SD hot-plugged - few tests broken and simulator not working

* only 2 tests broken, simulator working!

* README instructions to create new translations

* ensure correct encoding for i18n files

* Message about SD mount when entering settings

* fixes pylint and tests broken

* Info about simulator sequences

* msg change for settings

* fix lots of tests

* gitignore

---------

Co-authored-by: Eduardo Schoenknecht <eduardo.schoenknecht@gmail.com>
  • Loading branch information
tadeubas and odudex authored Feb 18, 2023
1 parent c19c03e commit 0dc4181
Show file tree
Hide file tree
Showing 58 changed files with 5,588 additions and 2,254 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ simulator/sd
!tests/firmware-v0.0.0.bin
!tests/firmware-v0.0.0.bin.badsig
!tests/firmware-v0.0.0.bin.sha256.txt
!tests/firmware-v0.0.0.bin.sig
!tests/firmware-v0.0.0.bin.sig

src/kruxsim
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ good-names=i,
tx,
Run,
firmware_hash,
sd,
_

# Good variable names regexes, separated by a comma. If names match any regex,
Expand Down
97 changes: 92 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,20 @@ git pull origin main && git submodule update --init --recursive
```
This will make sure that all submodules (and their submodules, etc.) are pulled down and updated.

## Krux bash script helper
The [krux](krux) file is a bash script helper that have the following functions: `build`, `flash`, `sha256`, `sha256-with-header`, `b64decode`, `generate-keypair`, `pubkey-to-pem`, `pem-to-pubkey`, `sign`, `verify`, `build-release`, `clean`. Some of them uses [Docker](https://www.docker.com/) or the `openssl` lib or even a command-line tool like `wget`. Make sure they are installed before use. It is also a good idea to use [Vagrant](https://www.vagrantup.com/).

Exemples:
```bash
# build project for MaixDock
./krux build maixpy_dock

#flash the project on a MaixDock
./krux flash maixpy_dock
```

## Install krux and dev tools
The krux code is a Python package that should be installed with [Poetry](https://python-poetry.org/).
The krux code is a Python package that should be installed with [Poetry](https://python-poetry.org/) (You can try to install with pip: `pip3 install poetry`).
```bash
poetry install
```
Expand All @@ -48,7 +60,8 @@ Note that you can run `poetry install` after making a change to the krux code if

## Format code
```bash
poetry run black ./src && poetry run black ./tests
poetry run black ./src
poetry run black ./tests
```

## Run pylint
Expand Down Expand Up @@ -85,11 +98,41 @@ Type "help", "copyright", "credits" or "license" for more information.
## Run the simulator
This can be useful for testing a change to the krux code without having to run a full build and flash, visual regression testing,
generating screenshots, or even just trying out Krux before purchasing a device.

Before executing the simulator, make sure you have installed the poetry extras: `poetry install --extras simulator`. Otherwise you will get this error: `ModuleNotFoundError: No module named 'pygame'`
```bash
# Enter simulator folder:
cd simulator

# Run simulator with the touch device amigo, then use mouse to navigate:
poetry run python simulator.py --device maixpy_amigo_tft

# Run simulator with the small device m5stick, then use keyboard to navigate:
poetry run python simulator.py --device maixpy_m5stickv
```

Simulator error troubleshooting:
```bash
cd simulator && poetry run python simulator.py --device maixpy_amigo_tft
# ImportError: Unable to find zbar shared library
sudo apt install python3-zbar

# ImportError: libGL.so.1: cannot open shared object file: No such file or directory
sudo apt install libgl1

# `pygame.error: No available video device`
# You are trying to run the simulator on a SO without a GUI (some kind of terminal only or WSL). Try one with GUI!
```

Simulator sequences (automatic testing):
```bash
cd simulator && poetry run python simulator.py --device maixpy_m5stickv
# Enter simulator folder:
cd simulator

# Run all sequences of commands to all devices and all locales
./generate-all-screenshots.sh

# Run a specific sequence for a specific device (need to have the screenshots and the sd folder with the file settings.json inside)
poetry run python simulator.py --sequence sequences/about.txt --sd --device maixpy_m5stickv
```

## Live debug a device
Expand Down Expand Up @@ -125,7 +168,31 @@ init i2c:2 freq:XXX
[MAIXPY]: find ov sensor
```

From here, you can use the device as normal and, if you added any print statements to the code, they should appear whenever your code is reached.
Krux makes use of MaixPy's [WDT watchdog module](https://wiki.sipeed.com/soft/maixpy/en/api_reference/machine/wdt.html), you can see it [here](src/krux/wdt.py). This will reset the device if not fed for some time. To stop the watchdog, when connected through the terminal, run the following:
```python
# This will read the board config file, add the config to disable watchdog, save the new config file and reset the device (in order to make krux read the new file!)

import json, machine

CONF_FILENAME="/flash/config.json"
CONF_NAME="WATCHDOG_DISABLE"

conf_dict = {}
try:
with open(CONF_FILENAME, "rb") as f:
conf_dict = json.loads(f.read())
except:
pass

conf_dict[CONF_NAME] = 1

with open(CONF_FILENAME, "w") as f:
f.write(json.dumps(conf_dict))

machine.reset()
```

Now, with watchdog disabled, you can use the device normally. So no more automatic resets, and if you added any print statements to the code, they should appear whenever your code is reached.

You can also drop into a live Python REPL at any point by issuing an interrupt with Ctrl-C:

Expand All @@ -142,6 +209,26 @@ Type "help()" for more information.
>>>
```

Customizations made to the firmware removed the support to MaixPy IDE (due to size constraints), but you still can use it's terminal (MaixPy IDE menu bar > Tools > Open Terminal).

## Create new translations - i18n

The project has lots of translations [here](i18n/translations), if you add new english messages in code using `t()` function, you will need to:

```bash
# Enter i18n folder:
cd i18n

# Make sure all files have this new translated message:
python3 i18n.py validade

# Format translation files properly:
python3 i18n.py prettify

# Create the compiled table for krux translations.py
python3 i18n.py bake
```

## Run mkdocs
```bash
poetry run mkdocs serve
Expand Down
16 changes: 9 additions & 7 deletions i18n/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def find_translation_slugs():
for filename in filenames:
if not filename.endswith(".py"):
continue
with open(join(dirpath, filename), "r") as src_file:
with open(join(dirpath, filename), "r", encoding="utf8") as src_file:
contents = src_file.read()
for match in re.findall(r"[^A-Za-z0-9]t\(\s*\"(.+?)\"\s*\)", contents):
slugs[match] = True
Expand Down Expand Up @@ -68,7 +68,7 @@ def validate_translation_files():
print("Validating %s..." % translation_filename)
valid = True
with open(
join(TRANSLATION_FILES_DIR, translation_filename), "r"
join(TRANSLATION_FILES_DIR, translation_filename), "r", encoding="utf8"
) as translation_file:
translations = load_translations(translation_file)
for slug in slugs:
Expand Down Expand Up @@ -96,15 +96,15 @@ def bake_translations():
]
for translation_filename in translation_filenames:
with open(
join(TRANSLATION_FILES_DIR, translation_filename), "r"
join(TRANSLATION_FILES_DIR, translation_filename), "r", encoding="utf8"
) as translation_file:
translations = json.load(translation_file)
lookup = {}
for slug, translation in list(translations.items()):
lookup[binascii.crc32(slug.encode("utf-8"))] = translation
translation_table[basename(translation_filename).split(".")[0]] = lookup

with open(join(SRC_DIR, "krux", "translations.py"), "w") as translations:
with open(join(SRC_DIR, "krux", "translations.py"), "w", encoding="utf8") as translations:
translations.write(
"""# The MIT License (MIT)
Expand Down Expand Up @@ -140,7 +140,9 @@ def create_translation_file(locale):
slugs = find_translation_slugs()
for slug in slugs:
translations[slug.replace("\\n", "\n")] = ""
with open(join(TRANSLATION_FILES_DIR, "%s.json" % locale), "w") as translation_file:
with open(
join(TRANSLATION_FILES_DIR, "%s.json" % locale), "w", encoding="utf8"
) as translation_file:
translation_file.write(
json.dumps(translations, sort_keys=True, indent=4, ensure_ascii=False)
)
Expand All @@ -156,11 +158,11 @@ def prettify_translation_files():
for translation_filename in translation_filenames:
translations = {}
with open(
join(TRANSLATION_FILES_DIR, translation_filename), "r"
join(TRANSLATION_FILES_DIR, translation_filename), "r", encoding="utf8"
) as translation_file:
translations = json.load(translation_file)
with open(
join(TRANSLATION_FILES_DIR, translation_filename), "w"
join(TRANSLATION_FILES_DIR, translation_filename), "w", encoding="utf8"
) as translation_file:
translation_file.write(
json.dumps(translations, sort_keys=True, indent=4, ensure_ascii=False)
Expand Down
Loading

0 comments on commit 0dc4181

Please sign in to comment.