diff --git a/pytec/pytec/client.py b/pytec/pytec/client.py index 5ac2095..159fd41 100644 --- a/pytec/pytec/client.py +++ b/pytec/pytec/client.py @@ -57,12 +57,14 @@ class Client: 'max_i_neg': {'max': 3.0, 'value': 3.0}, 'max_v': {'max': 5.988, 'value': 5.988}, 'max_i_pos': {'max': 3.0, 'value': 3.0}}, + 'polarity': 'normal', {'channel': 1, 'center': 'vref', 'i_set': {'max': 2.9802790335151985, 'value': -0.02002179650216762}, 'max_i_neg': {'max': 3.0, 'value': 3.0}, 'max_v': {'max': 5.988, 'value': 5.988}, 'max_i_pos': {'max': 3.0, 'value': 3.0}} + 'polarity': 'normal', ] """ return self._get_conf("pwm") diff --git a/src/channels.rs b/src/channels.rs index 94dc7b3..802c245 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -545,6 +545,7 @@ impl Channels { max_v: self.get_max_v(channel).into(), max_i_pos: self.get_max_i_pos(channel).into(), max_i_neg: self.get_max_i_neg(channel).into(), + polarity: PolarityJson(self.channel_state(channel).polarity.clone()), } } @@ -626,6 +627,21 @@ impl Serialize for CenterPointJson { } } +pub struct PolarityJson(Polarity); + +// used in JSON encoding, not for config +impl Serialize for PolarityJson { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_str(match self.0 { + Polarity::Normal => "normal", + Polarity::Reversed => "reversed", + }) + } +} + #[derive(Serialize)] pub struct PwmSummaryField { value: T, @@ -646,6 +662,7 @@ pub struct PwmSummary { max_v: PwmSummaryField, max_i_pos: PwmSummaryField, max_i_neg: PwmSummaryField, + polarity: PolarityJson, } #[derive(Serialize)]