Пример #1
0
void SAC_ClockDisplay::SetFloat(float v, bool trailingZeros)
{
  //Tlc.clear();
  ClearSegments();
  int iVal = (int)v; // integer part
  int fVal = 0;
  float frac = v - (float)iVal;

  if(iVal < 10000) {
    // which digit's decimal point do I use?
    int dp_pos = 0;
    if(iVal < 10) {
      dp_pos = 0;
      fVal = (int)(frac * 100.0);
    }
    else if(iVal < 100) {
      dp_pos = 1;
      fVal = (int)(frac * 10.0);
    }
    else if(iVal < 1000) {
      dp_pos = 2;
      fVal = (int)(frac);
    }
    else {
      dp_pos = 3;
    }
    //Debug("I: "); Debug(iVal);
    //Debug(", F: "); Debug(fVal);
    //DebugLn("");
    SetSegment(dp_pos, DP);
    int p = 0;
    char buf[12];
    ltoa(iVal,buf,10);
    while(p < 4 && buf[p] != '\0') {
      SetDigit(p,buf[p]);
      p++;
    }
    int offset = p;
    p = 0;
    ltoa(fVal,buf,10);
    while(p+offset < 4 && buf[p] != '\0') {
      SetDigit(p+offset,buf[p]);
      p++;
    }

    p = p+offset;
    while(p<4) {
      SetDigit(p,trailingZeros?'0':' ');
      p++;
    }

    Tlc.update();
  }
  else { 
    // value too big, what should I do?
  }
}
Пример #2
0
void SAC_ClockDisplay::SetDigit(int digit, int value)
{
  //Debug("SetDigit(");
  //Debug(digit);
  //Debug(", "); Debug(value); DebugLn(")");
  char c = ' ';
  if(value >= 0 && value <= 9) {
    c = '0' + value;
  }
  SetDigit(digit, c);
}
Пример #3
0
static void UpdateDigits (uint16_t scan) {
    // Special case where a counter was selected
    uint16_t i;
    uint8_t *display;

    if (active != DisplayBuffer) return;
    display = (uint8_t *)Sequence_Sets[prev];

    /* programmatic update of the display buffers */
    if (display == Counter) {
        // Update the counter
        counter++;

        // Update the counter digits
        SetDigit(scan, 2, counter & 0xF, 4);
        SetDigit(scan+4, 10, (counter >> 4) & 0xF, 4);
        SetDigit(scan+8, 18, (counter >> 8) & 0xF, 4);
        SetDigit(scan+12, 24, (counter >> 12) & 0xF, 4);
    } else if (display == Clock) {
Пример #4
0
void SAC_ClockDisplay::update()
{
  static bool colonOn = false;
  if (mClockIsSet) {

    // manage the colon
    if (FirstHalfOfSecond()) {
      if (!colonOn) {
	//analogWrite(mColonPin, 255);
	Tlc.set(mColon1, mBrightness);
	Tlc.set(mColon2, mBrightness);
	mNeedUpdate = true;
	colonOn = true;
      }
    }
    else {
      if (colonOn) {
	//analogWrite(mColonPin, 0);
	Tlc.set(mColon1, 0);
	Tlc.set(mColon2, 0);
	mNeedUpdate = true;
	colonOn = false;
      }
    }
    DateTime dt = clock.now();
    if(mHour != dt.hour() || mMinute != dt.minute()) {
      mNeedUpdate = true;

      mHour = dt.hour();
      mMinute = dt.minute();

      if(mHour == 0) mHour = 12;
      if(mHour > 12) mHour -= 12;

      int h0 = mHour/10;
      int h1 = mHour - (h0 * 10);
      int m0 = mMinute/10;
      int m1 = mMinute - (m0 * 10);

      //Tlc.clear();
      ClearSegments();
      
      if (mLeadingZeros || h0 > 0) {
	SetDigit(0,h0);
      }
      SetDigit(1,h1);
      SetDigit(2,m0);
      SetDigit(3,m1);
    }
  }
  else {
    if (FirstHalfOfSecond()) {
      if (!colonOn) {
	//Tlc.clear();
	ClearSegments();
	mNeedUpdate = true;
	SetDigit(0,'-');
	SetDigit(1,'-');
	SetDigit(2,'-');
	SetDigit(3,'-');
	//analogWrite(mColonPin, 255);
	Tlc.set(mColon1, mBrightness);
	Tlc.set(mColon2, mBrightness);
	colonOn = true;
      }
    }
    else {
      if (colonOn) {
	//Tlc.clear();
	ClearSegments();
	mNeedUpdate = true;
	SetDigit(0,' ');
	SetDigit(1,' ');
	SetDigit(2,' ');
	SetDigit(3,' ');
	//analogWrite(mColonPin, 0);
	Tlc.set(mColon1, 0);
	Tlc.set(mColon2, 0);
	colonOn = false;
      }
    }
  }
    
  if (mNeedUpdate) {
    Tlc.update();
    mNeedUpdate = false;
  }
}