A simple WIP that logs data from a Grove sensor, and can send and receive information over USB and SMS.
Dependencies: DHT DS_1337 SDFileSystem USBDevice mbed
UsbComms.h
00001 #ifndef __USB_COMMS_H__ 00002 #define __USB_COMMS_H__ 00003 #include "AbstractHandler.h" 00004 00005 #define TX_USB_MSG_MAX 64u // only send 64 bytes at a time 00006 #define TX_USB_BUFF_SIZE 256u // the tx buffer can hold up to 256 bytes 00007 00008 class USBSerial; 00009 class CircBuff; 00010 00011 /*! 00012 * \brief The UsbComms class handles input and output for the serial port connected to a PC 00013 * The main run() function cycles through checking for input and copying to a buffer to be handled, 00014 * and checking the output buffer to see if there is anything to be sent out. 00015 * 00016 * Data can be queued for output by copying it to the circular buffer 00017 */ 00018 class UsbComms : public AbstractHandler 00019 { 00020 public: 00021 UsbComms(MyTimers *_timer); 00022 ~UsbComms(); 00023 00024 void run(); 00025 00026 void setRequest(int request, void *data = 0); 00027 00028 enum request_t { 00029 usbreq_PrintToTerminal, ///< Print to terminal normally 00030 usbreq_PrintToTerminalTimestamp ///< Print to terminal, including the timestamp 00031 }; 00032 00033 private: 00034 USBSerial *_serial; ///< Interface to the serial port 00035 CircBuff *m_circBuff; ///< Data waiting to be printed to the serial port 00036 00037 // state machine 00038 enum mode_t{ 00039 usb_Start, ///< Set up the state machine 00040 usb_CheckInput, ///< See if any data is waiting to be read in - currently does not process anything 00041 usb_CheckOutput, ///< See if any data should be sent over serial 00042 }; 00043 mode_t mode; 00044 00045 // helpers 00046 void printToTerminal(char *s); // raw 00047 void printToTerminalEx(char *s); // add timestamp 00048 }; 00049 00050 00051 #endif
Generated on Tue Jul 12 2022 23:07:44 by 1.7.2