added deck.hwinfo module

This commit is contained in:
Luxferre
2025-12-23 00:09:58 +02:00
parent ebbf0fbbe6
commit 97de31f2ad
3 changed files with 33 additions and 1 deletions
+9
View File
@@ -94,6 +94,15 @@ The following `deck.fs` functions are direct aliases to the corresponding `os` c
- `env` = `getenv` = `os.getenv` - `env` = `getenv` = `os.getenv`
- `rnd` = `urandom` = `os.urandom` - `rnd` = `urandom` = `os.urandom`
### `deck.hwinfo` (WIP)
Various hardware information.
Exports the following functions:
- `board_id()`: get the board ID, or `emulated` if it's not run on a CircuitPython device
- `battery_v()`: (T-Deck-specific) get the current battery voltage
### `deck.net` ### `deck.net`
T-Deck/CircuitPython-specific library for Wi-Fi connection and returning `requests` and `socket` library instances. T-Deck/CircuitPython-specific library for Wi-Fi connection and returning `requests` and `socket` library instances.
+23
View File
@@ -0,0 +1,23 @@
# deck.hwinfo: various T-Deck-specific hardware info sources
REAL_HW = False
try:
import board, analogio
vbat_analog = analogio.AnalogIn(board.BAT_ADC)
REAL_HW = True
except:
pass
# get board ID
def board_id():
if REAL_HW:
return board.board_id
else:
return 'emulated'
# get battery voltage
def battery_v():
if REAL_HW:
return (vbat_analog.value * 3.3) / 65535 * 2
else:
return 0
+1 -1
View File
@@ -7,7 +7,7 @@ from deck.fs import unlock_rootfs, lock_rootfs, mount_sd, umount_sd, env, rnd
from deck.fs import du, df, sep, pwd, ls, md, cd, rd, rm, mv, cp, sync from deck.fs import du, df, sep, pwd, ls, md, cd, rd, rm, mv, cp, sync
from deck.input import input, input_multi from deck.input import input, input_multi
from deck.pager import print_paged, term_size from deck.pager import print_paged, term_size
# from deck.hwinfo import from deck.hwinfo import board_id, battery_v
from app.ed import edit, view from app.ed import edit, view
try: try:
from deck import net from deck import net