mirror of
https://github.com/FliegendeWurst/raspi-oled.git
synced 2024-11-24 11:14:58 +00:00
Compare commits
No commits in common. "c17424a686fe2dc4f8928052c68deda57794a44d" and "b228e552de1bc61d8097459a73a35b7409d76988" have entirely different histories.
c17424a686
...
b228e552de
761
Cargo.lock
generated
761
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -23,7 +23,6 @@ rppal = { version = "0.13.1", features = ["hal"] }
|
|||||||
ssd1351 = { git = "https://github.com/FliegendeWurst/ssd1351-rust" }
|
ssd1351 = { git = "https://github.com/FliegendeWurst/ssd1351-rust" }
|
||||||
display-interface-spi = "0.4.1"
|
display-interface-spi = "0.4.1"
|
||||||
ureq = { version = "2.4.0", default-features = false }
|
ureq = { version = "2.4.0", default-features = false }
|
||||||
#gpio-am2302-rs = { git = "https://github.com/FliegendeWurst/gpio-am2302-rs" }
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
@ -31,10 +31,6 @@ fn main() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
while temps.len() < 5 && attempts < 10 {
|
while temps.len() < 5 && attempts < 10 {
|
||||||
if let Ok((rh, temp)) = raspi_oled::am2302_reading(&line) {
|
if let Ok((rh, temp)) = raspi_oled::am2302_reading(&line) {
|
||||||
// TODO: try out gpio_am2302_rs!
|
|
||||||
//if let Ok(reading) = gpio_am2302_rs::try_read(26) {
|
|
||||||
//let rh = reading.humidity as i64;
|
|
||||||
//let temp = (reading.temperature * 10.0) as i64;
|
|
||||||
if rh > 0 && temp < 500 {
|
if rh > 0 && temp < 500 {
|
||||||
rhs.push(rh);
|
rhs.push(rh);
|
||||||
temps.push(temp);
|
temps.push(temp);
|
||||||
@ -47,13 +43,10 @@ fn main() {
|
|||||||
// median = hopefully no faulty readings
|
// median = hopefully no faulty readings
|
||||||
temps.sort();
|
temps.sort();
|
||||||
rhs.sort();
|
rhs.sort();
|
||||||
let rh = rhs[rhs.len() / 2];
|
|
||||||
let temp = temps[temps.len() / 2];
|
|
||||||
println!("info: acquired {} readings (temps {:?}, rhs {:?}), using rh {} and temp {}", temps.len(), temps, rhs, rh, temp);
|
|
||||||
database
|
database
|
||||||
.execute(
|
.execute(
|
||||||
"INSERT INTO sensor_readings (time, humidity, celsius) VALUES (?1, ?2, ?3)",
|
"INSERT INTO sensor_readings (time, humidity, celsius) VALUES (?1, ?2, ?3)",
|
||||||
params![time.as_secs(), rh, temp],
|
params![time.as_secs(), rhs[rhs.len() / 2], temps[temps.len() / 2]],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
10
src/lib.rs
10
src/lib.rs
@ -76,7 +76,6 @@ fn read_events(line: &gpio_cdev::Line, timeout: std::time::Duration) -> Result<V
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if events.len() < 81 {
|
if events.len() < 81 {
|
||||||
println!("error: only got {} events", events.len());
|
|
||||||
return Err(SensorError::Timeout);
|
return Err(SensorError::Timeout);
|
||||||
}
|
}
|
||||||
Ok(events)
|
Ok(events)
|
||||||
@ -163,14 +162,15 @@ impl From<gpio_cdev::Error> for SensorError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn am2302_reading(line: &Line) -> Result<(u16, u16), SensorError> {
|
pub fn am2302_reading(line: &Line) -> Result<(u16, u16), SensorError> {
|
||||||
let out = line.request(LineRequestFlags::OUTPUT, 1, "rust-am2302").unwrap();
|
line.request(LineRequestFlags::OUTPUT, 1, "rust-am2302").unwrap();
|
||||||
out.set_value(1)?;
|
|
||||||
sleep(Duration::from_millis(500));
|
sleep(Duration::from_millis(500));
|
||||||
set_max_priority();
|
set_max_priority();
|
||||||
// set low for 20 ms
|
// set low for 20 ms
|
||||||
out.set_value(0)?;
|
if let Err(e) = line.request(LineRequestFlags::OUTPUT, 0, "rust-am2302") {
|
||||||
|
set_normal_priority();
|
||||||
|
return Err(SensorError::Io(e));
|
||||||
|
}
|
||||||
sleep(Duration::from_millis(3));
|
sleep(Duration::from_millis(3));
|
||||||
drop(out);
|
|
||||||
|
|
||||||
let events = read_events(&line, Duration::from_secs(1));
|
let events = read_events(&line, Duration::from_secs(1));
|
||||||
println!("{:?} {:?}", events, events.as_ref().map(|x| x.len()));
|
println!("{:?} {:?}", events, events.as_ref().map(|x| x.len()));
|
||||||
|
Loading…
Reference in New Issue
Block a user