amiro-os / include / amiro / BaseSensor.hpp @ 81b48c66
History | View | Annotate | Download (2.784 KB)
1 | 58fe0e0b | Thomas Schöpping | #ifndef AMIRO_BASE_SENSOR_H_
|
---|---|---|---|
2 | #define AMIRO_BASE_SENSOR_H_
|
||
3 | |||
4 | /* ABOUT THE USED PREPROCESSOR DIRECTIVES IN THIS FILE
|
||
5 | * AMIRO_NCALIBRATION:
|
||
6 | * If defined, the calibration() function will be ignored for compilation.
|
||
7 | * Thus, all inheriting classes must use this directive, too.
|
||
8 | * AMIRO_NSELFTEST:
|
||
9 | * If defined, the selftest() function will be ignored for compilation.
|
||
10 | * Thus, all inheriting classes must use this directive, too.
|
||
11 | */
|
||
12 | |||
13 | namespace amiro {
|
||
14 | |||
15 | /**
|
||
16 | * This is an interface class, which should be used as a blueprint for all drivers of the AMiRo.
|
||
17 | */
|
||
18 | template<typename Init_t = void, typename Calib_t = void> |
||
19 | class BaseSensor |
||
20 | { |
||
21 | public:
|
||
22 | BaseSensor() {} |
||
23 | virtual ~BaseSensor() {}
|
||
24 | |||
25 | /**
|
||
26 | * Some error codes that should be returned by the implementations of the virtual functions of this class.
|
||
27 | */
|
||
28 | enum ErrorCodes {
|
||
29 | SUCCESS = 0x00u, OK = 0x00u, |
||
30 | ERROR = 0x80u, FAIL = 0x80u, |
||
31 | NOT_IMPLEMENTED = 0xFFu
|
||
32 | }; |
||
33 | |||
34 | /**
|
||
35 | * Initializes the hardware (e.g. sets register values).
|
||
36 | * This function is optional.
|
||
37 | *
|
||
38 | * @param[in,out] driver specific initialization data (should be used for arguments and results); optional
|
||
39 | * @return an error code
|
||
40 | */
|
||
41 | virtual inline msg_t init(Init_t* = NULL) |
||
42 | { |
||
43 | return NOT_IMPLEMENTED;
|
||
44 | } |
||
45 | |||
46 | /**
|
||
47 | * Reads the most important values from the hardware and stores them in local buffers.
|
||
48 | *
|
||
49 | * @return an error code
|
||
50 | */
|
||
51 | virtual msg_t update() = 0; |
||
52 | |||
53 | /**
|
||
54 | * If required, wakes the hardware from power saving mode into an active state.
|
||
55 | * (Re)Initializes all local buffers with valid values, thus the update() function should be called.
|
||
56 | *
|
||
57 | * @return an error code
|
||
58 | */
|
||
59 | virtual msg_t wakeup() = 0; |
||
60 | |||
61 | /**
|
||
62 | * Puts the hardware in a power saving mode to reduce energy consumption.
|
||
63 | * This function is optional.
|
||
64 | * @return an error code
|
||
65 | */
|
||
66 | virtual msg_t hibernate()
|
||
67 | { |
||
68 | return NOT_IMPLEMENTED;
|
||
69 | } |
||
70 | |||
71 | #ifndef AMIRO_NCALIBRATION
|
||
72 | /**
|
||
73 | * Runs a calibration of the hardware.
|
||
74 | * This function is optional.
|
||
75 | *
|
||
76 | * @param[in,out] driver specific calibration data (should be used for arguments and results); optional
|
||
77 | *
|
||
78 | * @return an error code
|
||
79 | */
|
||
80 | virtual msg_t calibration(Calib_t* = NULL) |
||
81 | { |
||
82 | return NOT_IMPLEMENTED;
|
||
83 | } |
||
84 | #else
|
||
85 | static uint8_t calibration(Calib_t* = NULL) |
||
86 | { |
||
87 | return NOT_IMPLEMENTED;
|
||
88 | } |
||
89 | #endif
|
||
90 | |||
91 | #ifndef AMIRO_NSELFTEST
|
||
92 | /**
|
||
93 | * Runs a self-test on the hardware and/or communication.
|
||
94 | * This function is optional but highly recommended.
|
||
95 | *
|
||
96 | * @return an error code
|
||
97 | */
|
||
98 | virtual msg_t selftest()
|
||
99 | { |
||
100 | return NOT_IMPLEMENTED;
|
||
101 | } |
||
102 | #else
|
||
103 | static msg_t selftest()
|
||
104 | { |
||
105 | return NOT_IMPLEMENTED;
|
||
106 | } |
||
107 | #endif
|
||
108 | |||
109 | }; |
||
110 | |||
111 | } |
||
112 | |||
113 | #endif /* AMIRO_BASE_SENSOR_H_ */ |