/////// File LcdFace.C /////// #include "LcdFace.h" #include #include #include LcdFace::LcdFace(const int d, const char* k) : CalcFace(d, k) { cw = new CalcWindow(d); } LcdFace::~LcdFace() { delete cw; } void LcdFace::build_number(char c, int& i) { static int leading_0 = 0; static int before_point = 1; if ( i == 0 ) // reset { leading_0 = 0; before_point = 1; cw->clear_lcd(); } if ( leading_0 && c == '0' ) return; // ignore extra leading zero if ( i == 0 && c == '0' ) leading_0 = 1; // first leading zero else leading_0 = 0; if ( before_point ) { if ( c == '.' ) { before_point = 0; if ( i == 0 ) nbuf[i++] = '0'; nbuf[i++] = c; } else if ( i == 1 && nbuf[0] == '0' ) nbuf[0] = c; else { nbuf[i++] = c; nbuf[i] = '.'; } } else // after point { if ( c == '.' ) return; nbuf[i++] = c; } if ( before_point ) nbuf[i+1] = '\0'; else nbuf[i]= '\0'; show_str(nbuf); } void LcdFace::show_number(double n) { static int width = prec+2; cw->clear_lcd(); if ( n == 0.0 ) show_str("0."); else { ostrstream os(nbuf, width, ios::out); os.precision(prec); os.width(width); os << n << ""; // put n as string in buf show_str(nbuf); } }