capstone_finish
Dependencies: BufferedSerial motor_sn7544
MbedHardware.h@10:ca4e4062701a, 2019-11-26 (annotated)
- Committer:
- Jeonghoon
- Date:
- Tue Nov 26 15:30:27 2019 +0000
- Revision:
- 10:ca4e4062701a
- Parent:
- 9:ccd662244071
capstone finish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jeonghoon | 3:2a3664dc6634 | 1 | /* |
Jeonghoon | 3:2a3664dc6634 | 2 | * MbedHardware |
Jeonghoon | 3:2a3664dc6634 | 3 | * |
Jeonghoon | 3:2a3664dc6634 | 4 | * Created on: Aug 17, 2011 |
Jeonghoon | 3:2a3664dc6634 | 5 | * Author: nucho |
Jeonghoon | 3:2a3664dc6634 | 6 | */ |
Jeonghoon | 3:2a3664dc6634 | 7 | |
Jeonghoon | 3:2a3664dc6634 | 8 | #ifndef ROS_MBED_HARDWARE_H_ |
Jeonghoon | 3:2a3664dc6634 | 9 | #define ROS_MBED_HARDWARE_H_ |
Jeonghoon | 3:2a3664dc6634 | 10 | |
Jeonghoon | 3:2a3664dc6634 | 11 | #include "mbed.h" |
Jeonghoon | 3:2a3664dc6634 | 12 | |
Jeonghoon | 3:2a3664dc6634 | 13 | #include "BufferedSerial.h" |
Jeonghoon | 3:2a3664dc6634 | 14 | |
Jeonghoon | 3:2a3664dc6634 | 15 | class MbedHardware { |
Jeonghoon | 3:2a3664dc6634 | 16 | public: |
Jeonghoon | 10:ca4e4062701a | 17 | MbedHardware(PinName tx, PinName rx, long baud) |
Jeonghoon | 3:2a3664dc6634 | 18 | :iostream(tx, rx){ |
Jeonghoon | 3:2a3664dc6634 | 19 | baud_ = baud; |
Jeonghoon | 3:2a3664dc6634 | 20 | t.start(); |
Jeonghoon | 3:2a3664dc6634 | 21 | } |
Jeonghoon | 3:2a3664dc6634 | 22 | |
Jeonghoon | 3:2a3664dc6634 | 23 | MbedHardware() |
Jeonghoon | 10:ca4e4062701a | 24 | :iostream(USBTX, USBRX) { //PA_11, PA_12 //USBTX, USBRX |
Jeonghoon | 10:ca4e4062701a | 25 | baud_ = 115200; |
Jeonghoon | 3:2a3664dc6634 | 26 | t.start(); |
Jeonghoon | 3:2a3664dc6634 | 27 | } |
Jeonghoon | 3:2a3664dc6634 | 28 | |
Jeonghoon | 3:2a3664dc6634 | 29 | void setBaud(long baud){ |
Jeonghoon | 3:2a3664dc6634 | 30 | this->baud_= baud; |
Jeonghoon | 3:2a3664dc6634 | 31 | } |
Jeonghoon | 3:2a3664dc6634 | 32 | |
Jeonghoon | 3:2a3664dc6634 | 33 | int getBaud(){return baud_;} |
Jeonghoon | 3:2a3664dc6634 | 34 | |
Jeonghoon | 3:2a3664dc6634 | 35 | void init(){ |
Jeonghoon | 3:2a3664dc6634 | 36 | iostream.baud(baud_); |
Jeonghoon | 3:2a3664dc6634 | 37 | } |
Jeonghoon | 3:2a3664dc6634 | 38 | |
Jeonghoon | 3:2a3664dc6634 | 39 | int read(){ |
Jeonghoon | 3:2a3664dc6634 | 40 | if (iostream.readable()) { |
Jeonghoon | 3:2a3664dc6634 | 41 | return iostream.getc(); |
Jeonghoon | 3:2a3664dc6634 | 42 | } else { |
Jeonghoon | 3:2a3664dc6634 | 43 | return -1; |
Jeonghoon | 3:2a3664dc6634 | 44 | } |
Jeonghoon | 3:2a3664dc6634 | 45 | }; |
Jeonghoon | 3:2a3664dc6634 | 46 | void write(uint8_t* data, int length) { |
Jeonghoon | 3:2a3664dc6634 | 47 | for (int i=0; i<length; i++) |
Jeonghoon | 3:2a3664dc6634 | 48 | iostream.putc(data[i]); |
Jeonghoon | 3:2a3664dc6634 | 49 | } |
Jeonghoon | 3:2a3664dc6634 | 50 | |
Jeonghoon | 3:2a3664dc6634 | 51 | unsigned long time(){return t.read_ms();} |
Jeonghoon | 3:2a3664dc6634 | 52 | |
Jeonghoon | 3:2a3664dc6634 | 53 | protected: |
Jeonghoon | 3:2a3664dc6634 | 54 | BufferedSerial iostream; |
Jeonghoon | 3:2a3664dc6634 | 55 | long baud_; |
Jeonghoon | 3:2a3664dc6634 | 56 | Timer t; |
Jeonghoon | 3:2a3664dc6634 | 57 | }; |
Jeonghoon | 3:2a3664dc6634 | 58 | |
Jeonghoon | 3:2a3664dc6634 | 59 | |
Jeonghoon | 3:2a3664dc6634 | 60 | #endif /* ROS_MBED_HARDWARE_H_ */ |