From 8ee13aa2a3ae77395abca0d99176841c8dcf2570 Mon Sep 17 00:00:00 2001 From: CircleShift Date: Sat, 21 Jun 2025 21:41:44 -0400 Subject: Thermostat temperature overhaul --- scripts/gui-common/temperature.js | 90 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 scripts/gui-common/temperature.js (limited to 'scripts/gui-common/temperature.js') diff --git a/scripts/gui-common/temperature.js b/scripts/gui-common/temperature.js new file mode 100644 index 0000000..ba8161a --- /dev/null +++ b/scripts/gui-common/temperature.js @@ -0,0 +1,90 @@ +'use strict'; + +class Temperature { + + /// Temperature in kelvin + #temp = 0; + + /** + * Constructor + * @param {number} k Temperature in kelvin + */ + constructor(k) { + this.#temp = k; + } + + /** + * Create a new temperature object using celcius + * @param {number} c + * @returns {Temperature} + */ + static from_celcius(c) { + return new Temperature(c + 273.15); + } + + /** + * Get the temperature in celcius + * @returns {number} + */ + to_celcius() { + return this.#temp - 273.15; + } + + /** + * Create a new temperature object using fahrenheit + * @param {number} f + * @returns {Temperature} + */ + static from_fahrenheit(f) { + return new Temperature((f + 459.67) * 5 / 9); + } + + /** + * Get the temperature in fahrenheit + * @returns {number} + */ + to_fahrenheit() { + return (this.#temp * 9 / 5) - 459.67; + } + + /** + * From degrees halc + * @param {number} h + * @returns {Temperature} + */ + static from_halc(h) { + return Temperature.from_celcius(h / 2); + } + + /** + * To degrees halc + * @returns {number} + */ + to_halc() { + return this.to_celcius() * 2; + } + + /** + * Get the temperature in kelvin + * @returns {number} + */ + to_kelvin() { + return this.#temp; + } + + /** + * Add the temperature to the current temperature + * @param {Temperature} t + */ + add(t) { + this.#temp += t.#temp; + } + + /** + * Subtract the temperature from the current temperature + * @param {Temperature} t + */ + sub(t) { + this.#temp -= t.#temp; + } +} \ No newline at end of file -- cgit v1.2.3