Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MODSERIAL Terminal mbed
stripe.cpp
00001 #include <stdio.h> 00002 #include <stdlib.h> 00003 #include <stdarg.h> 00004 #include "stripe.h" 00005 #include "mbed.h" 00006 00007 #define sprintf mysprintf 00008 00009 int mysprintf( char * str, const char * format, ... ) 00010 { 00011 char s[50]; 00012 va_list ap; 00013 00014 va_start(ap,format); 00015 vsprintf(s,format,ap); 00016 va_end(ap); 00017 00018 strncpy(str,s,strlen(s)); 00019 return strlen(s); 00020 } 00021 00022 Stripe::Stripe( uint8_t bc, uint8_t oc, uint8_t ic ) 00023 { 00024 00025 memset((void*)&(this->strip),0x20,sizeof(Strip)); 00026 sprintf(this->strip.bgc, "\033[48;5;%03um", bc ); 00027 sprintf(this->strip.row[0].fgc, "\033[38;5;%03um", oc ); 00028 sprintf(this->strip.row[1].fgc, "\033[38;5;%03um", ic ); 00029 sprintf(this->strip.row[0].eol, "\n\r" ); 00030 sprintf(this->strip.row[1].eol, "\n\r" ); 00031 this->wp = 0; 00032 this->rp =0; 00033 00034 } 00035 00036 00037 int Stripe::advance( void ) 00038 { 00039 if ( ++ wp >= 16 ) 00040 return 0; 00041 else 00042 return 1; 00043 } 00044 00045 int Stripe::inbyte( uint8_t b ) 00046 { 00047 sprintf(&strip.row[1].hex[wp*3], "%02X ", b ); 00048 00049 if (b >=0x20 && b<=0x80) 00050 { 00051 strip.row[1].asc[wp] = b; 00052 }else{ 00053 strip.row[1].asc[wp] = '.'; 00054 } 00055 return advance(); 00056 } 00057 00058 int Stripe::outbyte( uint8_t b ) 00059 { 00060 sprintf(&strip.row[0].hex[wp*3], "%02X ", b ); 00061 00062 if (b >=0x20 && b<=0x80) 00063 { 00064 strip.row[0].asc[wp] = b; 00065 }else{ 00066 strip.row[0].asc[wp] = '.'; 00067 } 00068 return advance(); 00069 } 00070 00071 uint8_t Stripe::getc( void ) 00072 { 00073 char c; 00074 00075 while ( rp < sizeof(strip) ) 00076 { 00077 c = ((char*)(&strip))[rp++]; 00078 if (c) 00079 return c; 00080 } 00081 return 0; 00082 }
Generated on Wed Jul 13 2022 07:44:32 by
1.7.2