mirror of
https://github.com/italicsjenga/mppt-modbus.git
synced 2024-12-23 16:51:30 +11:00
stinko
This commit is contained in:
parent
1a8bf2e57c
commit
1eea528d5d
31
src/main.rs
31
src/main.rs
|
@ -118,6 +118,7 @@ struct MpptEeprom {
|
||||||
|
|
||||||
trait Scaled {
|
trait Scaled {
|
||||||
fn get_scaled(&self, info: &Info) -> f32;
|
fn get_scaled(&self, info: &Info) -> f32;
|
||||||
|
fn new(input: f32, info: &Info) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
@ -129,12 +130,10 @@ impl Scaled for Tempcomp {
|
||||||
fn get_scaled(&self, info: &Info) -> f32 {
|
fn get_scaled(&self, info: &Info) -> f32 {
|
||||||
self.data as f32 * info.v_scale * f32::powf(2., -16.)
|
self.data as f32 * info.v_scale * f32::powf(2., -16.)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Tempcomp {
|
fn new(input: f32, info: &Info) -> Self {
|
||||||
pub fn new(voltage: f32, info: &Info) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
data: ((voltage / f32::powf(2., -16.)) / info.v_scale) as u16,
|
data: ((input / f32::powf(2., -16.)) / info.v_scale) as u16,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,12 +147,10 @@ impl Scaled for Voltage {
|
||||||
fn get_scaled(&self, info: &Info) -> f32 {
|
fn get_scaled(&self, info: &Info) -> f32 {
|
||||||
self.data as f32 * info.v_scale * f32::powf(2., -15.)
|
self.data as f32 * info.v_scale * f32::powf(2., -15.)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Voltage {
|
fn new(input: f32, info: &Info) -> Self {
|
||||||
fn new(voltage: f32, info: &Info) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
data: ((voltage / f32::powf(2., -15.)) / info.v_scale) as u16,
|
data: ((input / f32::powf(2., -15.)) / info.v_scale) as u16,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,12 +164,10 @@ impl Scaled for VoltagePercentage {
|
||||||
fn get_scaled(&self, info: &Info) -> f32 {
|
fn get_scaled(&self, info: &Info) -> f32 {
|
||||||
self.data as f32 * 100. * f32::powf(2., -16.)
|
self.data as f32 * 100. * f32::powf(2., -16.)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl VoltagePercentage {
|
fn new(input: f32, info: &Info) -> Self {
|
||||||
fn new(voltage: f32, info: &Info) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
data: ((voltage / f32::powf(2., -16.)) / 100.) as u16,
|
data: ((input / f32::powf(2., -16.)) / 100.) as u16,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,12 +181,10 @@ impl Scaled for Current {
|
||||||
fn get_scaled(&self, info: &Info) -> f32 {
|
fn get_scaled(&self, info: &Info) -> f32 {
|
||||||
self.data as f32 * info.i_scale * f32::powf(2., -15.)
|
self.data as f32 * info.i_scale * f32::powf(2., -15.)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Current {
|
fn new(input: f32, info: &Info) -> Self {
|
||||||
fn new(current: f32, info: &Info) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
data: ((current / f32::powf(2., -15.)) / info.i_scale) as u16,
|
data: ((input / f32::powf(2., -15.)) / info.i_scale) as u16,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,11 +198,9 @@ impl Scaled for Raw {
|
||||||
fn get_scaled(&self, info: &Info) -> f32 {
|
fn get_scaled(&self, info: &Info) -> f32 {
|
||||||
self.data as f32
|
self.data as f32
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Raw {
|
fn new(input: f32, info: &Info) -> Self {
|
||||||
fn new(input: u16, info: &Info) -> Self {
|
Self { data: input as u16 }
|
||||||
Self { data: input }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue