MCP23S17 Bufferd
ExioInBuffer.h@0:54debc783452, 2016-11-04 (annotated)
- Committer:
- ryood
- Date:
- Fri Nov 04 19:48:18 2016 +0000
- Revision:
- 0:54debc783452
- Child:
- 1:f00bf8a84d56
Impl. ExioInBuffer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ryood | 0:54debc783452 | 1 | /* |
ryood | 0:54debc783452 | 2 | * ExioInBuffer.h |
ryood | 0:54debc783452 | 3 | * |
ryood | 0:54debc783452 | 4 | * Created: 2016.11.05 |
ryood | 0:54debc783452 | 5 | * |
ryood | 0:54debc783452 | 6 | */ |
ryood | 0:54debc783452 | 7 | |
ryood | 0:54debc783452 | 8 | #ifndef _EXIOINBUFFER_H_ |
ryood | 0:54debc783452 | 9 | #define _EXIOINBUFFER_H_ |
ryood | 0:54debc783452 | 10 | |
ryood | 0:54debc783452 | 11 | #include "mbed.h" |
ryood | 0:54debc783452 | 12 | #include "rtos.h" |
ryood | 0:54debc783452 | 13 | #include "ExioMcp23s17.h" |
ryood | 0:54debc783452 | 14 | |
ryood | 0:54debc783452 | 15 | class ExioInBuffer { |
ryood | 0:54debc783452 | 16 | public: |
ryood | 0:54debc783452 | 17 | ExioInBuffer(ExioMcp23s17* device, ExioPort port, uint32_t interval) : |
ryood | 0:54debc783452 | 18 | _device(device), |
ryood | 0:54debc783452 | 19 | _port(port), |
ryood | 0:54debc783452 | 20 | _interval(interval), |
ryood | 0:54debc783452 | 21 | _buffer(0x00), |
ryood | 0:54debc783452 | 22 | _timer(&ExioInBuffer::threadHelper, osTimerPeriodic, (void *)this) |
ryood | 0:54debc783452 | 23 | { |
ryood | 0:54debc783452 | 24 | |
ryood | 0:54debc783452 | 25 | } |
ryood | 0:54debc783452 | 26 | |
ryood | 0:54debc783452 | 27 | uint8_t readPort() |
ryood | 0:54debc783452 | 28 | { |
ryood | 0:54debc783452 | 29 | return _buffer; |
ryood | 0:54debc783452 | 30 | } |
ryood | 0:54debc783452 | 31 | |
ryood | 0:54debc783452 | 32 | void run() |
ryood | 0:54debc783452 | 33 | { |
ryood | 0:54debc783452 | 34 | _timer.start(_interval); |
ryood | 0:54debc783452 | 35 | } |
ryood | 0:54debc783452 | 36 | |
ryood | 0:54debc783452 | 37 | void stop() |
ryood | 0:54debc783452 | 38 | { |
ryood | 0:54debc783452 | 39 | _timer.stop(); |
ryood | 0:54debc783452 | 40 | } |
ryood | 0:54debc783452 | 41 | |
ryood | 0:54debc783452 | 42 | protected: |
ryood | 0:54debc783452 | 43 | ExioMcp23s17* _device; |
ryood | 0:54debc783452 | 44 | ExioPort _port; |
ryood | 0:54debc783452 | 45 | uint32_t _interval; |
ryood | 0:54debc783452 | 46 | uint8_t _buffer; |
ryood | 0:54debc783452 | 47 | RtosTimer _timer; |
ryood | 0:54debc783452 | 48 | |
ryood | 0:54debc783452 | 49 | static void threadHelper(const void* arg) |
ryood | 0:54debc783452 | 50 | { |
ryood | 0:54debc783452 | 51 | ExioInBuffer* instance = (ExioInBuffer*)arg; |
ryood | 0:54debc783452 | 52 | instance->update(); |
ryood | 0:54debc783452 | 53 | } |
ryood | 0:54debc783452 | 54 | |
ryood | 0:54debc783452 | 55 | void update() { |
ryood | 0:54debc783452 | 56 | _buffer = _device->readPort(_port); |
ryood | 0:54debc783452 | 57 | } |
ryood | 0:54debc783452 | 58 | }; |
ryood | 0:54debc783452 | 59 | |
ryood | 0:54debc783452 | 60 | #endif //_EXIOINBUFFER_H_ |