hellomqttt to thingspeak mqtt and ifttt

Dependencies:   Servo MQTTPacket FP

Committer:
jasonberry
Date:
Wed May 05 14:48:01 2021 +0000
Revision:
25:ca1b1098c77f
TEST

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jasonberry 25:ca1b1098c77f 1 /* mbed TextDisplay Display Library Base Class
jasonberry 25:ca1b1098c77f 2 * Copyright (c) 2007-2009 sford
jasonberry 25:ca1b1098c77f 3 * Released under the MIT License: http://mbed.org/license/mit
jasonberry 25:ca1b1098c77f 4 */
jasonberry 25:ca1b1098c77f 5
jasonberry 25:ca1b1098c77f 6 #include "TextDisplay.h"
jasonberry 25:ca1b1098c77f 7
jasonberry 25:ca1b1098c77f 8 TextDisplay::TextDisplay(const char *name) : Stream(name){
jasonberry 25:ca1b1098c77f 9 _row = 0;
jasonberry 25:ca1b1098c77f 10 _column = 0;
jasonberry 25:ca1b1098c77f 11 if (name == NULL) {
jasonberry 25:ca1b1098c77f 12 _path = NULL;
jasonberry 25:ca1b1098c77f 13 } else {
jasonberry 25:ca1b1098c77f 14 _path = new char[strlen(name) + 2];
jasonberry 25:ca1b1098c77f 15 sprintf(_path, "/%s", name);
jasonberry 25:ca1b1098c77f 16 }
jasonberry 25:ca1b1098c77f 17 }
jasonberry 25:ca1b1098c77f 18
jasonberry 25:ca1b1098c77f 19 int TextDisplay::_putc(int value) {
jasonberry 25:ca1b1098c77f 20 if(value == '\n') {
jasonberry 25:ca1b1098c77f 21 _column = 0;
jasonberry 25:ca1b1098c77f 22 _row++;
jasonberry 25:ca1b1098c77f 23 if(_row >= rows()) {
jasonberry 25:ca1b1098c77f 24 _row = 0;
jasonberry 25:ca1b1098c77f 25 }
jasonberry 25:ca1b1098c77f 26 } else {
jasonberry 25:ca1b1098c77f 27 character(_column, _row, value);
jasonberry 25:ca1b1098c77f 28 _column++;
jasonberry 25:ca1b1098c77f 29 if(_column >= columns()) {
jasonberry 25:ca1b1098c77f 30 _column = 0;
jasonberry 25:ca1b1098c77f 31 _row++;
jasonberry 25:ca1b1098c77f 32 if(_row >= rows()) {
jasonberry 25:ca1b1098c77f 33 _row = 0;
jasonberry 25:ca1b1098c77f 34 }
jasonberry 25:ca1b1098c77f 35 }
jasonberry 25:ca1b1098c77f 36 }
jasonberry 25:ca1b1098c77f 37 return value;
jasonberry 25:ca1b1098c77f 38 }
jasonberry 25:ca1b1098c77f 39
jasonberry 25:ca1b1098c77f 40 // crude cls implementation, should generally be overwritten in derived class
jasonberry 25:ca1b1098c77f 41 void TextDisplay::cls() {
jasonberry 25:ca1b1098c77f 42 locate(0, 0);
jasonberry 25:ca1b1098c77f 43 for(int i=0; i<columns()*rows(); i++) {
jasonberry 25:ca1b1098c77f 44 putc(' ');
jasonberry 25:ca1b1098c77f 45 }
jasonberry 25:ca1b1098c77f 46 }
jasonberry 25:ca1b1098c77f 47
jasonberry 25:ca1b1098c77f 48 void TextDisplay::locate(int column, int row) {
jasonberry 25:ca1b1098c77f 49 _column = column;
jasonberry 25:ca1b1098c77f 50 _row = row;
jasonberry 25:ca1b1098c77f 51 }
jasonberry 25:ca1b1098c77f 52
jasonberry 25:ca1b1098c77f 53 int TextDisplay::_getc() {
jasonberry 25:ca1b1098c77f 54 return -1;
jasonberry 25:ca1b1098c77f 55 }
jasonberry 25:ca1b1098c77f 56
jasonberry 25:ca1b1098c77f 57 void TextDisplay::foreground(uint16_t colour) {
jasonberry 25:ca1b1098c77f 58 _foreground = colour;
jasonberry 25:ca1b1098c77f 59 }
jasonberry 25:ca1b1098c77f 60
jasonberry 25:ca1b1098c77f 61 void TextDisplay::background(uint16_t colour) {
jasonberry 25:ca1b1098c77f 62 _background = colour;
jasonberry 25:ca1b1098c77f 63 }
jasonberry 25:ca1b1098c77f 64
jasonberry 25:ca1b1098c77f 65 bool TextDisplay::claim (FILE *stream) {
jasonberry 25:ca1b1098c77f 66 if ( _path == NULL) {
jasonberry 25:ca1b1098c77f 67 fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n");
jasonberry 25:ca1b1098c77f 68 return false;
jasonberry 25:ca1b1098c77f 69 }
jasonberry 25:ca1b1098c77f 70 if (freopen(_path, "w", stream) == NULL) {
jasonberry 25:ca1b1098c77f 71 // Failed, should not happen
jasonberry 25:ca1b1098c77f 72 return false;
jasonberry 25:ca1b1098c77f 73 }
jasonberry 25:ca1b1098c77f 74 // make sure we use line buffering
jasonberry 25:ca1b1098c77f 75 setvbuf(stdout, NULL, _IOLBF, columns());
jasonberry 25:ca1b1098c77f 76 return true;
jasonberry 25:ca1b1098c77f 77 }