Skip to content

Commit

Permalink
Support 16 bit lock times
Browse files Browse the repository at this point in the history
  • Loading branch information
jpieper committed Jun 5, 2021
1 parent 08034e9 commit 6ba82ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ Zero if the switch is current turned off, non-zero otherwise.
Mode: Read/write

Power will be maintained for this long after the switch has been
turned off.
turned off. The maximum value is 3276.7s, all register scalings
report in units of 100ms (thus int8 will not be able to command or
monitor the full possible scale).

### 0x004 - Boot time ###

Expand Down
10 changes: 5 additions & 5 deletions fw/power_dist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ Value ScaleVoltage(float value, size_t type) {
return ScaleMapping(value, 0.5f, 0.1f, 0.001f, type);
}

int8_t ReadIntMapping(Value value) {
int16_t ReadInt16Mapping(Value value) {
return std::visit([](auto a) {
return static_cast<int8_t>(a);
return static_cast<int16_t>(a);
}, value);
}

Expand Down Expand Up @@ -514,7 +514,7 @@ class PowerDist : public mjlib::multiplex::MicroServer::Server {
return 2;
}
case Register::kLockTime: {
status_.lock_time_100ms = ReadIntMapping(value);
status_.lock_time_100ms = ReadInt16Mapping(value);
return 0;
}
case Register::kFaultCode:
Expand Down Expand Up @@ -547,10 +547,10 @@ class PowerDist : public mjlib::multiplex::MicroServer::Server {
return IntMapping(static_cast<int8_t>(status_.switch_status), type);
}
case Register::kLockTime: {
return IntMapping(static_cast<int8_t>(status_.lock_time_100ms), type);
return IntMapping(static_cast<int16_t>(status_.lock_time_100ms), type);
}
case Register::kBootTime: {
return IntMapping(static_cast<int8_t>(0), type);
return IntMapping(static_cast<int16_t>(0), type);
}
case Register::kOutputVoltage: {
return ScaleVoltage(status_.output_voltage_V, type);
Expand Down

0 comments on commit 6ba82ed

Please sign in to comment.