Gleb Klochkov / Mbed OS Climatcontroll_Main

Dependencies:   esp8266-driver

Committer:
glebiuskv
Date:
Fri Apr 13 08:53:46 2018 +0000
Revision:
0:2f0e1e23c242
initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
glebiuskv 0:2f0e1e23c242 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
glebiuskv 0:2f0e1e23c242 2 *
glebiuskv 0:2f0e1e23c242 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
glebiuskv 0:2f0e1e23c242 4 * and associated documentation files (the "Software"), to deal in the Software without
glebiuskv 0:2f0e1e23c242 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
glebiuskv 0:2f0e1e23c242 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
glebiuskv 0:2f0e1e23c242 7 * Software is furnished to do so, subject to the following conditions:
glebiuskv 0:2f0e1e23c242 8 *
glebiuskv 0:2f0e1e23c242 9 * The above copyright notice and this permission notice shall be included in all copies or
glebiuskv 0:2f0e1e23c242 10 * substantial portions of the Software.
glebiuskv 0:2f0e1e23c242 11 *
glebiuskv 0:2f0e1e23c242 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
glebiuskv 0:2f0e1e23c242 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
glebiuskv 0:2f0e1e23c242 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
glebiuskv 0:2f0e1e23c242 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
glebiuskv 0:2f0e1e23c242 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
glebiuskv 0:2f0e1e23c242 17 */
glebiuskv 0:2f0e1e23c242 18
glebiuskv 0:2f0e1e23c242 19 #include "stdint.h"
glebiuskv 0:2f0e1e23c242 20 #include "USBSerial.h"
glebiuskv 0:2f0e1e23c242 21
glebiuskv 0:2f0e1e23c242 22 int USBSerial::_putc(int c) {
glebiuskv 0:2f0e1e23c242 23 if (!terminal_connected)
glebiuskv 0:2f0e1e23c242 24 return 0;
glebiuskv 0:2f0e1e23c242 25 send((uint8_t *)&c, 1);
glebiuskv 0:2f0e1e23c242 26 return 1;
glebiuskv 0:2f0e1e23c242 27 }
glebiuskv 0:2f0e1e23c242 28
glebiuskv 0:2f0e1e23c242 29 int USBSerial::_getc() {
glebiuskv 0:2f0e1e23c242 30 uint8_t c = 0;
glebiuskv 0:2f0e1e23c242 31 while (buf.isEmpty());
glebiuskv 0:2f0e1e23c242 32 buf.dequeue(&c);
glebiuskv 0:2f0e1e23c242 33 return c;
glebiuskv 0:2f0e1e23c242 34 }
glebiuskv 0:2f0e1e23c242 35
glebiuskv 0:2f0e1e23c242 36
glebiuskv 0:2f0e1e23c242 37 bool USBSerial::writeBlock(uint8_t * buf, uint16_t size) {
glebiuskv 0:2f0e1e23c242 38 if(size > MAX_PACKET_SIZE_EPBULK) {
glebiuskv 0:2f0e1e23c242 39 return false;
glebiuskv 0:2f0e1e23c242 40 }
glebiuskv 0:2f0e1e23c242 41 if(!send(buf, size)) {
glebiuskv 0:2f0e1e23c242 42 return false;
glebiuskv 0:2f0e1e23c242 43 }
glebiuskv 0:2f0e1e23c242 44 return true;
glebiuskv 0:2f0e1e23c242 45 }
glebiuskv 0:2f0e1e23c242 46
glebiuskv 0:2f0e1e23c242 47
glebiuskv 0:2f0e1e23c242 48
glebiuskv 0:2f0e1e23c242 49 bool USBSerial::EPBULK_OUT_callback() {
glebiuskv 0:2f0e1e23c242 50 uint8_t c[65];
glebiuskv 0:2f0e1e23c242 51 uint32_t size = 0;
glebiuskv 0:2f0e1e23c242 52
glebiuskv 0:2f0e1e23c242 53 //we read the packet received and put it on the circular buffer
glebiuskv 0:2f0e1e23c242 54 readEP(c, &size);
glebiuskv 0:2f0e1e23c242 55 for (uint32_t i = 0; i < size; i++) {
glebiuskv 0:2f0e1e23c242 56 buf.queue(c[i]);
glebiuskv 0:2f0e1e23c242 57 }
glebiuskv 0:2f0e1e23c242 58
glebiuskv 0:2f0e1e23c242 59 //call a potential handlenr
glebiuskv 0:2f0e1e23c242 60 if (rx)
glebiuskv 0:2f0e1e23c242 61 rx.call();
glebiuskv 0:2f0e1e23c242 62
glebiuskv 0:2f0e1e23c242 63 return true;
glebiuskv 0:2f0e1e23c242 64 }
glebiuskv 0:2f0e1e23c242 65
glebiuskv 0:2f0e1e23c242 66 uint8_t USBSerial::available() {
glebiuskv 0:2f0e1e23c242 67 return buf.available();
glebiuskv 0:2f0e1e23c242 68 }
glebiuskv 0:2f0e1e23c242 69
glebiuskv 0:2f0e1e23c242 70 bool USBSerial::connected() {
glebiuskv 0:2f0e1e23c242 71 return terminal_connected;
glebiuskv 0:2f0e1e23c242 72 }