blob: fa8609dafca4b6e843942efccb29454aec3e735d [file] [log] [blame]
Brian Silverman5c0bf772013-02-28 16:44:44 -08001#ifndef AOS_COMMON_ZERO_SWITCH_VALUE_H_
2#define AOS_COMMON_ZERO_SWITCH_VALUE_H_
3
4#include "aos/common/type_traits.h"
5#include "aos/common/byteorder.h"
6
7namespace aos {
8
9// Contains all of the information from a zeroing sensor of some kind.
10// It is all contained here because it all has to be retrieved at the same time
11// or else there are race conditions with the sensor triggering and retrieving
12// the encoder values that would make writing code to deal with the information
13// hard (ie if the trigger sensor is read, then it changes->triggers the
14// interrupt which reads the encoder value).
15struct ZeroSwitchValue {
16 // What the curent encoder value is.
17 int32_t current_encoder;
18 // What the value of the encoder was when the interrupt triggered.
19 int32_t edge_encoder;
20 // What the current value of the sensor is.
21 bool current_value;
22
23 void NetworkToHost() {
24 current_encoder = ntoh(current_encoder);
25 edge_encoder = ntoh(edge_encoder);
26 }
27};
28static_assert(shm_ok<ZeroSwitchValue>::value, "it's getting sent over the wire");
29
30} // namespace aos
31
32#endif // AOS_COMMON_ZERO_SWITCH_VALUE_H_