]> git.earman.xyz Git - sensor-watch.git/commitdiff
WIP: Add support for bicolor led in the simulator
authorTom Hodson <thomas.c.hodson@gmail.com>
Tue, 22 Nov 2022 13:30:24 +0000 (14:30 +0100)
committerTom Hodson <thomas.c.hodson@gmail.com>
Tue, 22 Nov 2022 13:30:24 +0000 (14:30 +0100)
I noticed that the bicolor led isn't supported in the simulator. Here is a quick mockup of how I would add support for it.

I added an SVG filter to the #light rectangle in the SVG which lets us multiply the colours by a matrix in code. I then insert values so that the original green colour gets mixed into the combination of red and green requested by `watch_set_led_color`

# Testing
So far I've only tested this with the standard firmware build but it seems to work.

# Possible issues
I wasn't 100% sure what to do when red + green > 255, current behaviour is that it gets clamped to 255 in the simulator.

watch-library/simulator/shell.html
watch-library/simulator/watch/watch_led.c

index 80e1e2eac05ec8606a33adf62ab43184f725bd73..7b38a9aa879ba2065906912655644ad8dfd88723 100644 (file)
         <stop offset="0.94" stop-color="#000d00" stop-opacity="0.05"/>
         <stop offset="1" stop-opacity="0"/>
       </radialGradient>
+      <filter id="ledcolor">
+        <feColorMatrix in="SourceGraphic" type="matrix"
+                       values=" 0      0      0      0 0
+                                0      1      0      0 0 
+                                0      0      0      0 0 
+                                0      0      0      1 0  "/>
+     
+      </filter>
     </defs>
     <g id="Calque">
       <g id="Contours">
@@ -71,7 +79,7 @@
           <rect x="293.5" y="520" width="683" height="334" rx="34.68" style="fill: #777b7a"/>
         </g>
         <g id="light" style="opacity: 0">
-          <rect x="293.5" y="520" width="683" height="334" rx="34.68" style="fill: url(#Dégradé_sans_nom_3)"/>
+          <rect x="293.5" y="520" width="683" height="334" rx="34.68" style="fill: url(#Dégradé_sans_nom_3)" filter="url(#ledcolor)"/>
         </g>
       </g>
       <g id="Textes">
index 068da8bd305c9d9c72b06e2984e8a0b1e897d1c9..249be056f5b480e85099725de04a88105dcd4b22 100644 (file)
@@ -32,7 +32,16 @@ void watch_disable_leds(void) {}
 
 void watch_set_led_color(uint8_t red, uint8_t green) {
     EM_ASM({
-        document.getElementById('light').style.opacity = $1 / 255;
+        // the watch svg contains an feColorMatrix filter with id ledcolor
+        // and a green svg gradient that mimics the led being on
+        // https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feColorMatrix
+        // this changes the color of the gradient to match the red+green combination
+        let filter = document.getElementById("ledcolor");
+        let color_matrix = filter.children[0].values.baseVal;
+        console.log($0, $1);
+        color_matrix[1].value = $0  / 255; // red value
+        color_matrix[6].value = $1 / 255; // green value
+        document.getElementById('light').style.opacity = Math.min(255, $0 + $1) / 255;
     }, red, green);
 }