mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Use a proper enum for TPMS signal type.
This commit is contained in:
parent
9a41961aeb
commit
5e6a76dfe7
@ -30,6 +30,8 @@ using namespace portapack;
|
||||
|
||||
#include "crc.hpp"
|
||||
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace tpms {
|
||||
|
||||
Timestamp Packet::received_at() const {
|
||||
@ -44,9 +46,9 @@ Optional<Reading> Packet::reading() const {
|
||||
const auto length = crc_valid_length();
|
||||
|
||||
switch(length) {
|
||||
case 64: return Reading { 64, reader_.read(0, 32), reader_.read(32, 8) };
|
||||
case 72: return Reading { 72, reader_.read(0, 32), reader_.read(40, 8), reader_.read(48, 8), reader_.read(56, 8) };
|
||||
case 80: return Reading { 80, reader_.read(8, 32), reader_.read(48, 8), reader_.read(56, 8), reader_.read(64, 8) };
|
||||
case 64: return Reading { Reading::Type::FLM_64, reader_.read(0, 32), reader_.read(32, 8) };
|
||||
case 72: return Reading { Reading::Type::FLM_72, reader_.read(0, 32), reader_.read(40, 8), reader_.read(48, 8), reader_.read(56, 8) };
|
||||
case 80: return Reading { Reading::Type::FLM_80, reader_.read(8, 32), reader_.read(48, 8), reader_.read(56, 8), reader_.read(64, 8) };
|
||||
default: return { };
|
||||
}
|
||||
}
|
||||
@ -147,7 +149,7 @@ void TPMSAppView::draw(const tpms::Packet& packet) {
|
||||
const auto reading_opt = packet.reading();
|
||||
if( reading_opt.is_valid() ) {
|
||||
const auto reading = reading_opt.value();
|
||||
auto s = to_string_dec_uint(reading.type(), 2) + " " + to_string_hex(reading.id(), 8);
|
||||
auto s = to_string_dec_uint(toUType(reading.type()), 2) + " " + to_string_hex(reading.id(), 8);
|
||||
s += " " + to_string_hex(reading.value_1(), 2);
|
||||
if( reading.value_2().is_valid() ) {
|
||||
s += " " + to_string_hex(reading.value_2().value(), 2);
|
||||
|
@ -48,8 +48,15 @@ private:
|
||||
|
||||
class Reading {
|
||||
public:
|
||||
enum Type {
|
||||
None = 0,
|
||||
FLM_64 = 1,
|
||||
FLM_72 = 2,
|
||||
FLM_80 = 3,
|
||||
};
|
||||
|
||||
constexpr Reading(
|
||||
) : type_ { 0 },
|
||||
) : type_ { Type::None },
|
||||
id_ { 0 },
|
||||
value_1_ { 0 },
|
||||
value_2_ { 0 },
|
||||
@ -58,7 +65,7 @@ public:
|
||||
}
|
||||
|
||||
constexpr Reading(
|
||||
uint32_t type,
|
||||
Type type,
|
||||
uint32_t id,
|
||||
uint16_t value_1
|
||||
) : type_ { type },
|
||||
@ -70,7 +77,7 @@ public:
|
||||
}
|
||||
|
||||
constexpr Reading(
|
||||
uint32_t type,
|
||||
Type type,
|
||||
uint32_t id,
|
||||
uint16_t value_1,
|
||||
uint16_t value_2,
|
||||
@ -83,7 +90,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t type() const {
|
||||
Type type() const {
|
||||
return type_;
|
||||
}
|
||||
|
||||
@ -104,7 +111,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t type_;
|
||||
Type type_;
|
||||
uint32_t id_;
|
||||
uint16_t value_1_;
|
||||
Optional<uint16_t> value_2_;
|
||||
|
Loading…
Reference in New Issue
Block a user