smple

Dependencies:   ESP8266Interface IFTTT mbed

Fork of IFTTT_ESP8266_Example by Austin Blackstone

Committer:
jksoft
Date:
Mon Jul 27 11:43:18 2015 +0000
Revision:
4:3994cd534bd5
rev0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 4:3994cd534bd5 1 #ifndef SOFTSERIAL_SEND_ONRY_H
jksoft 4:3994cd534bd5 2 #define SOFTSERIAL_SEND_ONRY_H
jksoft 4:3994cd534bd5 3
jksoft 4:3994cd534bd5 4 #include "mbed.h"
jksoft 4:3994cd534bd5 5 #include "SoftSerial_Ticker.h"
jksoft 4:3994cd534bd5 6 /** A software serial implementation
jksoft 4:3994cd534bd5 7 *
jksoft 4:3994cd534bd5 8 */
jksoft 4:3994cd534bd5 9 class SoftSerialSendOnry: public Stream {
jksoft 4:3994cd534bd5 10
jksoft 4:3994cd534bd5 11 public:
jksoft 4:3994cd534bd5 12 /**
jksoft 4:3994cd534bd5 13 * Constructor
jksoft 4:3994cd534bd5 14 *
jksoft 4:3994cd534bd5 15 * @param TX Name of the TX pin, NC for not connected
jksoft 4:3994cd534bd5 16 * @param name Name of the connection
jksoft 4:3994cd534bd5 17 */
jksoft 4:3994cd534bd5 18 SoftSerialSendOnry(PinName TX, const char* name = NULL);
jksoft 4:3994cd534bd5 19 virtual ~SoftSerialSendOnry();
jksoft 4:3994cd534bd5 20
jksoft 4:3994cd534bd5 21 /** Set the baud rate of the serial port
jksoft 4:3994cd534bd5 22 *
jksoft 4:3994cd534bd5 23 * @param baudrate The baudrate of the serial port (default = 9600).
jksoft 4:3994cd534bd5 24 */
jksoft 4:3994cd534bd5 25 void baud(int baudrate);
jksoft 4:3994cd534bd5 26
jksoft 4:3994cd534bd5 27 enum Parity {
jksoft 4:3994cd534bd5 28 None = 0,
jksoft 4:3994cd534bd5 29 Odd,
jksoft 4:3994cd534bd5 30 Even,
jksoft 4:3994cd534bd5 31 Forced1,
jksoft 4:3994cd534bd5 32 Forced0
jksoft 4:3994cd534bd5 33 };
jksoft 4:3994cd534bd5 34
jksoft 4:3994cd534bd5 35 enum IrqType {
jksoft 4:3994cd534bd5 36 RxIrq = 0,
jksoft 4:3994cd534bd5 37 TxIrq
jksoft 4:3994cd534bd5 38 };
jksoft 4:3994cd534bd5 39
jksoft 4:3994cd534bd5 40 /** Set the transmission format used by the serial port
jksoft 4:3994cd534bd5 41 *
jksoft 4:3994cd534bd5 42 * @param bits The number of bits in a word (default = 8)
jksoft 4:3994cd534bd5 43 * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
jksoft 4:3994cd534bd5 44 * @param stop The number of stop bits (default = 1)
jksoft 4:3994cd534bd5 45 */
jksoft 4:3994cd534bd5 46 void format(int bits=8, Parity parity=SoftSerialSendOnry::None, int stop_bits=1);
jksoft 4:3994cd534bd5 47
jksoft 4:3994cd534bd5 48 /** Determine if there is space available to write a character
jksoft 4:3994cd534bd5 49 *
jksoft 4:3994cd534bd5 50 * @returns
jksoft 4:3994cd534bd5 51 * 1 if there is space to write a character,
jksoft 4:3994cd534bd5 52 * 0 otherwise
jksoft 4:3994cd534bd5 53 */
jksoft 4:3994cd534bd5 54 int writeable();
jksoft 4:3994cd534bd5 55
jksoft 4:3994cd534bd5 56 /** Attach a function to call whenever a serial interrupt is generated
jksoft 4:3994cd534bd5 57 *
jksoft 4:3994cd534bd5 58 * @param fptr A pointer to a void function, or 0 to set as none
jksoft 4:3994cd534bd5 59 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
jksoft 4:3994cd534bd5 60 */
jksoft 4:3994cd534bd5 61 void attach(void (*fptr)(void), IrqType type=RxIrq) {
jksoft 4:3994cd534bd5 62 fpointer[type].attach(fptr);
jksoft 4:3994cd534bd5 63 }
jksoft 4:3994cd534bd5 64
jksoft 4:3994cd534bd5 65 /** Attach a member function to call whenever a serial interrupt is generated
jksoft 4:3994cd534bd5 66 *
jksoft 4:3994cd534bd5 67 * @param tptr pointer to the object to call the member function on
jksoft 4:3994cd534bd5 68 * @param mptr pointer to the member function to be called
jksoft 4:3994cd534bd5 69 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
jksoft 4:3994cd534bd5 70 */
jksoft 4:3994cd534bd5 71 template<typename T>
jksoft 4:3994cd534bd5 72 void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
jksoft 4:3994cd534bd5 73 fpointer[type].attach(tptr, mptr);
jksoft 4:3994cd534bd5 74 }
jksoft 4:3994cd534bd5 75
jksoft 4:3994cd534bd5 76 /** Generate a break condition on the serial line
jksoft 4:3994cd534bd5 77 */
jksoft 4:3994cd534bd5 78 void send_break();
jksoft 4:3994cd534bd5 79
jksoft 4:3994cd534bd5 80 protected:
jksoft 4:3994cd534bd5 81 DigitalOut *tx;
jksoft 4:3994cd534bd5 82
jksoft 4:3994cd534bd5 83 bool tx_en;
jksoft 4:3994cd534bd5 84 int bit_period;
jksoft 4:3994cd534bd5 85 int _bits, _stop_bits, _total_bits;
jksoft 4:3994cd534bd5 86 Parity _parity;
jksoft 4:3994cd534bd5 87
jksoft 4:3994cd534bd5 88 FunctionPointer fpointer[2];
jksoft 4:3994cd534bd5 89
jksoft 4:3994cd534bd5 90 //tx
jksoft 4:3994cd534bd5 91 void tx_handler(void);
jksoft 4:3994cd534bd5 92 void prepare_tx(int c);
jksoft 4:3994cd534bd5 93 FlexTicker txticker;
jksoft 4:3994cd534bd5 94 int _char;
jksoft 4:3994cd534bd5 95 volatile int tx_bit;
jksoft 4:3994cd534bd5 96
jksoft 4:3994cd534bd5 97
jksoft 4:3994cd534bd5 98
jksoft 4:3994cd534bd5 99 virtual int _getc();
jksoft 4:3994cd534bd5 100 virtual int _putc(int c);
jksoft 4:3994cd534bd5 101 };
jksoft 4:3994cd534bd5 102
jksoft 4:3994cd534bd5 103
jksoft 4:3994cd534bd5 104 #endif
jksoft 4:3994cd534bd5 105