Blueforcer / awtrix3

Custom firmware for the Ulanzi Smart Pixel clock or self made awtrix. Getting started is easy as 1-2-3
https://blueforcer.github.io/awtrix3/
Other
1.25k stars 108 forks source link

[QUESTION] settings TCOL - hex to int? #162

Closed klein0r closed 1 year ago

klein0r commented 1 year ago

Question

How does the conversion from hex to int work?

When setting TCOL to #0000FF, the settings endpoint return 31 for that value (instead of 255). How does the conversion works?

Additional information

Logs

2023-06-04 11:03:28.409  - debug: awtrix-light.0 (112550) sending "POST" request to "/api/settings" with data: {"TCOL":"#0000FF"}
2023-06-04 11:03:28.458  - debug: awtrix-light.0 (112550) received 200 response from "/api/settings" with content: "OK"
2023-06-04 11:03:28.459  - debug: awtrix-light.0 (112550) sending "GET" request to "/api/settings" without data
2023-06-04 11:03:28.502  - debug: awtrix-light.0 (112550) received 200 response from "/api/settings" with content: {"FPS":23,"ABRI":true,"BRI":255,"ATRANS":true,"TCOL":31,"TSPEED":400,"ATIME":7000,"TFORMAT":"%H:%M:%S","DFORMAT":"%d.%m.%y","SOM":true,"CEL":true,"MAT":0,"SOUND":true,"GAMMA":0}
Blueforcer commented 1 year ago

It is the raw RGB565 value (16-bit color) wich is the converted RGB888 (24-bit color) youve sent. In this format, your #0000FF blue color converts to a value of 31 (or 1F in hexadecimal), not 255.

The RGB565 color bitmask is rrrrrggg:gggbbbbb: red - 5 bit (0-31) in MSB, green - 6 bit (0-63), blue - 5 bit (0-31) in LSB.

Convertingfunction: https://github.com/Blueforcer/awtrix-light/blob/d4e34c74ed127cb05d484aff6e5006e6e72b187e/src/Functions.h#L83-L95

Awtrix essentially "shrink" the color's range from 0-255 (8-bit) to 0-31 (5-bit): The blue component in the RGB888 representation is FF, which equals to 255 in decimal. To convert this to a 5-bit number, we divide 255 by the maximum 8-bit number (255), and multiply by the maximum 5-bit number (31): (255 / 255) * 31 = 31

Blueforcer commented 1 year ago

Du kannst auch gerne mal den discord server joinen, da können wir für deine Integration in einem eigenen thread evtl enger zusammenarbeiten