-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMCU_analog_readings.h
41 lines (32 loc) · 1.67 KB
/
MCU_analog_readings.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#pragma once
#include <string.h>
#include <stdint.h>
#pragma pack(push,1)
// @Parseclass
class MCU_analog_readings {
public:
MCU_analog_readings() = default;
MCU_analog_readings(const uint8_t buf[8]) { load(buf); }
inline void load(const uint8_t buf[]) { memcpy(this, buf, sizeof(*this)); }
inline void write(uint8_t buf[]) const { memcpy(buf, this, sizeof(*this)); }
// Getters
inline uint16_t get_steering_1() const { return steering_1; }
inline uint16_t get_steering_2() const { return steering_2; }
inline int16_t get_hall_effect_current() const { return hall_effect_current; }
inline uint16_t get_glv_battery_voltage() const { return glv_battery_voltage; }
// Setters
inline void set_steering_1(const int16_t steering_1) { this->steering_1 = steering_1; }
inline void set_steering_2(const uint16_t steering_2) { this->steering_2 = steering_2; }
inline void set_hall_effect_current(const int16_t hall_effect_current) { this->hall_effect_current = hall_effect_current; }
inline void set_glv_battery_voltage(const uint16_t glv_battery_voltage) { this->glv_battery_voltage = glv_battery_voltage; }
private:
// @Parse @Unit(A) @Scale(5000)
int16_t steering_1; // signed int, >0 is turning right, <0 is turning left, (2^14)/2 is +180 degrees out of digital sensor
// @Parse @Unit(A) @Scale(5000)
uint16_t steering_2; // unsigned int, 0-5V out of analog steering wheel sensor
// @Parse @Unit(C) @Scale(100)
int16_t hall_effect_current;
// @Parse @Unit(V) @Scale(2500)
uint16_t glv_battery_voltage;
};
#pragma pack(pop)