Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of rosserial_mbed_lib by
MbedHardware.h
00001 /* 00002 * MbedHardware 00003 * 00004 * Created on: Aug 17, 2011 00005 * Author: nucho 00006 */ 00007 00008 #ifndef MBEDHARDWARE_H_ 00009 #define MBEDHARDWARE_H_ 00010 00011 #include "mbed.h" 00012 #include "MODSERIAL.h" 00013 00014 #ifndef ROSSERIAL_BAUDRATE 00015 #define ROSSERIAL_BAUDRATE 57600 00016 #endif 00017 00018 00019 class MbedHardware { 00020 public: 00021 MbedHardware(MODSERIAL* io , int baud= ROSSERIAL_BAUDRATE) 00022 :iostream(*io){ 00023 baud_ = baud; 00024 t.start(); 00025 } 00026 MbedHardware() 00027 :iostream(USBTX, USBRX) { 00028 baud_ = ROSSERIAL_BAUDRATE; 00029 t.start(); 00030 } 00031 MbedHardware(MbedHardware& h) 00032 :iostream(h.iostream) { 00033 this->baud_ = h.baud_; 00034 00035 t.start(); 00036 } 00037 00038 void setBaud(int baud) { 00039 this->baud_= baud; 00040 } 00041 00042 int getBaud() { 00043 return baud_; 00044 } 00045 00046 void init() { 00047 iostream.baud(baud_); 00048 } 00049 00050 int read() { 00051 if (iostream.readable()) { 00052 return iostream.getc(); 00053 } else { 00054 return -1; 00055 } 00056 }; 00057 void write(uint8_t* data, int length) { 00058 for (int i=0; i<length; i++) iostream.putc(data[i]); 00059 } 00060 00061 unsigned long time() { 00062 return t.read_ms(); 00063 } 00064 00065 protected: 00066 int baud_; 00067 MODSERIAL iostream; 00068 Timer t; 00069 }; 00070 00071 00072 #endif /* MBEDHARDWARE_H_ */
Generated on Tue Jul 12 2022 19:53:57 by
1.7.2
