データの保存、更新、取得ができるWebサービス「milkcocoa」に接続し、データのプッシュ、送信、取得ができるライブラリを使ったサンプルです。ESP8266版 https://mlkcca.com/

Dependencies:   Milkcocoa mbed

Dependents:   M2m

Committer:
jksoft
Date:
Mon Feb 29 09:19:56 2016 +0000
Revision:
4:d40cc9301d1e
Parent:
0:82d5445a9461
????????????????; Milkcocoa????????

Who changed what in which revision?

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