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