Beispiel #1
0
void tick_clock(struct tm *tick_time, bool stop) {
  clear();
  if((sw_butt&4)==4) { 
    reg.tm_hour = 0;
    reg.tm_min = 0;
    reg.tm_sec = 0;
    sw_butt ^= 4;//reset
  }
  if(!stop && (sw_butt&1)==1) sw_tick();
  if(++button_sec == 3) mode = delays[mode];//change mode
  switch(mode) {
  case 0: draw_dp(0b101010, 3);//time
    if (!clock_is_24h_style()) {
      if(tick_time->tm_hour > 11)
        draw(26, 0);//PM
      else
        draw(23, 0);//AM
    }
    tock(tick_time, false, clock_is_24h_style());
    break;
  case 1: draw_dp(0b100, 3);//date
    draw(days[tick_time->tm_mon * 3 + 21], 5);
    draw(days[tick_time->tm_mon * 3 + 22], 6);
    draw(days[tick_time->tm_mon * 3 + 23], 7);
    draw(tick_time->tm_mday/10, 3);
    draw(tick_time->tm_mday%10, 4);
    draw(days[tick_time->tm_wday * 3], 0);
    draw(days[tick_time->tm_wday * 3 + 1], 1);
    draw(days[tick_time->tm_wday * 3 + 2], 2);
    break;
  case 2: draw_dp(0b1010 + (((sw_butt&1)==1)?32:0) + (((sw_butt&2)==2)?0b10001:0), 3);//stopwatch
    if((sw_butt&2)==2) {
      tock(&lap, true, true);
    } else {
      tock(&reg, true, true);
    }
    break;
  case 3: printreal(value, false);
    break;
  case 4: draw_dp(1<<(direction%5), 8);//score
    printint(score, 7, false);
    break;
  case 5: draw_dp(1<<(direction%5), 8);//level
    printint(level, 7, false);
    draw(28, 0);//L
    break;
  case 6: draw_dp(1<<(direction%5), 8);//hiscore
    printint(hiscore, 7, false);
    draw(18, 0);//H
    break;
  default: break;
  }
}
Beispiel #2
0
static void sci(bool neg, double x) {
  int ex = 0;
  while(x > ten) {
    x /= ten;
    ex++;
  }
  while(x < one) {
    x *= ten;
    ex--;
  }
  if(neg) x = -x;
  printreal(x, true);
  printint(ex, 7, false);//no zeros
}
Beispiel #3
0
/* Print single performance metric rate value */
static void
printrate(int     valfmt,	/* from pmValueSet */
          int     type,		/* from pmDesc */
          pmValue *val1,	/* current value */
          pmValue *val2,	/* previous value */
	  double  delta,	/* time difference between samples */
          int     minwidth)	/* output is at least this wide */
{
    pmAtomValue a, b;
    double	v;
    static int	dowrap = -1;

    pmExtractValue(valfmt, val1, type, &a, PM_TYPE_DOUBLE);
    pmExtractValue(valfmt, val2, type, &b, PM_TYPE_DOUBLE);
    v = a.d - b.d;
    if (v < 0.0) {
	if (dowrap == -1) {
	    /* PCP_COUNTER_WRAP in environment enables "counter wrap" logic */
	    if (getenv("PCP_COUNTER_WRAP") == NULL)
		dowrap = 0;
	    else
		dowrap = 1;
	}
	if (dowrap) {
	    switch (type) {
		case PM_TYPE_32:
		case PM_TYPE_U32:
		    v += (double)UINT_MAX+1;
		    break;
		case PM_TYPE_64:
		case PM_TYPE_U64:
		    v += (double)ULONGLONG_MAX+1;
		    break;
	    }
	}
    }
    v /= delta;
    printreal(v, minwidth);
}
Beispiel #4
0
/* Print performance metric values */
static void
printvals(Context *x, pmValueSet *vset, int cols)
{
    int 	i, j;
    pmAtomValue	av;
    int		doreal = 0;

    if (x->desc.type == PM_TYPE_FLOAT || x->desc.type == PM_TYPE_DOUBLE)
	doreal = 1;

    /* null instance domain */
    if (x->desc.indom == PM_INDOM_NULL) {
	if (vset->numval == 1) {
	    if (doreal) {
		pmExtractValue(vset->valfmt, &vset->vlist[0], x->desc.type, &av, PM_TYPE_DOUBLE);
		printreal(av.d, cols);
	    }
	    else
		pmPrintValue(stdout, vset->valfmt, x->desc.type, &vset->vlist[0], cols);

	}
	else
	    printf("%*s", cols, "?");
	putchar('\n');
    }

    /* non-null instance domain */
    else {
	for (i = 0; i < x->inum; i++) {
	    for (j = 0; j < vset->numval; j++) {
		if (vset->vlist[j].inst == x->ipairs[i].id)
		    break;
	    }
	    if (j < vset->numval) {
		if (doreal) {
		    pmExtractValue(vset->valfmt, &vset->vlist[j], x->desc.type, &av, PM_TYPE_DOUBLE);
		    printreal(av.d, cols);
		}
		else
		    pmPrintValue(stdout, vset->valfmt, x->desc.type, &vset->vlist[j], cols);
	    }
	    else
		printf("%*s", cols, "?");
	    putchar(' ');
	}
	putchar('\n');

	for (j = 0; j < vset->numval; j++) {
	    for (i = 0; i < x->inum; i++) {
		if (vset->vlist[j].inst == x->ipairs[i].id)
		    break;
	    }
	    if (x->iall == 1 && i == x->inum) {
		printf("Warning: value=");
		if (doreal) {
		    pmExtractValue(vset->valfmt, &vset->vlist[j], x->desc.type, &av, PM_TYPE_DOUBLE);
		    printreal(av.d, 1);
		}
		else
		    pmPrintValue(stdout, vset->valfmt, x->desc.type, &vset->vlist[j], 1);
		printf(", but instance=%d is unknown\n", vset->vlist[j].inst);
	    }
	}
    }
}