]> git.earman.xyz Git - sensor-watch.git/commitdiff
add temp input to simulator
authorRobert Masen <robert.masen@smartthings.com>
Fri, 2 Aug 2024 23:20:44 +0000 (18:20 -0500)
committerRobert Masen <robert.masen@smartthings.com>
Fri, 2 Aug 2024 23:20:44 +0000 (18:20 -0500)
watch-library/shared/driver/thermistor_driver.c
watch-library/simulator/shell.html

index 73bdef410bbebed2f3150c5df3f5edcea23f5848..8ce5934544d1b5f3c2d35ba0537a07eb8769576d 100644 (file)
@@ -45,7 +45,15 @@ void thermistor_driver_disable(void) {
     // Disable the enable pin's output circuitry.
     watch_disable_digital_output(THERMISTOR_ENABLE_PIN);
 }
-
+#if __EMSCRIPTEN__
+#include <emscripten.h>
+float thermistor_driver_get_temperature(void)
+{
+    return EM_ASM_DOUBLE({
+        return temp_c || 25.0;
+    });
+}
+#else
 float thermistor_driver_get_temperature(void) {
     // set the enable pin to the level that powers the thermistor circuit.
     watch_set_pin_level(THERMISTOR_ENABLE_PIN, THERMISTOR_ENABLE_VALUE);
@@ -56,3 +64,4 @@ float thermistor_driver_get_temperature(void) {
 
     return watch_utility_thermistor_temperature(value, THERMISTOR_HIGH_SIDE, THERMISTOR_B_COEFFICIENT, THERMISTOR_NOMINAL_TEMPERATURE, THERMISTOR_NOMINAL_RESISTANCE, THERMISTOR_SERIES_RESISTANCE);
 }
+#endif
index 29fbed038b36e7eeb39bc840776856c406c1cb73..9cdb29028dfde900b61f0be2fcf3c249b2b8196d 100644 (file)
     <div>
       <button onclick="getLocation()">Set register (will prompt for access)</button>
     </div>
+    <h2>Temp.</h2>
+    <div>
+      <input type="number" min="-100" max="120" id="temp-c" />C
+      <button onclick="setTemp()">Set</button>
+    </div>
   </div>
 
   <form onSubmit="sendText(); return false" style="display: flex; flex-direction: column; width: 100%">
   lat = 0;
   lon = 0;
   tx = "";
+  temp_c = 25.0;
   function updateLocation(location) {
     lat = Math.round(location.coords.latitude * 100);
     lon = Math.round(location.coords.longitude * 100);
     document.getElementById(skin).checked = true;
     setSkin(skin);
   }
+
+  function setTemp() {
+    let tempInput = document.getElementById("temp-c");
+    if (!tempInput) {
+      return console.warn("no input found");
+    }
+    if (tempInput.value == "") {
+      return console.warn("no value in input");
+    }
+    
+    try {
+      temp_c = Number.parseFloat(tempInput.value);
+    } catch (e) {
+      return console.warn("input value is not a valid float:", tempInput.value,  e);
+    }
+  }
   loadPrefs();
 </script>
 {{{ SCRIPT }}}
 
 </body>
 </html>
-