From 1c479a28759da252bc7dc23c5dd64483d9a0dafa Mon Sep 17 00:00:00 2001 From: Brod8362 Date: Tue, 28 Feb 2023 16:21:03 -0600 Subject: [PATCH 1/2] Add sim status window background and make it pretty Instead of drawing just circles use a background image to show status symbols what the respective status means (not just the color of the dots). Furthermore draw a rectangle for the battery status instead of bubbles. --- img/sim_background.bmp | Bin 0 -> 230538 bytes img/sim_background.xcf | Bin 0 -> 12689 bytes main.cpp | 70 ++++++++++++++++++++++++++++++----------- 3 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 img/sim_background.bmp create mode 100644 img/sim_background.xcf diff --git a/img/sim_background.bmp b/img/sim_background.bmp new file mode 100644 index 0000000000000000000000000000000000000000..9fe59049da17fcb276e4e2949265917698160ea7 GIT binary patch literal 230538 zcmeI5S*#V+n#ZfVpLykphmM{2a2|LdAt50ohQts;455j{5C{gMfsPV|07{td6}^O3 zTXDb<$Q6}AF3{JD4K|8gxNxuF0Ei3@w9E>~AoH;L`|oqsK5N&W_pUvjU!Aj3!&?sQ4PXEUU;qYS00v+H24DaNU;qYS00v+H26_?${j5!Fo`u&fOrm{^ z_CXkE83tZ4U;Spm1>vwQkG9a0$}oN_{%$n}=9)(D1iB41eA2e}LBo_`FwnFN9Lb|y zuj6;{UDNum)#?h)H`(i(-lokPMfCf3^oxFB00v+H24DaNU;qZ%oPkC5`+l-;x{hI= z9c!os?s2dI3{=NJ{8^B1i>mef6ZA{@1p`$xaNKNIYpv$We+9m)+IQ4l)zw|?V81D* zqjc$NThVLz}P{ZHZy4thb!G8P({Mcv)mdEt3a_aC-vP1}XfY|mApx%n~uj;(A@ror%?hESvVmeuy$8|_kd!9Y_mpfRj8MwZ&8 z^3}Jhi`92}mIcaNYybnz$-rRK=Oqha-K+PMsBfFoU+4(G#2Gjn)9(gbkEdZBo4`PG zG7$EyQXBO&^h@~#11-aV`e>}S@HY#;$8Rm;H|oRYtPk-Eet`iPfB_hQ0T_S*7=Qs7 zfB_hQ0T_S*7=Qs7fB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^e{%4{)N@6m(^fx*SdJ{5v<(5wLb8|0QS@__;Y(y z9v*seb^C0@cr)shIHbd(>eJ4Fs1q=7^EAy*?Yrl+-jCVdtz!e~cVUM2VAtLNX)<@*0UkFXTMs{VJFX+9|jFP2rBIgQTjW)a{<1L%XjgbQSdb@U2e*Fsuj8PGA<&;W}BYnZL5TLIt5uI zHZAg;sAnl&b1^`C6`AA7xjmD+GsDZ=d)unR9_7gG*>T;TO5ec{uQy2v|N8FwuTqSWC^WiS#!5s>~jdY@1h1+OHxww+zzL{>I z3YW^H#l;g^Gh8x>&iHXt=7a0xG2BkS(U${}47ri>fbT`QAN9nAlXmzDtv5j%emV<|xjtUsAaLX%BeM(@ZGm8=>u2C_M1=hrkiW z*IdLm!7S~7#zl6ciqr5)Xw+w1P=q(*eEdofcV)N0?!GlXK>EBC)X~ozxZ9g|5OIU= zsb13O9>mf3A)A|q=Jqq=#_SNLd9RBG<{q; z$_=4~*{aYx`Fjl}O*OdZpvto} zCap2~XRR~wlm|^b&EmsI;j=0`MG)qNr?~&{MUegjK=`7O`TuLb{~qY0qwS*bMcBh1 zV22%Rcm88{V0dKif92i&e}C`BzW;!F|LD8tSUdk%<){A}7@7a6)r_ZF^PY@v;ApLqtV4?& zaQ;~iE!kfW$-Iy%GA1^j*(Fd-UgZ=MS9M$1xN9}(+7~?142lu1^@s6 literal 0 HcmV?d00001 diff --git a/main.cpp b/main.cpp index 9c61966..7a04302 100644 --- a/main.cpp +++ b/main.cpp @@ -426,6 +426,16 @@ public: init_NRF_WDT(); init_NRF_POWER(); + // Attempt to load background PNG for the status display window + SDL_Surface* simDisplayBgRaw = SDL_LoadBMP("img/sim_background.bmp"); + if (simDisplayBgRaw == NULL) { + printf("Failed to load sim background image: %s\n", SDL_GetError()); + } else { + // convert the loaded image into a texture + simDisplayTexture = SDL_CreateTextureFromSurface(renderer, simDisplayBgRaw); + SDL_FreeSurface(simDisplayBgRaw); + simDisplayBgRaw = NULL; + } motorController.Init(); settingsController.Init(); @@ -444,6 +454,9 @@ public: // Destructor ~Framework(){ + if (simDisplayTexture != NULL) { + SDL_DestroyTexture(simDisplayTexture); + } SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); @@ -486,6 +499,8 @@ public: } void refresh() { + // left edge for all "bubbles" (circles) + constexpr const int bubbleLeftEdge = 65; // always refresh the LVGL screen this->refresh_screen(); @@ -494,9 +509,13 @@ public: } SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL_RenderClear(renderer); + // Render the background if it was able to be loaded + if (simDisplayTexture != NULL) { + SDL_RenderCopy(renderer, simDisplayTexture, NULL, NULL); + } { // motorController.motor_is_running - constexpr const int center_x = 45; - constexpr const int center_y = 15; + constexpr const int center_x = bubbleLeftEdge; + constexpr const int center_y = 216; bool motor_is_running = nrf_gpio_pin_read(Pinetime::PinMap::Motor); if (motor_is_running) { draw_circle_red(center_x, center_y, 15); @@ -505,8 +524,8 @@ public: } } { // ble.motor_is_running - constexpr const int center_x = 75; - constexpr const int center_y = 15; + constexpr const int center_x = bubbleLeftEdge; + constexpr const int center_y = 24; if (bleController.IsConnected()) { draw_circle_blue(center_x, center_y, 15); } else { @@ -514,18 +533,31 @@ public: } } // batteryController.percentRemaining - for (uint8_t percent=0; percent<=10; percent++) { - const int center_x = 15+15*percent; - const int center_y = 60; - if (batteryController.percentRemaining < percent*10) { - draw_circle_grey(center_x, center_y, 15); - } else { - draw_circle_green(center_x, center_y, 15); - } + { + const int center_x = bubbleLeftEdge; + const int center_y = 164; + const int max_bar_length = 150; + const int filled_bar_length = max_bar_length * (batteryController.percentRemaining/100.0); + const int rect_height = 14; + SDL_Rect rect { + .x = center_x - rect_height/2, + .y = center_y, + .w = max_bar_length, + .h = rect_height + }; + SDL_SetRenderDrawColor(renderer, 128, 128, 128, 255); + SDL_RenderDrawRect(renderer, &rect); + + rect.w = filled_bar_length; + rect.h++; + rect.h-=2; + SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); + SDL_RenderFillRect(renderer, &rect); + //set color and new x pos, draw again } { // batteryController.isCharging - constexpr const int center_x = 15; - constexpr const int center_y = 90; + constexpr const int center_x = bubbleLeftEdge; + constexpr const int center_y = 120; if (batteryController.isCharging) { draw_circle_yellow(center_x, center_y, 15); } else @@ -534,7 +566,7 @@ public: } } { // brightnessController.Level - constexpr const int center_y = 15; + constexpr const int center_y = 72; const Pinetime::Controllers::BrightnessController::Levels level = brightnessController.Level(); uint8_t level_idx = 0; if (level == Pinetime::Controllers::BrightnessController::Levels::Low) @@ -548,11 +580,12 @@ public: level_idx = 3; } for (uint8_t i=0; i<4; i++) { - const int center_x = 115+15*i; + const int bubble_size = (i*2) + 5; + const int center_x = bubbleLeftEdge + ((bubble_size+10) * i) - 5; if (i <= level_idx) { - draw_circle_white(center_x, center_y, 15); + draw_circle_white(center_x, center_y, bubble_size); } else { - draw_circle_grey(center_x, center_y, 15); + draw_circle_grey(center_x, center_y, bubble_size); } } } @@ -943,6 +976,7 @@ private: int width; // Width of the window SDL_Renderer *renderer = NULL; // Pointer for the renderer SDL_Window *window = NULL; // Pointer for the window + SDL_Texture* simDisplayTexture = NULL; // Background for the sim status window bool left_release_sent = true; // make sure to send one mouse button release event bool right_last_state = false; // varable used to send message only on changing state From aa34f93161f7e8576673efe2a13f0f23844f243e Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Mon, 8 May 2023 18:30:13 +0200 Subject: [PATCH 2/2] sim: embedd background bmp and load from memory Loading the file from disk introduces a slight dependency on the working directory for the simulator. Prevent that by loading the bmp from memory. Use a python script to convert the backround bmp image to a C header file. Include this header in `main.cpp` and load the bmp from memory. --- CMakeLists.txt | 4 ++++ img/CMakeLists.txt | 26 ++++++++++++++++++++++++++ img/convert_bmp_to_header.py | 21 +++++++++++++++++++++ main.cpp | 8 ++++++-- 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 img/CMakeLists.txt create mode 100755 img/convert_bmp_to_header.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 182714e..a156977 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -325,6 +325,10 @@ endif() target_include_directories(infinisim PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/gif-h") +# embedd background image for the status window to use +add_subdirectory(img) +add_dependencies(infinisim infinisim_img_background) + install(TARGETS infinisim DESTINATION bin) # helper library to manipulate littlefs raw image diff --git a/img/CMakeLists.txt b/img/CMakeLists.txt new file mode 100644 index 0000000..ce274bf --- /dev/null +++ b/img/CMakeLists.txt @@ -0,0 +1,26 @@ +message(STATUS "folder img: converting background.bmp to C file to include in binary") + +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12) + # FindPython3 module introduces with CMake 3.12 + # https://cmake.org/cmake/help/latest/module/FindPython3.html + find_package(Python3 REQUIRED) +else() + set(Python3_EXECUTABLE "python") +endif() + +set(bmp_file ${CMAKE_CURRENT_SOURCE_DIR}/sim_background.bmp) +set(out_file ${CMAKE_CURRENT_BINARY_DIR}/sim_background.h) +# call python script to convert image to c file +add_custom_command( + OUTPUT ${out_file} + COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/convert_bmp_to_header.py + ${bmp_file} + --var-name "SIM_BACKGROUND" + --output ${out_file} + DEPENDS ${bmp_file} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) +# add target that can be added as dependency to infinisim target to trigger creation of C-file +add_custom_target(infinisim_img_background + DEPENDS ${out_file} +) diff --git a/img/convert_bmp_to_header.py b/img/convert_bmp_to_header.py new file mode 100755 index 0000000..4707072 --- /dev/null +++ b/img/convert_bmp_to_header.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +import argparse + +parser = argparse.ArgumentParser() + +parser.add_argument("bmp", + help="Path to bmp to convert to C header file") +parser.add_argument("--var-name", + help="name of the variable to make the bmp data available", + default="IMAGE_DATA") +parser.add_argument("-o", "--output", + help="Path where to create C header file", + required=True) +args = parser.parse_args() + +with open(args.output, "w", encoding="utf-8") as f: + # conversion script based on: + # https://stackoverflow.com/questions/18422123/sdl-embed-image-inside-program-executable + f.write("static const unsigned char {:s}[] = {{{:s}}};".format( + args.var_name, + ",".join(str(b) for b in open(args.bmp, "rb").read()))) diff --git a/main.cpp b/main.cpp index 7a04302..118b8e1 100644 --- a/main.cpp +++ b/main.cpp @@ -69,6 +69,8 @@ #endif #include +#include "img/sim_background.h" // provides variable SIM_BACKGROUND + /********************* * DEFINES *********************/ @@ -426,8 +428,10 @@ public: init_NRF_WDT(); init_NRF_POWER(); - // Attempt to load background PNG for the status display window - SDL_Surface* simDisplayBgRaw = SDL_LoadBMP("img/sim_background.bmp"); + // Attempt to load background BMP from memory for the status display window + const size_t SIM_BACKGROUND_size = sizeof(SIM_BACKGROUND); + SDL_RWops *rw = SDL_RWFromMem((void*)SIM_BACKGROUND, SIM_BACKGROUND_size); + SDL_Surface* simDisplayBgRaw = SDL_LoadBMP_RW(rw, 1); if (simDisplayBgRaw == NULL) { printf("Failed to load sim background image: %s\n", SDL_GetError()); } else {