Commit 0f089a5b authored by Richard Weiss's avatar Richard Weiss

Feat: add in LIFX tools

Adds in LIFX interface to the thermal tracker.
parent 0577c688
......@@ -20,6 +20,10 @@ WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
Adafruit_BME680 bme;
//OLED oled(4, 2, 15);
OLED oled(24, 22, 21);
void setup(void) {
Serial.begin(9600);
......@@ -36,10 +40,13 @@ void setup(void) {
setup_net();
timeClient.begin();
timeClient.update();
oled.begin();
}
void loop(void) {
static StaticJsonDocument<200> doc;
oled.drawLine(32, 32, 96, 96, RED);
if (!bme.performReading()) {
Serial.println("Failed to perform reading :(");
......
......@@ -86,6 +86,12 @@ dependencies = [
"rustc-demangle",
]
[[package]]
name = "base-x"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b20b618342cf9891c292c4f5ac2cde7287cc5c87e87e9c769d617793607dec1"
[[package]]
name = "base64"
version = "0.9.3"
......@@ -102,6 +108,12 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
[[package]]
name = "base64"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
[[package]]
name = "bit-set"
version = "0.5.2"
......@@ -185,6 +197,12 @@ dependencies = [
"safemem",
]
[[package]]
name = "bumpalo"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"
[[package]]
name = "byte-tools"
version = "0.3.1"
......@@ -223,7 +241,7 @@ checksum = "c74d84029116787153e02106bf53e66828452a4b325cc8652b788b5967c0a0b6"
dependencies = [
"num-integer",
"num-traits",
"time",
"time 0.1.43",
]
[[package]]
......@@ -232,6 +250,12 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "498d20a7aaf62625b9bf26e637cf7736417cde1d0c99f1d04d1170229a85cf87"
[[package]]
name = "chunked_transfer"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d29eb15132782371f71da8f947dba48b3717bdb6fa771b9b434d645e40a7193"
[[package]]
name = "cloudabi"
version = "0.0.3"
......@@ -247,6 +271,17 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
name = "cookie"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1373a16a4937bc34efec7b391f9c1500c30b8478a701a4f44c9165cc0475a6e0"
dependencies = [
"percent-encoding 2.1.0",
"time 0.2.16",
"version_check 0.9.2",
]
[[package]]
name = "crc32fast"
version = "1.2.0"
......@@ -309,6 +344,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "discard"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]]
name = "doc-comment"
version = "0.3.3"
......@@ -483,6 +524,17 @@ dependencies = [
"unicode-normalization",
]
[[package]]
name = "idna"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
dependencies = [
"matches",
"unicode-bidi",
"unicode-normalization",
]
[[package]]
name = "indexmap"
version = "1.5.1"
......@@ -517,6 +569,15 @@ version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]]
name = "js-sys"
version = "0.3.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85a7e2c92a4804dd459b86c339278d0fe87cf93757fae222c3fa3ae75458bc73"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "kstring"
version = "1.0.0"
......@@ -987,6 +1048,15 @@ dependencies = [
"prost",
]
[[package]]
name = "qstring"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d464fae65fff2680baf48019211ce37aaec0c78e9264c84a3e484717f965104e"
dependencies = [
"percent-encoding 2.1.0",
]
[[package]]
name = "quick-error"
version = "1.2.3"
......@@ -1234,6 +1304,21 @@ dependencies = [
"winapi",
]
[[package]]
name = "ring"
version = "0.16.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "952cd6b98c85bbc30efa1ba5783b8abf12fec8b3287ffa52605b9432313e34e4"
dependencies = [
"cc",
"libc",
"once_cell",
"spin",
"untrusted",
"web-sys",
"winapi",
]
[[package]]
name = "rmp"
version = "0.8.9"
......@@ -1275,9 +1360,9 @@ dependencies = [
"sha1",
"term",
"threadpool",
"time",
"time 0.1.43",
"tiny_http",
"url",
"url 1.7.2",
]
[[package]]
......@@ -1308,6 +1393,28 @@ version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
]
[[package]]
name = "rustls"
version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d1126dcf58e93cee7d098dbda643b5f92ed724f1f6a63007c1116eed6700c81"
dependencies = [
"base64 0.12.3",
"log 0.4.11",
"ring",
"sct",
"webpki",
]
[[package]]
name = "ryu"
version = "1.0.5"
......@@ -1320,6 +1427,31 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
[[package]]
name = "sct"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c"
dependencies = [
"ring",
"untrusted",
]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.114"
......@@ -1381,6 +1513,70 @@ version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f"
[[package]]
name = "spin"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "standback"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33a71ea1ea5f8747d1af1979bfb7e65c3a025a70609f04ceb78425bc5adad8e6"
dependencies = [
"version_check 0.9.2",
]
[[package]]
name = "stdweb"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5"
dependencies = [
"discard",
"rustc_version",
"stdweb-derive",
"stdweb-internal-macros",
"stdweb-internal-runtime",
"wasm-bindgen",
]
[[package]]
name = "stdweb-derive"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
dependencies = [
"proc-macro2",
"quote",
"serde",
"serde_derive",
"syn",
]
[[package]]
name = "stdweb-internal-macros"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11"
dependencies = [
"base-x",
"proc-macro2",
"quote",
"serde",
"serde_derive",
"serde_json",
"sha1",
"syn",
]
[[package]]
name = "stdweb-internal-runtime"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
[[package]]
name = "syn"
version = "1.0.38"
......@@ -1455,6 +1651,44 @@ dependencies = [
"winapi",
]
[[package]]
name = "time"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a51cadc5b1eec673a685ff7c33192ff7b7603d0b75446fb354939ee615acb15"
dependencies = [
"cfg-if",
"libc",
"standback",
"stdweb",
"time-macros",
"version_check 0.9.2",
"winapi",
]
[[package]]
name = "time-macros"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ae9b6e9f095bc105e183e3cd493d72579be3181ad4004fceb01adbe9eecab2d"
dependencies = [
"proc-macro-hack",
"time-macros-impl",
]
[[package]]
name = "time-macros-impl"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa"
dependencies = [
"proc-macro-hack",
"proc-macro2",
"quote",
"standback",
"syn",
]
[[package]]
name = "tiny_http"
version = "0.6.2"
......@@ -1463,9 +1697,9 @@ checksum = "1661fa0a44c95d01604bd05c66732a446c657efb62b5164a7a083a3b552b4951"
dependencies = [
"ascii",
"chrono",
"chunked_transfer",
"chunked_transfer 0.3.1",
"log 0.4.11",
"url",
"url 1.7.2",
]
[[package]]
......@@ -1608,17 +1842,51 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "untrusted"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]]
name = "ureq"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b770aa61edaa144d3af86a8b0ccbb1bf8ca9dd0c1ac2a17081f35943aae6eb82"
dependencies = [
"base64 0.12.3",
"chunked_transfer 1.2.0",
"cookie",
"lazy_static",
"qstring",
"rustls",
"url 2.1.1",
"webpki",
"webpki-roots",
]
[[package]]
name = "url"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a"
dependencies = [
"idna",
"idna 0.1.5",
"matches",
"percent-encoding 1.0.1",
]
[[package]]
name = "url"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb"
dependencies = [
"idna 0.2.0",
"matches",
"percent-encoding 2.1.0",
]
[[package]]
name = "version_check"
version = "0.1.5"
......@@ -1643,6 +1911,7 @@ dependencies = [
"serde",
"serde_json",
"tract-onnx",
"ureq",
]
[[package]]
......@@ -1651,6 +1920,89 @@ version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasm-bindgen"
version = "0.2.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0563a9a4b071746dd5aedbc3a28c6fe9be4586fb3fbadb67c400d4f53c6b16c"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc71e4c5efa60fb9e74160e89b93353bc24059999c0ae0fb03affc39770310b0"
dependencies = [
"bumpalo",
"lazy_static",
"log 0.4.11",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97c57cefa5fa80e2ba15641578b44d36e7a64279bc5ed43c6dbaf329457a2ed2"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "841a6d1c35c6f596ccea1f82504a192a60378f64b3bb0261904ad8f2f5657556"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93b162580e34310e5931c4b792560108b10fd14d64915d7fff8ff00180e70092"
[[package]]
name = "web-sys"
version = "0.3.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dda38f4e5ca63eda02c059d243aa25b5f35ab98451e518c51612cd0f1bd19a47"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "webpki"
version = "0.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab146130f5f790d45f82aeeb09e55a256573373ec64409fc19a6fb82fb1032ae"
dependencies = [
"ring",
"untrusted",
]
[[package]]
name = "webpki-roots"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f20dea7535251981a9670857150d571846545088359b28e4951d350bdaf179f"
dependencies = [
"webpki",
]
[[package]]
name = "which"
version = "3.1.1"
......
......@@ -17,4 +17,6 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rmp-serde = "0.14.4"
tract-onnx = "0.10.0"
\ No newline at end of file
tract-onnx = "0.10.0"
ureq = "1.4"
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
use std::fmt::{Formatter, Error};
/// The state machine exposes a counter of the number of people
/// that have incremented or decremented it. It also keeps track
/// of some stuff needed to work out which state it'll be in next.
#[derive(Debug, Copy, Clone)]
pub struct StateMachine {
pub counter: i32,
subcounter: i32,
last_state: i32,
}
impl std::fmt::Display for StateMachine {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
write!(f, "StateMachine({})", self.counter)
}
}
/// Action represet the actions taken by the state machine. This is mostly
/// useful for translating state machine transitions into actions that affect
/// the outside world.
pub enum Action {
Noop,
Inc,
Dec
}
impl StateMachine {
pub fn new() -> Self {
StateMachine {
counter: 0,
subcounter: 0,
last_state: 0
}
}
pub fn act(&self, readout: i32) -> (Self, Action) {
let subcount = if readout != self.last_state {
0
} else {
self.subcounter + 1
};
let mut new_state = StateMachine {
counter: self.counter,
subcounter: subcount,
last_state: readout,
};
let last = self.last_state;
let action = match (last, readout) {
(0, 0) => Action::Noop,
(0, 1) if self.subcounter > 5 => {new_state.counter += 1; Action::Inc},
(0, 1) => Action::Noop,
(0, 2) if self.subcounter > 5 => {new_state.counter -= 1; Action::Dec},
(0, 2) => Action::Noop,
(2, 0) => Action::Noop,
(2, 1) => Action::Noop,
(2, 2) => Action::Noop,
(1, 0) => Action::Noop,
(1, 1) => Action::Noop,
(1, 2) => Action::Noop,
(_, _) => unreachable!(),
};
(new_state, action)
}
}
pub struct LifxInfo {
group_id: String,
header: String
}
impl LifxInfo {
/// Read out the LifxInfo from a text file. It should have
/// exactly two lines, the first is the group id for the
/// lights we want to turn on and off, and the second is
/// a LIFX auth token.
///
/// For example:
///
/// Bearer c6...
/// 4d0a...
/// EOF
pub fn new() -> LifxInfo {
let info = include_str!("../lifx_info.txt");
let lines: Vec<&str> = info.split("\n").collect();
return LifxInfo {
group_id: lines[1].to_owned(),
header: lines[0].to_owned()
}
}
/// Turn on lights
pub fn lights_on(&self) {
let auth = self.header.clone();
let url = format!("https://api.lifx.com/v1/lights/group_id:{}/state", self.group_id);
let req = ureq::put(&url).set(
"Authorization",&auth).send_form(&[("power", "on")]);
println!("{:?}", req);
}