copy lib

Fork of GMMP by SKTelecom_ThingPlug

Committer:
lesmin
Date:
Thu Jul 23 00:55:15 2015 +0000
Revision:
0:32c20cfb2b30
initial commit

Who changed what in which revision?

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