-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add WiFi and GitHub configuration restoration functions
- 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
1 parent
ae3c65c
commit 7f2d723
Showing
10 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SSID = "" | ||
PSK = "" | ||
COUNTRY = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |