An mbed wrapper around the helium-client to communicate with the Helium Atom

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BufferedSerial.cpp Source File

BufferedSerial.cpp

00001 /*
00002  * Copyright 2017, Helium Systems, Inc.
00003  * All Rights Reserved. See LICENSE.txt for license information
00004  */
00005 
00006 #include "BufferedSerial.h"
00007 
00008 BufferedSerial:: BufferedSerial(PinName tx,
00009                                 PinName rx,
00010                                 int     baud)
00011     : RawSerial(tx, rx, baud)
00012 {
00013     this->attach(callback(this, &BufferedSerial::_rx_interrupt),
00014                  Serial::RxIrq);
00015 }
00016 
00017 
00018 BufferedSerial::~BufferedSerial()
00019 {
00020     this->attach(NULL, Serial::RxIrq);
00021 }
00022 
00023 void BufferedSerial::_rx_interrupt()
00024 {
00025     _rx_buffer.push(serial_getc(&_serial));
00026 }
00027 
00028 
00029 void BufferedSerial::baud(int baud)
00030 {
00031     serial_baud(&_serial, baud);
00032 }
00033 
00034 int BufferedSerial::getc()
00035 {
00036     uint8_t ch;
00037     if (_rx_buffer.pop(&ch))
00038     {
00039         return ch;
00040     }
00041     return -1;
00042 }
00043 
00044 int BufferedSerial::putc(int ch)
00045 {
00046     serial_putc(&_serial, ch);
00047     return ch;
00048 }
00049 
00050 
00051 int BufferedSerial::readable()
00052 {
00053     return _rx_buffer.available() > 0;
00054 }