Skip to content

Commit

Permalink
feat: add WiFi and GitHub configuration restoration functions
Browse files Browse the repository at this point in the history
- Added navigation options for restoring WiFi and GitHub configurations.
- Implemented  function for file copying.
- Added  function for updating display.
- Implemented  and  functions to handle configuration restoration.
- Set up initial view and button press handling in the main loop.
  • Loading branch information
dawidrylko committed Jul 7, 2024
1 parent ae3c65c commit 7f2d723
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 1 deletion.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,29 @@ This repository provides several example projects that demonstrate the capabilit

The examples in this repository are organized into different categories based on their functionality. Each category contains a set of examples that demonstrate a specific feature or use case of the Badger 2040.

### ✨ Configuration Restoration

Easily restore WiFi and GitHub configurations with the new configuration restoration feature:

```plaintext
badger_os/
├── examples/
│ ├── restore.py
│ └── icon-restore.png
└── defaults/
├── WIFI_HOME.py
├── WIFI_WORK.py
├── WIFI_HOTSPOT.py
├── GITHUB_HOME.py
└── GITHUB_WORK.py
```

- `config_restore.py`: Main script to handle restoration of WiFi and GitHub configurations.
- `WIFI_HOME.py`, `WIFI_WORK.py`, `WIFI_HOTSPOT.py`: Default WiFi configuration files.
- `GITHUB_HOME.py`, `GITHUB_WORK.py`: Default GitHub configuration files.

Simply press the appropriate button on the Badger 2040 to restore the corresponding configuration.

### 🌐 WiFi

Explore the wireless connectivity capabilities of the Badger 2040 with the following examples:
Expand Down
4 changes: 3 additions & 1 deletion badger_os/GITHUB_CONFIG.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
TOKEN = "__PASTE_YOUR_TOKEN_HERE__"
REPOSITORIES = [
{"owner": "dawidrylko", "repo": "badger2040"},
{"owner": "dawidrylko", "repo": "dawidrylko.com"},
{"owner": "dawidrylko", "repo": "badger2040"},
{"owner": "silesiansolutions", "repo": "silesiansolutions.com"},
{"owner": "silesiansolutions", "repo": "rowniwsieci.pl"},
]
3 changes: 3 additions & 0 deletions badger_os/WIFI_CONFIG.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SSID = ""
PSK = ""
COUNTRY = ""
5 changes: 5 additions & 0 deletions badger_os/defaults/GITHUB_HOME.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TOKEN = "__PASTE_YOUR_HOME_TOKEN_HERE__"
REPOSITORIES = [
{"owner": "dawidrylko", "repo": "dawidrylko.com"},
{"owner": "dawidrylko", "repo": "badger2040"},
]
5 changes: 5 additions & 0 deletions badger_os/defaults/GITHUB_WORK.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TOKEN = "__PASTE_YOUR_WORK_TOKEN_HERE__"
REPOSITORIES = [
{"owner": "silesiansolutions", "repo": "silesiansolutions.com"},
{"owner": "silesiansolutions", "repo": "rowniwsieci.pl"},
]
3 changes: 3 additions & 0 deletions badger_os/defaults/WIFI_HOME.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SSID = "__PASTE_YOUR_HOME_SSID_HERE__"
PSK = "__PASTE_YOUR_HOME_PSK_HERE__"
COUNTRY = "en"
3 changes: 3 additions & 0 deletions badger_os/defaults/WIFI_HOTSPOT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SSID = "__PASTE_YOUR_HOTSPOT_SSID_HERE__"
PSK = "__PASTE_YOUR_HOTSPOT_PSK_HERE__"
COUNTRY = "en"
3 changes: 3 additions & 0 deletions badger_os/defaults/WIFI_WORK.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SSID = "__PASTE_YOUR_WORK_SSID_HERE__"
PSK = "__PASTE_YOUR_WORK_PSK_HERE__"
COUNTRY = "en"
Binary file added badger_os/examples/icon-restore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions badger_os/examples/restore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import badger2040
from badger2040 import WIDTH
import time

NAVIGATION = [
"WiFi: (A) Home | (B) Work",
" (C) HotSpot",
"GitHub: (UP) Home | (DOWN) Work",
]


def copy_file(src, dest):
with open(src, "rb") as src_file:
with open(dest, "wb") as dest_file:
dest_file.write(src_file.read())


def draw_view(lines):
badger.set_pen(15)
badger.clear()

badger.set_font("bitmap8")
badger.set_pen(0)
badger.rectangle(0, 0, WIDTH, 16)
badger.set_pen(15)
badger.text("Restore Defaults", 3, 4, WIDTH, 1)

badger.set_pen(0)
for i, line in enumerate(lines):
badger.text(line, 10, 30 + i * 16)
badger.update()


def restoreWifi(fileName):
badger.led(128)
draw_view(["Restoring config..."] + [""] * 2 + NAVIGATION)
copy_file("/defaults/" + fileName, "/WIFI_CONFIG.py")
time.sleep(2)
draw_view(["Config restored!"] + [""] * 2 + NAVIGATION)
badger.led(0)


def restoreGithubConfig(fileName):
badger.led(128)
draw_view(["Restoring config..."] + [""] * 2 + NAVIGATION)
copy_file("/defaults/" + fileName, "/GITHUB_CONFIG.py")
time.sleep(2)
draw_view(["Config restored!"] + [""] * 2 + NAVIGATION)
badger.led(0)


badger = badger2040.Badger2040()
badger.set_update_speed(2)
badger.led(128)

draw_view([""] * 3 + NAVIGATION)


while True:
# Sometimes a button press or hold will keep the system
# powered *through* HALT, so latch the power back on.
badger.keepalive()

if badger.pressed(badger2040.BUTTON_A):
restoreWifi("WIFI_HOME.py")
if badger.pressed(badger2040.BUTTON_B):
restoreWifi("WIFI_WORK.py")
if badger.pressed(badger2040.BUTTON_C):
restoreWifi("WIFI_HOTSPOT.py")
if badger.pressed(badger2040.BUTTON_UP):
restoreGithubConfig("GITHUB_HOME.py")
if badger.pressed(badger2040.BUTTON_DOWN):
restoreGithubConfig("GITHUB_WORK.py")

badger.halt()

0 comments on commit 7f2d723

Please sign in to comment.