Calculate total energy and print it, also in JSON format
This commit is contained in:
parent
3373984f86
commit
c0f57afff4
33
src/main.rs
33
src/main.rs
|
@ -221,6 +221,7 @@ fn main() -> ! {
|
||||||
|
|
||||||
// track nano_joules (== nanoVoltAmpereSeconds) generated, for LED flashing
|
// track nano_joules (== nanoVoltAmpereSeconds) generated, for LED flashing
|
||||||
let mut nano_joules: u32 = 0;
|
let mut nano_joules: u32 = 0;
|
||||||
|
let mut joules: u32 = 0; // total energy generated
|
||||||
let mut loopcnt_led_y_off = 0;
|
let mut loopcnt_led_y_off = 0;
|
||||||
|
|
||||||
let mut loopcnt: u64 = 0;
|
let mut loopcnt: u64 = 0;
|
||||||
|
@ -292,6 +293,7 @@ fn main() -> ! {
|
||||||
pin_led_y.set_high().unwrap();
|
pin_led_y.set_high().unwrap();
|
||||||
loopcnt_led_y_off = loopcnt + 10;
|
loopcnt_led_y_off = loopcnt + 10;
|
||||||
nano_joules -= 1000000000;
|
nano_joules -= 1000000000;
|
||||||
|
joules += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if loopcnt == loopcnt_led_y_off {
|
if loopcnt == loopcnt_led_y_off {
|
||||||
|
@ -322,8 +324,14 @@ fn main() -> ! {
|
||||||
logger.log(b"mA - Pout: ").unwrap();
|
logger.log(b"mA - Pout: ").unwrap();
|
||||||
data = String::from(vout * iout / 1000);
|
data = String::from(vout * iout / 1000);
|
||||||
logger.log(data.as_bytes()).unwrap();
|
logger.log(data.as_bytes()).unwrap();
|
||||||
|
logger.log(b"mW - E: ").unwrap();
|
||||||
|
data = String::from(joules);
|
||||||
|
logger.log(data.as_bytes()).unwrap();
|
||||||
|
logger.log(b"J / ").unwrap();
|
||||||
|
data = String::from(joules/3600);
|
||||||
|
logger.log(data.as_bytes()).unwrap();
|
||||||
|
|
||||||
logger.log(b"mW - raw: [").unwrap();
|
logger.log(b"Wh - raw: [").unwrap();
|
||||||
|
|
||||||
for i in 0..adc_value.len() {
|
for i in 0..adc_value.len() {
|
||||||
data = String::from(adc_value[i]);
|
data = String::from(adc_value[i]);
|
||||||
|
@ -341,6 +349,29 @@ fn main() -> ! {
|
||||||
logger.log(b"\r\n").unwrap();
|
logger.log(b"\r\n").unwrap();
|
||||||
},
|
},
|
||||||
2 => {
|
2 => {
|
||||||
|
let mut data: String<16>;
|
||||||
|
|
||||||
|
logger.log(b"{\"vin\":").unwrap();
|
||||||
|
data = String::from(vin);
|
||||||
|
logger.log(data.as_bytes()).unwrap();
|
||||||
|
logger.log(b",\"vout\":").unwrap();
|
||||||
|
data = String::from(vout);
|
||||||
|
logger.log(data.as_bytes()).unwrap();
|
||||||
|
logger.log(b",\"iout\":").unwrap();
|
||||||
|
data = String::from(iout);
|
||||||
|
logger.log(data.as_bytes()).unwrap();
|
||||||
|
logger.log(b",\"pout\":").unwrap();
|
||||||
|
data = String::from(vout * iout);
|
||||||
|
logger.log(data.as_bytes()).unwrap();
|
||||||
|
logger.log(b",\"energy\":").unwrap();
|
||||||
|
data = String::from(joules);
|
||||||
|
logger.log(data.as_bytes()).unwrap();
|
||||||
|
logger.log(b",\"pwm\"").unwrap();
|
||||||
|
data = String::from(pwmval);
|
||||||
|
logger.log(data.as_bytes()).unwrap();
|
||||||
|
logger.log(b"}\r\n").unwrap();
|
||||||
|
},
|
||||||
|
3 => {
|
||||||
switchctrl.log_status(&mut logger);
|
switchctrl.log_status(&mut logger);
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
Loading…
Reference in a new issue