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