From baa4e5f0357091d2385844967c529d9ab1ba6fc6 Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Tue, 21 Dec 2021 18:10:27 -0500 Subject: [PATCH] Add qrcode to wifi panel --- README.md | 4 +++- scripts/wifi.sh | 2 +- src/config.cpp | 1 + src/panel/wifi.cpp | 23 ++++++++++++++++++++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d75ceec..cabe8be 100644 --- a/README.md +++ b/README.md @@ -83,5 +83,7 @@ for you. You can add your SSID and password by editing the `WIFI_SSID` and image. The qr code generation relies on the program `qrencode`. It can be installed on -any debian system using `sudo apt install qrencode` +any debian system using `sudo apt install qrencode`. By default the image has a +transparent background. If you would like a different background, you will need +to adjust wifi.cpp to adjust where it is located to your preference. diff --git a/scripts/wifi.sh b/scripts/wifi.sh index 92693d0..a405e21 100755 --- a/scripts/wifi.sh +++ b/scripts/wifi.sh @@ -6,7 +6,7 @@ if [ $# -ne 2 ]; then echo "The result will be in wifi.png" fi -qrencode -s 6 -o "./img/wifi.png" "WIFI:T:WPA;S:$1;P:$2;;" +qrencode -s 6 --background=FFFFFF00 -o "./img/wifi.png" "WIFI:T:WPA;S:$1;P:$2;;" echo "Your wifi qrcode is wifi.png !" echo "Your wifi qrcode is now in the local img folder as wifi.png" diff --git a/src/config.cpp b/src/config.cpp index 6b8e454..9d59802 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -24,6 +24,7 @@ const char* IMAGE_LOCATIONS[] = { "bmp_24.png", "sky.png", "wifi_background.jpg", + "wifi.png", }; size_t IMAGE_LOCATIONS_LENGTH = sizeof(IMAGE_LOCATIONS)/sizeof(IMAGE_LOCATIONS[0]); diff --git a/src/panel/wifi.cpp b/src/panel/wifi.cpp index bf17aea..eb2727c 100644 --- a/src/panel/wifi.cpp +++ b/src/panel/wifi.cpp @@ -69,8 +69,29 @@ void wifi::update_texture(){ SDL_RenderCopy(board::getRenderer(), board::getImage("wifi_background.jpg"), NULL, NULL); + //place the title + tgt.x = 50; + tgt.y = 50; + TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), + "Wireless", + &tgt.w, &tgt.h); + //Note about the string "Wireless" + //Because this is only called once, it makes more sense to not have + //"Wireless" as a static string, and instead generate it dynamically once, + //copy it into this _texture, and then delete if once it goes out of the + //LRU. This way, we dont waste memory holding a string we only copy once + SDL_RenderCopy(board::getRenderer(), + board::getString("Wireless", + { "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), NULL, &tgt); - + //show the QRCode + tgt.x = -25; + tgt.y = tgt.h; + tgt.w = (SCREEN_WIDTH / 2) ; + std::cerr << "TGT.W : " << tgt.w << "\n"; + tgt.h = tgt.w; + SDL_RenderCopy(board::getRenderer(), + board::getImage("wifi.png"), NULL, &tgt); SDL_SetRenderTarget(board::getRenderer(), NULL);