Home Alert System

Dependencies:   PWM_Tone_Library DHT

Committer:
ethaderu
Date:
Tue Mar 05 02:34:44 2019 +0000
Revision:
3:78f223d34f36
Publish 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ethaderu 3:78f223d34f36 1 #include "Print.h"
ethaderu 3:78f223d34f36 2 #include "mbed.h"
ethaderu 3:78f223d34f36 3
ethaderu 3:78f223d34f36 4 #include <stdio.h>
ethaderu 3:78f223d34f36 5 #include <string.h>
ethaderu 3:78f223d34f36 6
ethaderu 3:78f223d34f36 7 size_t Print::write(const uint8_t* buf, size_t size) {
ethaderu 3:78f223d34f36 8 size_t ret = 0;
ethaderu 3:78f223d34f36 9 while (size--) {
ethaderu 3:78f223d34f36 10 ret += write(*buf++);
ethaderu 3:78f223d34f36 11 }
ethaderu 3:78f223d34f36 12 return ret;
ethaderu 3:78f223d34f36 13 }
ethaderu 3:78f223d34f36 14
ethaderu 3:78f223d34f36 15 size_t Print::print(const char* s) {
ethaderu 3:78f223d34f36 16 return write((const uint8_t*)s, strlen(s));
ethaderu 3:78f223d34f36 17 }
ethaderu 3:78f223d34f36 18
ethaderu 3:78f223d34f36 19 size_t Print::print(char c) {
ethaderu 3:78f223d34f36 20 return write(c);
ethaderu 3:78f223d34f36 21 }
ethaderu 3:78f223d34f36 22
ethaderu 3:78f223d34f36 23 size_t Print::print(int n) {
ethaderu 3:78f223d34f36 24 return print((long) n);
ethaderu 3:78f223d34f36 25 }
ethaderu 3:78f223d34f36 26
ethaderu 3:78f223d34f36 27 size_t Print::print(long n) {
ethaderu 3:78f223d34f36 28 char buf[8 * sizeof(long) + 1];
ethaderu 3:78f223d34f36 29 snprintf(buf, sizeof(buf), "%ld", n);
ethaderu 3:78f223d34f36 30 return print(buf);
ethaderu 3:78f223d34f36 31 }
ethaderu 3:78f223d34f36 32
ethaderu 3:78f223d34f36 33 // Digits are ignored for now
ethaderu 3:78f223d34f36 34 size_t Print::print(double n, int digits) {
ethaderu 3:78f223d34f36 35 char buf[65];
ethaderu 3:78f223d34f36 36 snprintf(buf, sizeof(buf), "%g", n);
ethaderu 3:78f223d34f36 37 return print(buf);
ethaderu 3:78f223d34f36 38 }
ethaderu 3:78f223d34f36 39
ethaderu 3:78f223d34f36 40 size_t Print::println(const char* s) {
ethaderu 3:78f223d34f36 41 return print(s) + println();
ethaderu 3:78f223d34f36 42 }
ethaderu 3:78f223d34f36 43
ethaderu 3:78f223d34f36 44 size_t Print::println(char c) {
ethaderu 3:78f223d34f36 45 return print(c) + println();
ethaderu 3:78f223d34f36 46 }
ethaderu 3:78f223d34f36 47
ethaderu 3:78f223d34f36 48 size_t Print::println(int n) {
ethaderu 3:78f223d34f36 49 return print(n) + println();
ethaderu 3:78f223d34f36 50 }
ethaderu 3:78f223d34f36 51
ethaderu 3:78f223d34f36 52 size_t Print::println(long n) {
ethaderu 3:78f223d34f36 53 return print(n) + println();
ethaderu 3:78f223d34f36 54 }
ethaderu 3:78f223d34f36 55
ethaderu 3:78f223d34f36 56 size_t Print::println(double n, int digits) {
ethaderu 3:78f223d34f36 57 return print(n, digits) + println();
ethaderu 3:78f223d34f36 58 }
ethaderu 3:78f223d34f36 59
ethaderu 3:78f223d34f36 60 size_t Print::println() {
ethaderu 3:78f223d34f36 61 return print('\r') + print('\n');
ethaderu 3:78f223d34f36 62 }