From 7f2d7237029244cbb59095ac81a6e7228bb02fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ry=C5=82ko?= Date: Sun, 7 Jul 2024 14:00:25 +0200 Subject: [PATCH] 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. --- README.md | 23 +++++++++ badger_os/GITHUB_CONFIG.py | 4 +- badger_os/WIFI_CONFIG.py | 3 ++ badger_os/defaults/GITHUB_HOME.py | 5 ++ badger_os/defaults/GITHUB_WORK.py | 5 ++ badger_os/defaults/WIFI_HOME.py | 3 ++ badger_os/defaults/WIFI_HOTSPOT.py | 3 ++ badger_os/defaults/WIFI_WORK.py | 3 ++ badger_os/examples/icon-restore.png | Bin 0 -> 3539 bytes badger_os/examples/restore.py | 75 ++++++++++++++++++++++++++++ 10 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 badger_os/WIFI_CONFIG.py create mode 100644 badger_os/defaults/GITHUB_HOME.py create mode 100644 badger_os/defaults/GITHUB_WORK.py create mode 100644 badger_os/defaults/WIFI_HOME.py create mode 100644 badger_os/defaults/WIFI_HOTSPOT.py create mode 100644 badger_os/defaults/WIFI_WORK.py create mode 100644 badger_os/examples/icon-restore.png create mode 100644 badger_os/examples/restore.py diff --git a/README.md b/README.md index 7ac9f09..125cf3b 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/badger_os/GITHUB_CONFIG.py b/badger_os/GITHUB_CONFIG.py index 8593325..7c5a505 100644 --- a/badger_os/GITHUB_CONFIG.py +++ b/badger_os/GITHUB_CONFIG.py @@ -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"}, ] diff --git a/badger_os/WIFI_CONFIG.py b/badger_os/WIFI_CONFIG.py new file mode 100644 index 0000000..76d4a88 --- /dev/null +++ b/badger_os/WIFI_CONFIG.py @@ -0,0 +1,3 @@ +SSID = "" +PSK = "" +COUNTRY = "" diff --git a/badger_os/defaults/GITHUB_HOME.py b/badger_os/defaults/GITHUB_HOME.py new file mode 100644 index 0000000..1b7e5ea --- /dev/null +++ b/badger_os/defaults/GITHUB_HOME.py @@ -0,0 +1,5 @@ +TOKEN = "__PASTE_YOUR_HOME_TOKEN_HERE__" +REPOSITORIES = [ + {"owner": "dawidrylko", "repo": "dawidrylko.com"}, + {"owner": "dawidrylko", "repo": "badger2040"}, +] diff --git a/badger_os/defaults/GITHUB_WORK.py b/badger_os/defaults/GITHUB_WORK.py new file mode 100644 index 0000000..a21bce3 --- /dev/null +++ b/badger_os/defaults/GITHUB_WORK.py @@ -0,0 +1,5 @@ +TOKEN = "__PASTE_YOUR_WORK_TOKEN_HERE__" +REPOSITORIES = [ + {"owner": "silesiansolutions", "repo": "silesiansolutions.com"}, + {"owner": "silesiansolutions", "repo": "rowniwsieci.pl"}, +] diff --git a/badger_os/defaults/WIFI_HOME.py b/badger_os/defaults/WIFI_HOME.py new file mode 100644 index 0000000..0cd0d5a --- /dev/null +++ b/badger_os/defaults/WIFI_HOME.py @@ -0,0 +1,3 @@ +SSID = "__PASTE_YOUR_HOME_SSID_HERE__" +PSK = "__PASTE_YOUR_HOME_PSK_HERE__" +COUNTRY = "en" diff --git a/badger_os/defaults/WIFI_HOTSPOT.py b/badger_os/defaults/WIFI_HOTSPOT.py new file mode 100644 index 0000000..202e86b --- /dev/null +++ b/badger_os/defaults/WIFI_HOTSPOT.py @@ -0,0 +1,3 @@ +SSID = "__PASTE_YOUR_HOTSPOT_SSID_HERE__" +PSK = "__PASTE_YOUR_HOTSPOT_PSK_HERE__" +COUNTRY = "en" diff --git a/badger_os/defaults/WIFI_WORK.py b/badger_os/defaults/WIFI_WORK.py new file mode 100644 index 0000000..ba3159b --- /dev/null +++ b/badger_os/defaults/WIFI_WORK.py @@ -0,0 +1,3 @@ +SSID = "__PASTE_YOUR_WORK_SSID_HERE__" +PSK = "__PASTE_YOUR_WORK_PSK_HERE__" +COUNTRY = "en" diff --git a/badger_os/examples/icon-restore.png b/badger_os/examples/icon-restore.png new file mode 100644 index 0000000000000000000000000000000000000000..b62cd45be91209588a874052e9f1f992abfb042f GIT binary patch literal 3539 zcmY*bc|278_rJ1ChUh6}e~f*}n6YnTWDi*)Mp?!(gUQ%t2167fdXOzCl%-HqM0N^8 zVagI^A~M#IEh$UFZ}jx*`~80I>)i9c=f2PTe9q^ObMG}{hs;kI+cCY` zz8&OX-aE;{3jn~zgEKO+^)oUv3d9Ez?1MbKux8i*ECJ_bXJ!ZhS}7?GuD&7;e8}8} z>Jw7Eu|p*#89ck{H=g0`2I58-yVz>~kBXW2X9j8Ai(_|iGOANQ@8jf=d^Zl|ieD&SN`e+Wvn^tamD}w9VOIE-pL3x>wYn*@-miuF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z!WE>+sY@A5MtqKVR4X~#oEV@kAz=)T>Vx+sniWyCZk_;1`1#_qi{j) z1Eyk#q4a@*IChPww^^eFjrf`LE&&KnB|nfU?BE15m}xvnw`>vQz+sip&lg_~<({h? zk{u@%!#VIDB<@rhG~nZGj&tog6Iy7O-*CDXT(HB52>oE zwt4F{M{U2Kx&0`@SS*6RKO-Q`$7zh{`-3OC#iqsaFGHL2>y#za94#u$YvYwS@ws_@ zW$l8lIT`dcN^G)se#AXCn97%!^pO~zk%8Nuo|%|R^{m20pTsMZ;&;1%`Cu7%OpsTp znx-ay%elv@gTA&IbVPJkh6LaIO=#62XYmi#+B}J1*sH|APZE&>Oi2SXo7_n>jz}2zXMmsvEyGECs7u(D^|3tDO;blD%5pw`Wh+rXD<4UqhC!*5n6zxwrOYsc;yM_@hXEqDOvz7S!E?(6bhe`EBOeH30U>pBjS!+0)^#836>WhUyAoR!&Q5sk|JazDSQ|evbieX{jn`sY literal 0 HcmV?d00001 diff --git a/badger_os/examples/restore.py b/badger_os/examples/restore.py new file mode 100644 index 0000000..b3c7417 --- /dev/null +++ b/badger_os/examples/restore.py @@ -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()