From 23f792caa9d7f68dd720007a8f94deee820e8413 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 19 Jan 2023 12:17:31 +0000 Subject: [PATCH] Badger2040W: Finish core libs, add Badge. --- .../examples/badger2040w/badges/badge.jpg | Bin 0 -> 7878 bytes .../examples/badger2040w/badges/badge.txt | 6 + .../examples/badger2040w/examples/badge.py | 171 ++++++++++++++++++ .../badger2040w/examples/icon-net-info.jpg | Bin 0 -> 2005 bytes .../badger2040w/examples/icon-news.jpg | Bin 0 -> 1767 bytes .../examples/badger2040w/examples/info.py | 17 +- .../examples/{network_info.py => net_info.py} | 0 micropython/examples/badger2040w/launcher.py | 33 +--- .../examples/badger2040w/lib/badger2040w.py | 24 ++- .../examples/badger2040w/uf2-manifest.txt | 4 +- 10 files changed, 210 insertions(+), 45 deletions(-) create mode 100644 micropython/examples/badger2040w/badges/badge.jpg create mode 100644 micropython/examples/badger2040w/badges/badge.txt create mode 100644 micropython/examples/badger2040w/examples/icon-net-info.jpg create mode 100644 micropython/examples/badger2040w/examples/icon-news.jpg rename micropython/examples/badger2040w/examples/{network_info.py => net_info.py} (100%) diff --git a/micropython/examples/badger2040w/badges/badge.jpg b/micropython/examples/badger2040w/badges/badge.jpg new file mode 100644 index 0000000000000000000000000000000000000000..287a43ca98546b172d0367c5f8dcad52d380ac42 GIT binary patch literal 7878 zcmbW)XEYqZ+bHne=ruYUqOQJr@4c*z5WN$u8a-N&h#)#ktWK~(l(0H0qPNvsSS8Uz zbctx;=KsF;+xrgKqSBo56B6)M-9ZI2Hy1n z*#7O40Qg@4_@4p1hlfuT z8ycIMTUy)NdwTo&2L^|RN2X_H=jOjIEaKMIH#WDncYf^dot&Qi`hEWA;_~W0E+7E! zzghpr|Aze^F6w`-d-(Wx_(cD40q+I>>v+`o1RP?7G-^+Xp8C;pioYhNQ%4k|yGght zjE?CY{ijG7z>;g+C;y@Sm+b!z7WMxn`(LpC?ZN@b@qqsh504t40{9i70X-(n{AA&7 ze#4K78spwV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cm^MMqnL$QT7jK=P6!5+F2Ei@{9?3aO_r^c8bYJrv$Y1aEqqm5YpV&Dt9G-hKCh#Y zTp9nv=8;a8J@yVurw?*Fo__R^iydJC|J#bicn2aFsjBL!_;Onb3`k5vL z&!=0v=U3I7Am_%@!wp03`*gL8nc~Yp8PIdHQ&%njHnZNTaM{40i`5+x#ltl)`fddj z6d%TV?(pE1xF}FJk|14t^?50&DIebSEvd&@{|1GIR-HA-LH@-s*j=)<#koxZ!PJpp z`f`fjHoEFHh}$xM-gQ8Q)`QXN$L$1-e))op)T}wf*|KD)r>DKJgUP;8G9TX)bQZ|I zNZidz9~J&^risER?BaJV>&nuXT;*9i07WmCs3Tq5>YEo^sO7hZpSD?4;%}6slWSI1 zf3(k|YK8hXVUPjWHVcGsG*%L{N}3Jl&XmrfMJ^n^XR#~xzggm`QrdTQdsomSE#{rV ziAk~448d8NR5-Q*0&I_tzzxNQB za`#{`m5)zjbtr|Ti;Qh?HwB1%Wa-_`=HQF1-`FBb_w)0K$`#w60iSz@;qEklKZFV& zs4X9(oCGc($uc|PQ>htmRWox2M63LqOv!hWAzHN zoT-rtJGl*m$oa;0SpjZB?MnFAi5eEK9A*ErM!Ynj&aVPej9lqqI#!{3Ib}f+3wY zeQFYdf$8wmW6djz7_MZy#Z`B(Yci}V)Pr6PxDX|gJk|{sSR1ZYJhQcd`T0RI3tZe-~?$*L))wHdi&WY!d 0 and length > width: + text = text[:-1] + else: + text += "" + return text + + +# ------------------------------ +# Drawing functions +# ------------------------------ + +# Draw the badge, including user text +def draw_badge(): + display.set_pen(0) + display.clear() + + # Draw badge image + jpeg.open_file(badge_image) + jpeg.decode(WIDTH - IMAGE_WIDTH, 0) + + # Draw a border around the image + display.set_pen(0) + display.line(WIDTH - IMAGE_WIDTH, 0, WIDTH - 1, 0) + display.line(WIDTH - IMAGE_WIDTH, 0, WIDTH - IMAGE_WIDTH, HEIGHT - 1) + display.line(WIDTH - IMAGE_WIDTH, HEIGHT - 1, WIDTH - 1, HEIGHT - 1) + display.line(WIDTH - 1, 0, WIDTH - 1, HEIGHT - 1) + + # Uncomment this if a white background is wanted behind the company + # display.set_pen(15) + # display.rectangle(1, 1, TEXT_WIDTH, COMPANY_HEIGHT - 1) + + # Draw the company + display.set_pen(15) # Change this to 0 if a white background is used + display.set_font("serif") + display.text(company, LEFT_PADDING, (COMPANY_HEIGHT // 2) + 1, WIDTH, COMPANY_TEXT_SIZE) + + # Draw a white background behind the name + display.set_pen(15) + display.rectangle(1, COMPANY_HEIGHT + 1, TEXT_WIDTH, NAME_HEIGHT) + + # Draw the name, scaling it based on the available width + display.set_pen(0) + display.set_font("sans") + name_size = 2.0 # A sensible starting scale + while True: + name_length = display.measure_text(name, name_size) + if name_length >= (TEXT_WIDTH - NAME_PADDING) and name_size >= 0.1: + name_size -= 0.01 + else: + display.text(name, (TEXT_WIDTH - name_length) // 2, (NAME_HEIGHT // 2) + COMPANY_HEIGHT + 1, WIDTH, name_size) + break + + # Draw a white backgrounds behind the details + display.set_pen(15) + display.rectangle(1, HEIGHT - DETAILS_HEIGHT * 2, TEXT_WIDTH, DETAILS_HEIGHT - 1) + display.rectangle(1, HEIGHT - DETAILS_HEIGHT, TEXT_WIDTH, DETAILS_HEIGHT - 1) + + # Draw the first detail's title and text + display.set_pen(0) + display.set_font("sans") + name_length = display.measure_text(detail1_title, DETAILS_TEXT_SIZE) + display.text(detail1_title, LEFT_PADDING, HEIGHT - ((DETAILS_HEIGHT * 3) // 2), WIDTH, DETAILS_TEXT_SIZE) + display.text(detail1_text, 5 + name_length + DETAIL_SPACING, HEIGHT - ((DETAILS_HEIGHT * 3) // 2), WIDTH, DETAILS_TEXT_SIZE) + + # Draw the second detail's title and text + name_length = display.measure_text(detail2_title, DETAILS_TEXT_SIZE) + display.text(detail2_title, LEFT_PADDING, HEIGHT - (DETAILS_HEIGHT // 2), WIDTH, DETAILS_TEXT_SIZE) + display.text(detail2_text, LEFT_PADDING + name_length + DETAIL_SPACING, HEIGHT - (DETAILS_HEIGHT // 2), WIDTH, DETAILS_TEXT_SIZE) + + +# ------------------------------ +# Program setup +# ------------------------------ + +# Create a new Badger and set it to update NORMAL +display = badger2040w.Badger2040W() +display.led(128) +display.set_update_speed(badger2040w.UPDATE_NORMAL) + +jpeg = jpegdec.JPEG(display.display) + +# Open the badge file +try: + badge = open(BADGE_PATH, "r") +except OSError: + with open(BADGE_PATH, "w") as f: + f.write(DEFAULT_TEXT) + f.flush() + badge = open(BADGE_PATH, "r") + +# Read in the next 6 lines +company = badge.readline() # "mustelid inc" +name = badge.readline() # "H. Badger" +detail1_title = badge.readline() # "RP2040" +detail1_text = badge.readline() # "2MB Flash" +detail2_title = badge.readline() # "E ink" +detail2_text = badge.readline() # "296x128px" +badge_image = badge.readline() # /badges/badge.jpg + +# Truncate all of the text (except for the name as that is scaled) +company = truncatestring(company, COMPANY_TEXT_SIZE, TEXT_WIDTH) + +detail1_title = truncatestring(detail1_title, DETAILS_TEXT_SIZE, TEXT_WIDTH) +detail1_text = truncatestring(detail1_text, DETAILS_TEXT_SIZE, + TEXT_WIDTH - DETAIL_SPACING - display.measure_text(detail1_title, DETAILS_TEXT_SIZE)) + +detail2_title = truncatestring(detail2_title, DETAILS_TEXT_SIZE, TEXT_WIDTH) +detail2_text = truncatestring(detail2_text, DETAILS_TEXT_SIZE, + TEXT_WIDTH - DETAIL_SPACING - display.measure_text(detail2_title, DETAILS_TEXT_SIZE)) + + +# ------------------------------ +# Main program +# ------------------------------ + +draw_badge() + +while True: + if display.pressed(badger2040w.BUTTON_A) or display.pressed(badger2040w.BUTTON_B) or display.pressed(badger2040w.BUTTON_C) or display.pressed(badger2040w.BUTTON_UP) or display.pressed(badger2040w.BUTTON_DOWN): + badger_os.warning(display, "To change the text, connect Badger2040 to a PC, load up Thonny, and modify badge.txt") + time.sleep(4) + + draw_badge() + + display.update() + + # If on battery, halt the Badger to save power, it will wake up if any of the front buttons are pressed + display.halt() diff --git a/micropython/examples/badger2040w/examples/icon-net-info.jpg b/micropython/examples/badger2040w/examples/icon-net-info.jpg new file mode 100644 index 0000000000000000000000000000000000000000..73bcd3e3758b4c23044398b2328b601429753d8e GIT binary patch literal 2005 zcmbW&cTm%58VB%S@=JvPMv8$X1PCnX0+K@Wkbo%l3`!9M6=@2h5{eL5k}qlD6k0}5Rr1YdviB)GdHt)-*?{kpZA$}p3l7R%)2$T zH4f~sx3;qeAP@k6Y!6^-1h4{72m}%VM)QjSvNDTzVmje4wgT(Wy_QN%IMfM@uQ~!YQk0eWR_jdk@{v$k@bm zpVh%b);6|w_RcP@$K2eHd-(eKpE(;4crGmbQbZ&>Dmo!C>FTxX$u}}?XJ%#R-1*_| zy`tih`@9FG4}Yw#sjaJj+|bz8-qHE|r>^c7{R3|Y-~D~){qV#ug2}0A;mqtu@#4}y zmRD9KpVz*+AOQF~YkU12_FpdSwhIb_fiUD(7X%u)JwYrCu1-Phv^G0IO>{u25aiktdJ!d|(PJHBa7naaZtd1}J*Ak1RKj0) z0q>bOlN8DU^m9B>u8e#`JT>9Jk5B#8BlJ1)K78B59A%b0; zgn*beJvchhAmn+>t8wvV>`J|9YtM~xp}2Y`&J-}?ChF>Z%gTL7j-!*kuTcQUhmC5HLt+^M#LIe2w#Z~nxEidIvcn(*rWPC#+V zrt^cRi+HS4Iu<@li^{I+FGdqWgHw5As{I#B@@XGlWp5h$rPSJ~7C#9|Lvl-?%B%2d zCk?-T@_I4KKg&1UPSHJ%o9h>nz-=j_Lw?=Fik{p`Xf_Ni8nVG*)oAvmHE;A0v-pfq z+u7T39200cJLhojaZx3|WTYl&|9s{*L`>UCj7-#m-Lxbd$y&wm%4~WlvbIsZhQZpV*tstu0lnou>|$E> zX;#ESTWW(@Y0qd8iyzKKU96a@e|*EVAWO=Qa6|c|Z7WO_MNV-`-t6(1E-eilo=RF? zUp1;@oKY&JEi76g;V#?*6T75)eL2*y1qH|=FFE{!!#KZF$B?L3y!rZXuSA;uS^o8V zmqus?r)>eudWSzLAtlBUCi>vn84|1;X1NEMW;;Y}O#j}Ju*1fbkKZUhe_>K|@%ELz z>5oLK?$lLMma4HXW#G2Tl~dDAj){$#!~C|Vaz8Vx%1RpQArSC9vv2n#H=;m$Z2!I^ z$UraZWtxEmFBsfRqKDeR-h}Y1v_`HE>5q#kU67lJ7L=6FoU~^f#$Jqdw#abm{ynpp zVuz`yQ%9P2tJ{&&ZQZAx^H+CC$D@#WRRGDtttY>xt_0KA6Ib%ETR1ZEk~L>Be9YSQ zh-pul{Mj@CKiEd%EoK}Rb5nx?BO?jsYRNF?kryv2Sgm$cYXk^Yr~)oGr})CeTYzc{ zDad1fo|jB#Yqsq0tSElRvi5MrzfX8Tc=U3dLp6{iYgrgG&gSB8I$r(pu-SLyrng#m z!N5-7pI$9pRQ7k^TzH1#=)Uy06xyTK zNndWzGc!uj$9%lG*2y51T!DRUmgeKM<6%?J-0#c}TpZ}a7-M4PNp~h%cm>d+|MkRN zGLInNaA^``3~%&)*|qz7`kX|)Q zu~R8}4~LD-y)aG(znxw_QKiR~jp|;zas&9Bu(|7Lhs<}IT8+$npZbB=G9x7?2V)Xt zxV%RW5bj~WVb=QENo)l9#82txM(K^*cY`a<87E$;M5NZ6cL|iS<9QcO7e=yp@Sxdf r9gx(nitAq|7q%A%?ua@jUVQa)b7gcBcaFtS+x{_(bnbB&Tkrn~lNoFH literal 0 HcmV?d00001 diff --git a/micropython/examples/badger2040w/examples/icon-news.jpg b/micropython/examples/badger2040w/examples/icon-news.jpg new file mode 100644 index 0000000000000000000000000000000000000000..7c1b73cb4346e250a3aa49237d02021e646f02cf GIT binary patch literal 1767 zcmbW#YdF+d7y$6|pZgdSlOZuTwq zz2AoK{Wk`Ogl^xlbJy;ueftkYb7Nu;CmcykI(jTQGwbJ**{4qbawfmv{I3@-Ub=kc zX34G6-^$8wSJa4W@7GBl)HghBX?@lvecs+7>+0_Ly|?e}yZ+&ipGHQ<#uXEjvn~iA zzpzy67uY{sB$W$+LLpJuSr>$eR!t-cg*LLq%ysd_21RHYv*K~&6({m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JrizA-Meyf0i2L literal 0 HcmV?d00001 diff --git a/micropython/examples/badger2040w/examples/info.py b/micropython/examples/badger2040w/examples/info.py index 7cfff345..a878edda 100644 --- a/micropython/examples/badger2040w/examples/info.py +++ b/micropython/examples/badger2040w/examples/info.py @@ -1,8 +1,8 @@ import badger2040w from badger2040w import WIDTH -TEXT_SIZE = 0.45 -LINE_HEIGHT = 16 +TEXT_SIZE = 1 +LINE_HEIGHT = 15 display = badger2040w.Badger2040W() display.led(128) @@ -18,24 +18,23 @@ display.set_pen(15) display.text("badgerOS", 3, 4, WIDTH, 1) display.text("info", WIDTH - display.measure_text("help", 0.4) - 4, 4, WIDTH, 1) -display.set_font("sans") display.set_pen(0) y = 16 + int(LINE_HEIGHT / 2) -display.text("Made by Pimoroni, powered by MicroPython", 0, y, WIDTH, TEXT_SIZE) +display.text("Made by Pimoroni, powered by MicroPython", 5, y, WIDTH, TEXT_SIZE) y += LINE_HEIGHT -display.text("Dual-core RP2040, 133MHz, 264KB RAM", 0, y, WIDTH, TEXT_SIZE) +display.text("Dual-core RP2040, 133MHz, 264KB RAM", 5, y, WIDTH, TEXT_SIZE) y += LINE_HEIGHT -display.text("2MB Flash (1MB OS, 1MB Storage)", 0, y, WIDTH, TEXT_SIZE) +display.text("2MB Flash (1MB OS, 1MB Storage)", 5, y, WIDTH, TEXT_SIZE) y += LINE_HEIGHT -display.text("296x128 pixel Black/White e-Ink", 0, y, WIDTH, TEXT_SIZE) +display.text("296x128 pixel Black/White e-Ink", 5, y, WIDTH, TEXT_SIZE) y += LINE_HEIGHT y += LINE_HEIGHT -display.text("For more info:", 0, y, WIDTH, TEXT_SIZE) +display.text("For more info:", 5, y, WIDTH, TEXT_SIZE) y += LINE_HEIGHT -display.text("https://pimoroni.com/badger2040w", 0, y, WIDTH, TEXT_SIZE) +display.text("https://pimoroni.com/badger2040w", 5, y, WIDTH, TEXT_SIZE) display.update() diff --git a/micropython/examples/badger2040w/examples/network_info.py b/micropython/examples/badger2040w/examples/net_info.py similarity index 100% rename from micropython/examples/badger2040w/examples/network_info.py rename to micropython/examples/badger2040w/examples/net_info.py diff --git a/micropython/examples/badger2040w/launcher.py b/micropython/examples/badger2040w/launcher.py index da3d16f2..87947f35 100644 --- a/micropython/examples/badger2040w/launcher.py +++ b/micropython/examples/badger2040w/launcher.py @@ -20,10 +20,6 @@ else: # Otherwise restore previously running app badger_os.state_launch() -# for e.g. 2xAAA batteries, try max 3.4 min 3.0 -MAX_BATTERY_VOLTAGE = 4.0 -MIN_BATTERY_VOLTAGE = 3.2 - display = badger2040.Badger2040W() display.set_font("bitmap8") display.led(128) @@ -51,29 +47,6 @@ def map_value(input, in_min, in_max, out_min, out_max): return (((input - in_min) * (out_max - out_min)) / (in_max - in_min)) + out_min -def draw_battery(level, x, y): - # Outline - display.set_pen(15) - display.rectangle(x, y, 19, 10) - # Terminal - display.rectangle(x + 19, y + 3, 2, 4) - display.set_pen(0) - display.rectangle(x + 1, y + 1, 17, 8) - if level < 1: - display.set_pen(0) - display.line(x + 3, y, x + 3 + 10, y + 10) - display.line(x + 3 + 1, y, x + 3 + 11, y + 10) - display.set_pen(15) - display.line(x + 2 + 2, y - 1, x + 4 + 12, y + 11) - display.line(x + 2 + 3, y - 1, x + 4 + 13, y + 11) - return - # Battery Bars - display.set_pen(15) - for i in range(4): - if level / 4 > (1.0 * i) / 4: - display.rectangle(i * 4 + x + 2, y + 2, 3, 6) - - def draw_disk_usage(x): _, f_used, _ = badger_os.get_disk_usage() @@ -114,7 +87,8 @@ def render(): for i in range(max_icons): x = centers[i] label = examples[i + (state["page"] * 3)] - icon = f"{APP_DIR}/icon-{label}.jpg" + icon_label = label.replace("_", "-") + icon = f"{APP_DIR}/icon-{icon_label}.jpg" label = label.replace("_", " ") jpeg.open_file(icon) jpeg.decode(x - 32, 24) @@ -134,9 +108,6 @@ def render(): display.set_pen(0) display.rectangle(0, 0, WIDTH, 16) draw_disk_usage(90) - vbat = badger_os.get_battery_level() - bat = int(map_value(vbat, MIN_BATTERY_VOLTAGE, MAX_BATTERY_VOLTAGE, 0, 4)) - draw_battery(bat, WIDTH - 22 - 3, 3) display.set_pen(15) display.text("badgerOS", 4, 4, WIDTH, 1.0) diff --git a/micropython/examples/badger2040w/lib/badger2040w.py b/micropython/examples/badger2040w/lib/badger2040w.py index ca5475b4..11e975f8 100644 --- a/micropython/examples/badger2040w/lib/badger2040w.py +++ b/micropython/examples/badger2040w/lib/badger2040w.py @@ -28,6 +28,9 @@ UPDATE_MEDIUM = 1 UPDATE_FAST = 2 UPDATE_TURBO = 3 +LED = 22 +ENABLE_3V3 = 10 + WIDTH = 296 HEIGHT = 128 @@ -69,26 +72,39 @@ def system_speed(speed): class Badger2040W(): def __init__(self): self.display = PicoGraphics(DISPLAY_INKY_PACK) + self._led = machine.PWM(machine.Pin(LED)) + self._led.freq(1000) + self._led.duty_u16(0) def __getattr__(self, item): # Glue to redirect calls to PicoGraphics return getattr(self.display, item) def led(self, brightness): - pass + brightness = max(0, min(255, brightness)) + self._led.duty_u16(int(brightness * 256)) def invert(self, invert): - pass + raise RuntimeError("Display invert not supported in PicoGraphics.") def thickness(self, thickness): - print("Thickness!") + raise RuntimeError("Thickness not supported in PicoGraphics.") def halt(self): - pass + enable = machine.Pin(ENABLE_3V3, machine.Pin.OUT) + enable.off() + while not self.pressed_any(): + pass def pressed(self, button): return BUTTONS[button].value() == 1 + def pressed_any(self): + for button in BUTTONS.values(): + if button.value(): + return True + return False + @micropython.native def icon(self, data, index, data_w, icon_size, x, y): s_x = (index * icon_size) % data_w diff --git a/micropython/examples/badger2040w/uf2-manifest.txt b/micropython/examples/badger2040w/uf2-manifest.txt index 3e0c198b..6325b35e 100644 --- a/micropython/examples/badger2040w/uf2-manifest.txt +++ b/micropython/examples/badger2040w/uf2-manifest.txt @@ -3,4 +3,6 @@ lib/*.py examples/*.jpg examples/*.py images/*.jpg -images/*.txt \ No newline at end of file +images/*.txt +badges/*.txt +badges/*.jpg \ No newline at end of file