diff options
author | joeycastillo <joeycastillo@utexas.edu> | 2022-11-22 08:43:12 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-22 08:43:12 -0600 |
commit | a209178ac046ae53f66b9dc723e160031747444c (patch) | |
tree | 4de4fe6deb39bad73e26de775b74922569522f60 | |
parent | 8dbc00c56d8e2cc6618031d0c2a023d07a637cd3 (diff) | |
parent | 3377b489c7a34d798321c8be2e32974145eb9c81 (diff) | |
download | Sensor-Watch-a209178ac046ae53f66b9dc723e160031747444c.tar.gz Sensor-Watch-a209178ac046ae53f66b9dc723e160031747444c.tar.bz2 Sensor-Watch-a209178ac046ae53f66b9dc723e160031747444c.zip |
Merge pull request #141 from TomHodson/fix_simulated_led_color
Add support for bicolor led in the simulator
-rw-r--r-- | watch-library/simulator/shell.html | 10 | ||||
-rw-r--r-- | watch-library/simulator/watch/watch_led.c | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/watch-library/simulator/shell.html b/watch-library/simulator/shell.html index 80e1e2ea..7b38a9aa 100644 --- a/watch-library/simulator/shell.html +++ b/watch-library/simulator/shell.html @@ -51,6 +51,14 @@ <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"> diff --git a/watch-library/simulator/watch/watch_led.c b/watch-library/simulator/watch/watch_led.c index 068da8bd..636dc74f 100644 --- a/watch-library/simulator/watch/watch_led.c +++ b/watch-library/simulator/watch/watch_led.c @@ -32,7 +32,15 @@ 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; + 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); } |