예제 #1
0
void
display_clock(int x, int y, uint32_t tm)
{
	int hh, mm, ss, ms;

	hh = (int) tm / 3600000;
	mm = (int) (tm % 3600000) / 60000;
	ss = (int) (tm % 60000) / 1000;
	ms = (int) tm % 1000;
	draw_digit(x, y, hh / 10, GFX_COLOR_RED, GFX_COLOR_BLACK);
	x += DISP_WIDTH + SEG_THICK/2;
	draw_digit(x, y, hh % 10, GFX_COLOR_RED, GFX_COLOR_BLACK);
	x += DISP_WIDTH + SEG_THICK/2;
	draw_colon(x, y, GFX_COLOR_RED, GFX_COLOR_BLACK);
	x += SEG_THICK + SEG_THICK/2;;
	draw_digit(x, y, mm / 10, GFX_COLOR_RED, GFX_COLOR_BLACK);
	x += DISP_WIDTH + SEG_THICK/2;
	draw_digit(x, y, mm % 10, GFX_COLOR_RED, GFX_COLOR_BLACK);
	x += DISP_WIDTH + SEG_THICK/2;
	draw_colon(x, y, GFX_COLOR_RED, GFX_COLOR_BLACK);
	x += SEG_THICK + SEG_THICK/2;;
	draw_digit(x, y, ss / 10, GFX_COLOR_RED, GFX_COLOR_BLACK);
	x += DISP_WIDTH + SEG_THICK/2;
	draw_digit(x, y, ss % 10, GFX_COLOR_RED, GFX_COLOR_BLACK);
	x += DISP_WIDTH + SEG_THICK/2;
	draw_dp(x, y, GFX_COLOR_RED, GFX_COLOR_BLACK);
	x += SEG_THICK + SEG_THICK/2;
	draw_digit(x, y, ms / 100, GFX_COLOR_RED, GFX_COLOR_BLACK);
	x += DISP_WIDTH + SEG_THICK/2;
	draw_digit(x, y, ms / 10, GFX_COLOR_RED, GFX_COLOR_BLACK);
	x += DISP_WIDTH + SEG_THICK/2;
	draw_digit(x, y, ms, GFX_COLOR_RED, GFX_COLOR_BLACK);
}
예제 #2
0
void clock_draw_alien_rgb( ttk_surface srf, clocks_globals *glob )
{
	int x;
	char buf[16];
	ttk_color fills[4];
	ttk_color outlines[4];
	ttk_color darks[4];

	/* fill the color array */
	fills[0]    = mc_color( 255,   0,   0,   WHITE );	/* R */
	fills[1]    = mc_color(   0, 255,   0,   GREY );	/* G */
	fills[2]    = mc_color( 255, 255,   0,   GREY );	/* Y */
	fills[3]    = mc_color(   0,   0, 255,   WHITE );	/* B */
	outlines[0] = mc_color( 128,   0,   0,   GREY );	/* R */
	outlines[1] = mc_color(   0, 128,   0,   DKGREY );	/* G */
	outlines[2] = mc_color( 128, 128,   0,   DKGREY );	/* Y */
	outlines[3] = mc_color(   0,   0, 128,   GREY );	/* B */
	darks[0]    = mc_color(  50,   0,   0,   DKGREY );	/* R */
	darks[1]    = mc_color(   0,  50,   0,   DKGREY );	/* G */
	darks[2]    = mc_color(  50,  50,   0,   DKGREY );	/* Y */
	darks[3]    = mc_color(   0,   0,  50,   DKGREY );	/* B */

        /* clear to black */
        ttk_fillrect( srf, 0, 0, glob->w, glob->h, ttk_makecol( 0, 0, 0 ));

	snprintf( buf, 16, "%02d%02d", glob->dispTime.tm_hour,
				       glob->dispTime.tm_min );
	for( x=0 ; x<4 ; x++ ) {
		draw_digit( srf, glob, x, buf[x]-'0', 
				ALIEN_RGB, outlines[x], fills[x], darks[x]);
	}
}
예제 #3
0
파일: nclock.c 프로젝트: FliPPeh/NClock
int draw_number(const char *num, int x, int y)
{
    int len = strlen(num);
    int i;
    int written = 0;

    int valid_length = digitlen(num);

    if (x < 0)
        x = (COLS - WIDTH(valid_length)) / 2;

    if (y < 0)
        y = (LINES - HEIGHT) / 2;


    for (i = 0; i < len; ++i)
    {
        char glyph = map_glyph(num[i]);

        if (glyph < 0)
            continue;

        draw_digit(glyph, x, y);
        x += DIGIT_SPACING + DIGIT_WIDTH;

        ++written;
    }

    return written;
}
예제 #4
0
void draw_digits(Simulator *sim, char *digits, char *compare, int y,
				 IplImage *debug, CvFont *font)
{
	if (!compare || digits[0] != compare[0])
		draw_digit(sim->width, sim->sections[0] - 40, y,
				   &digits[0], debug, font);
	for (int i = 0; i < 6; i++) {
		if (!compare || digits[1 + i] != compare[1 + i])
			draw_digit(sim->width, sim->sections[6 + i * 7], y,
					   &digits[1 + i], debug, font);
		if (!compare || digits[7 + i] != compare[7 + i])
			draw_digit(sim->width, sim->sections[53 + i * 7], y,
					   &digits[7 + i], debug, font);
	}
	if (compare)
		draw_digit(sim->width, sim->sections[95] + 10, y,
				   &sim->checksum, debug, font);
}
예제 #5
0
void RegionChooser::draw_keyboard(const Cairo::RefPtr<Cairo::Context>& cr,
                                  int clip_low, int clip_high) {
    const int h = KEYBOARD_HEIGHT;
    const int w = get_width() - 1;
    const int bh = int(h * 0.55);

    Gdk::Cairo::set_source_rgba(cr, black);
    cr->rectangle(0.5, h1 + 0.5, w, h - 1);
    cr->stroke();

    int x1 = key_to_x(20.5, w);
    Gdk::Cairo::set_source_rgba(cr, grey1);
    cr->rectangle(1, h1 + 1, x1 - 1, h - 2);
    cr->fill();

    int x2 = key_to_x(109.5, w);
    Gdk::Cairo::set_source_rgba(cr, white);
    cr->rectangle(x1 + 1, h1 + 1, x2 - x1 - 1, h - 2);
    cr->fill();

    Gdk::Cairo::set_source_rgba(cr, grey1);
    cr->rectangle(x2 + 1, h1 + 1, w - x2 - 1, h - 2);
    cr->fill();

    Gdk::Cairo::set_source_rgba(cr, black);

    int clipkey1 = std::max(0, x_to_key_right(clip_low - 1, w));
    int clipkey2 = std::min(x_to_key_right(clip_high - 1, w) + 1, 128);

    for (int i = clipkey1 ; i < clipkey2 ; i++) {
        int note = (i + 3) % 12;
        int x = key_to_x(i, w);

        if (note == 1 || note == 4 || note == 6 ||
            note == 9 || note == 11) {
            // black key: short line in the middle, with a rectangle
            // on top
            int x2 = key_to_x(i + 0.5, w);
            cr->move_to(x2 + 0.5, h1 + bh + 0.5);
            cr->line_to(x2 + 0.5, h1 + h - 1);
            cr->stroke();

            int x3 = key_to_x(i + 1, w);
            cr->rectangle(x, h1 + 1, x3 - x + 1, bh);
            cr->fill();
        } else if (note == 3 || note == 8) {
            // C or F: long line to the left
            cr->move_to(x + 0.5, h1 + 1);
            cr->line_to(x + 0.5, h1 + h - 1);
            cr->stroke();
        }

        if (key_pressed[i]) draw_key(cr, i);

        if (note == 3) draw_digit(cr, i);
    }
}
예제 #6
0
파일: wmsm.c 프로젝트: bbidulock/dockapps
static void draw_uptime(int day,int hour,int min,int sec)
{
    if(sec!=last.sec) {
	draw_digit(sec,48,51);
	last.sec=sec;
	if(min!=last.min) {
	    draw_digit(min,34,51);
	    last.min=min;
	    if(hour!=last.hour) {
		draw_digit(hour,20,51);
		last.hour=hour;
		if(day!=last.day) {
		    draw_digit(day,5,51);
		    last.day=day;
		}
	    }
	}
    }
}
예제 #7
0
파일: tm990189.c 프로젝트: antervud/MAMEHub
void tm990189_state::segment_set(int offset, bool state)
{
	if (state)
		m_segment |= 1 << offset;
	else
	{
		m_segment &= ~ (1 << offset);
		if ((m_displayena_timer->remaining() > attotime::zero)  && (m_digitsel < 10))
			draw_digit();
	}
}
예제 #8
0
void clock_draw_alien_ap( ttk_surface srf, clocks_globals *glob )
{
	int x;
	char buf[16];

	snprintf( buf, 16, "%02d%02d", glob->dispTime.tm_hour,
				       glob->dispTime.tm_min );
	for( x=0 ; x<4 ; x++ ) {
		draw_digit( srf, glob, x, buf[x]-'0', ALIEN_AP );
	}
}
예제 #9
0
파일: illudere.c 프로젝트: palian/illusion3
void display_layer_update_cb(Layer *me, GContext* ctx) {
  time_t now = time(NULL);
  struct tm *t = localtime(&now);

  unsigned short display_hour = get_display_hour(t->tm_hour);
  unsigned short display_min = t->tm_min;
  unsigned short display_sec = t->tm_sec;

  unsigned short row1, row2;
  if (DEBUG) {
    row1 = display_min;
    row2 = display_sec;
  } else {
    row1 = display_hour;
    row2 = display_min;
  }

  draw_rect(0, 0, TILES_X, TILES_Y, 0);
  draw_digit(row1/10, 0, 0);
  draw_digit(row1%10, 1, 0);
  draw_digit(row2/10, 0, 1);
  draw_digit(row2%10, 1, 1);

  // now redraw tiles that have changed
  for (size_t j = 0; j < TILES_Y; j++) {
    for (size_t i = 0; i < TILES_X; i++) {
      unsigned char v = frames[current_frame][i][j];
      // TODO: make this only redraw when tiles have changed. At the moment,
      // I am marking the entire display_layer as dirty which seems to mean
      // I have to repaint the whole thing. Probably what I want is is separate
      // layer for each tile?

      // if (v != frames[prev_frame][i][j]) {
        draw_tile(ctx, i, j, v == 1);
        frames[prev_frame][i][j] = v;
      // }
    }
  }

  swap(&current_frame, &prev_frame);
}
예제 #10
0
void draw_digit_clock(SDL_Surface *surface, int cx, int cy, int w, int dotRadius, Uint32 color, time_t temps) {
    const int largeurDigit = w/4;
    const int blinkeurSpacing = w * 0.09;

    struct tm *tempsLocal = localtime(&temps);
    char tempsStr[5];

    if(temps == NULL) {
        strcpy(tempsStr, "8888");
    } else {
        strftime(tempsStr, 5, "%H%M", tempsLocal);
    }

    draw_digit(surface, tempsStr[0], cx - (largeurDigit/2)*2 - largeurDigit - (largeurDigit/2.5), cy, w/4, dotRadius, color);
    draw_digit(surface, tempsStr[1], cx - (largeurDigit/2)*2, cy, w/4, dotRadius, color);

    if(temps == NULL || tempsLocal->tm_sec % 2) {
        draw_circle(surface, cx, cy - blinkeurSpacing, dotRadius, color);
        draw_circle(surface, cx, cy + blinkeurSpacing, dotRadius, color);
    }
    draw_digit(surface, tempsStr[2], cx + (largeurDigit/2)*2, cy, w/4, dotRadius, color);
    draw_digit(surface, tempsStr[3], cx + (largeurDigit/2)*2 + largeurDigit + (largeurDigit/2.5), cy, w/4, dotRadius, color);
}
static void canvas_update_proc(Layer *this_layer, GContext *ctx) {

  // calculate the width of the digit - 3 tile columns plus 2 one pixel gaps
  int digit_width = (3 * tile_size) + 2;
  
  // calculate the height of the digit - 5 tile rows plus 4 one pixel gaps
  int digit_height = (5 * tile_size) + 4;
      
    // set the fill colour
    graphics_context_set_fill_color(ctx, GColorWhite);
  
  
    // Get the current time
    time_t now = time(NULL);
    struct tm *t = localtime(&now);
  
    // draw four digits, grouped together in the center using the individual time digits
    
    // top left
    // divide hours by 10 to get first hour digit
    draw_digit(ctx, t->tm_hour/10, s_main_window_center.x-digit_width-(tile_size/2), s_main_window_center.y-digit_height-(tile_size/2));  
  
    // top right
    // get the remainder of dividing hours by 10 to get second hour digit
    draw_digit(ctx, t->tm_hour%10, s_main_window_center.x+(tile_size/2), s_main_window_center.y-digit_height-(tile_size/2));  
    
    // bottom left
    // divide minutes by 10 to get first minute digit
    draw_digit(ctx, t->tm_min/10, s_main_window_center.x-digit_width-(tile_size/2), s_main_window_center.y+(tile_size/2));  
  
    // bottom right
    // get remainder of dividing minutes by 10 to get second minute digit
    draw_digit(ctx, t->tm_min%10, s_main_window_center.x+(tile_size/2), s_main_window_center.y+(tile_size/2));  
  
  
}
예제 #12
0
/*
 * And this is where we will generate our digits
 * when we copy them with the DMA2D device we can
 * use the color lookup table to set the values.
 * in this case we'll use 0, 1, and 2 for background
 * foreground, and outline color.
 *
 * While the digits are kerned in the display they are
 * drawn here with a box that is DISP_WIDTH + SKEW_MAX
 * pixels wide, but DISP_HEIGHT pixels high.
 */
void
generate_digits(void)
{
	uint32_t i;
	gfx_init(digit_draw_pixel, DIGIT_FB_WIDTH, DIGIT_FB_HEIGHT, GFX_FONT_LARGE);
	/* Cleared to zero (background) */
	for (i = 0; i < sizeof(digit_fb); i++) {
		digit_fb[i] = 0;
	}
	for (i = 0; i < 10; i++) {
		draw_digit(i * (DISP_WIDTH + SKEW_MAX), 0, i, 1, 2);
	}
	draw_colon(10 * (DISP_WIDTH + SKEW_MAX), 0, 1, 2);
	draw_dp(10 * (DISP_WIDTH + SKEW_MAX) + SEG_THICK + SKEW_MAX, 0, 1, 2);
	/* now the digit_fb memory has the 10 digits 0-9, : and . in it */
}
예제 #13
0
static void update_proc(Layer *layer, GContext *ctx)
{
	graphics_context_set_stroke_color(ctx, GColorWhite);
	graphics_context_set_fill_color(ctx, GColorWhite);

	draw_digit(layer, ctx, 0, 2, now->tm_hour / 10);
	draw_digit(layer, ctx, 1, 4, now->tm_hour % 10);
	draw_digit(layer, ctx, 2, 3, now->tm_min  / 10);
	draw_digit(layer, ctx, 3, 4, now->tm_min  % 10);
#ifdef SHOW_SECONDS
	draw_digit(layer, ctx, 4, 3, now->tm_sec  / 10);
	draw_digit(layer, ctx, 5, 4, now->tm_sec  % 10);
#endif
}
예제 #14
0
파일: main.c 프로젝트: bbidulock/dockapps
/* called when mouse button pressed */
static void
switch_light(void)
{
    int h, i, j = hindex;
    int x = 0;

    switch (backlight) {
	case LIGHTOFF:
	    backlight = LIGHTON;
	    dockapp_copyarea(backdrop_on, pixmap, 0, 0, 58, 58, 0, 0);
	    x = 2;
	    break;
	case LIGHTON:
	    backlight = LIGHTOFF;
	    dockapp_copyarea(backdrop_off, pixmap, 0, 0, 58, 58, 0, 0);
	    x = 0;
	    break;
    }

    /* redraw digit */
    draw_digit(history[hindex]);

#ifdef USE_SMP
    /* draw cpu number */
    if (cpu_opts.cpu_number != CPUNUM_NONE)
	draw_cpunumber();
#endif

    /* redraw chart */
    for (i = 0; i < MAX_HISTORY; i++) {
	h = (21 * history[j]) / 100;
	dockapp_copyarea(parts, pixmap, 100+x, 21-h, 2, h, 51-3*i, 54-h);
	j--;
	if (j < 0) j = MAX_HISTORY - 1;
    }

    /* show */
    dockapp_copy2window(pixmap);
}
예제 #15
0
void RegionChooser::draw_region(int from, int to, const Gdk::Color& color)
{
    const int h = KEYBOARD_HEIGHT;
    const int w = get_width() - 1;
    const int bh = int(h * 0.55);

    Glib::RefPtr<Gdk::Window> window = get_window();
    gc->set_foreground(color);

    for (int i = from ; i < to ; i++) {
        int note = (i + 3) % 12;
        int x = int(w * i / 128.0 + 0.5) + 1;
        int x2 = int(w * (i + 1.5) / 128.0 + 0.5);
        int x3 = int(w * (i + 1) / 128.0 + 0.5);
        int x4 = int(w * (i - 0.5) / 128.0 + 0.5);
        int w1 = x3 - x;
        switch (note) {
        case 0: case 5: case 10:
            window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);
            window->draw_rectangle(gc, true, x4 + 1, h1 + bh + 1, x2 - x4 - 1, h - bh - 2);
            break;
        case 2: case 7:
            window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);
            window->draw_rectangle(gc, true, x4 + 1, h1 + bh + 1, x3 - x4 - 1, h - bh - 2);
            break;
        case 3: case 8:
            window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);
            window->draw_rectangle(gc, true, x, h1 + bh + 1, x2 - x, h - bh - 2);
            if (note == 3) draw_digit(i);
            break;
        default:
            window->draw_rectangle(gc, true, x, h1 + 1, w1, bh - 1);
            break;
        }
    }
}
예제 #16
0
bool RegionChooser::on_expose_event(GdkEventExpose* event)
{
    Glib::RefPtr<Gdk::Window> window = get_window();
    window->clear();
    const int h = KEYBOARD_HEIGHT;
    const int w = get_width() - 1;
    const int bh = int(h * 0.55);

    Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();
    Glib::RefPtr<const Gdk::GC> white = get_style()->get_white_gc();

    window->draw_rectangle(black, false, 0, h1, w, h - 1);
    gc->set_foreground(grey1);
    int x1 = int(w * 20.5 / 128.0 + 0.5);
    int x2 = int(w * 109.5 / 128.0 + 0.5);
    window->draw_rectangle(gc, true, 1, h1 + 1,
                           x1 - 1, h - 2);
    window->draw_rectangle(white, true, x1 + 1, h1 + 1, x2 - x1 - 1, h - 2);
    window->draw_rectangle(gc, true, x2 + 1, h1 + 1,
                           w - x2 - 1, h - 2);
    for (int i = 0 ; i < 128 ; i++) {
        int note = (i + 3) % 12;
        int x = int(w * i / 128.0 + 0.5);

        if (note == 1 || note == 4 || note == 6 || note == 9 || note == 11) {
            int x2 = int(w * (i + 0.5) / 128.0 + 0.5);
            window->draw_line(black, x2, h1 + bh, x2, h1 + h);

            int x3 = int(w * (i + 1) / 128.0 + 0.5);
            window->draw_rectangle(black, true, x, h1 + 1, x3 - x + 1, bh);
        } else if (note == 3 || note == 8) {
            window->draw_line(black, x, h1 + 1, x, h1 + h);
        }
        if (note == 3) draw_digit(i);
    }

    if (instrument) {
        int i = 0;
        gig::Region *next_region;
        int x3 = -1;
        for (gig::Region *r = regions.first() ; r ; r = next_region) {

            if (x3 < 0) x3 = int(w * (r->KeyRange.low) / 128.0 + 0.5);
            next_region = regions.next();
            if (!next_region || r->KeyRange.high + 1 != next_region->KeyRange.low) {
                int x2 = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5);
                window->draw_line(black, x3, 0, x2, 0);
                window->draw_line(black, x3, h1 - 1, x2, h1 - 1);
                window->draw_line(black, x2, 1, x2, h1 - 2);
                window->draw_rectangle(white, true, x3 + 1, 1, x2 - x3 - 1, h1 - 2);
                x3 = -1;
            }
            i++;
        }

        for (gig::Region *r = regions.first() ; r ; r = regions.next()) {
            int x = int(w * (r->KeyRange.low) / 128.0 + 0.5);
            window->draw_line(black, x, 1, x, h1 - 2);
        }

        if (region) {
            int x1 = int(w * (region->KeyRange.low) / 128.0 + 0.5);
            int x2 = int(w * (region->KeyRange.high + 1) / 128.0 + 0.5);
            gc->set_foreground(red);
            window->draw_rectangle(gc, true, x1 + 1, 1, x2 - x1 - 1, h1 - 2);
        }
    }
    return true;
}
예제 #17
0
파일: main.c 프로젝트: bbidulock/dockapps
/* called by timer */
static void
update(void)
{
    int usage;
    int x, h;

    static light pre_backlight;
    static Bool in_alarm_mode = False;

    /* get current cpu usage in percent */
    usage = cpu_get_usage(&cpu_opts);
    hindex++;
    if (hindex >= MAX_HISTORY) {
	hindex = 0;
    }
    history[hindex] = usage;

    /* alarm mode */
    if (usage >= alarm_threshold) {
	if (!in_alarm_mode) {
	    in_alarm_mode = True;
	    pre_backlight = backlight;
	}
	if (backlight == LIGHTOFF) {
	    switch_light();
	    return;
	}
    } else {
	if (in_alarm_mode) {
	    in_alarm_mode = False;
	    if (backlight != pre_backlight) {
		switch_light();
		return;
	    }
	}
    }

    /* save current chart */
    dockapp_copyarea(pixmap, pix_chartbuf,  9, 33, 44, 21, 0, 0);

    /* all clear */
    if (backlight == LIGHTON) {
	dockapp_copyarea(backdrop_on, pixmap, 0, 0, 58, 58, 0, 0);
	x = 2;
    } else {
	dockapp_copyarea(backdrop_off, pixmap, 0, 0, 58, 58, 0, 0);
	x = 0;
    }

    /* draw digit */
    draw_digit(usage);

#ifdef USE_SMP
    /* draw cpu number */
    if (cpu_opts.cpu_number != CPUNUM_NONE)
	draw_cpunumber();
#endif

    /* draw chart */
    h = (21 * usage) / 100;
    dockapp_copyarea(pix_chartbuf, pixmap, 0, 0, 44, 21, 6, 33);
    dockapp_copyarea(parts, pixmap,100+x, 21-h, 2, h, 51, 54-h);

    /* show */
    dockapp_copy2window(pixmap);

}
예제 #18
0
/*
 * This is the code for the simple DMA2D Demo
 *
 * Basically it lets you put display digits on the
 * screen manually or with the DMA2D peripheral. It
 * has various 'bling' levels, and it tracks performance
 * by measuring how long it takes to go from one frame
 * to the next.
 */
int
main(void) {
	int	i;
	uint32_t t1, t0;
	char buf[35];
	char *scr_opt;
	int f_ndx = 0;
	float avg_frame;
	int	can_switch;
	int	opt, ds;

	/* Enable the clock to the DMA2D device */
	rcc_periph_clock_enable(RCC_DMA2D);
	fprintf(stderr, "DMA2D Demo program : Digits Gone Wild\n");
	printf("Generate background\n");
	generate_background();
	printf("Generate digits\n");
	generate_digits();

	gfx_init(lcd_draw_pixel, 800, 480, GFX_FONT_LARGE);
	opt = 0; /* screen clearing mode */
	can_switch = 0; /* auto switching every 10 seconds */
	t0 = mtime();
	ds = 0;
	while (1) {
		switch (opt) {
		default:
		case 0:
			/* very slow way to clear the screen */
			scr_opt = "manual clear";
			gfx_fillScreen(0xffff);
			break;
		case 1:
			/* faster, using a tight loop */
			scr_opt = "dedicated loop";
			lcd_clear(0xff7f7f);
			break;
		case 2:
			/* fastest? Using DMA2D to fill screen */
			scr_opt = "DMA 2D Fill";
			dma2d_fill(0xff7fff7f);
			break;
		case 3:
			/* still fast, using DMA2D to pre-populate BG */
			scr_opt = "DMA 2D Background";
			dma2d_bgfill();
			break;
		case 4:
			/* Now render all of the digits with DMA2D */
			scr_opt = "DMA 2D Digits";
			ds = 0;
			dma2d_bgfill();
			break;
		case 5:
			/* still fast, using DMA2D to render drop shadows */
			scr_opt = "DMA 2D Shadowed Digits";
			ds = 1;
			dma2d_bgfill();
			break;
		}

		/* This little state machine implements an automatic switch
		 * every 10 seconds unless you've disabled it with the 'd'
		 * command.
		 */
		if (((t0 / 1000) % 10 == 0) && (can_switch > 0)) {
			opt = (opt + 1) % MAX_OPTS;
			can_switch = 0;
		} else  if (((t0 / 1000) % 10 != 0) && (can_switch == 0)) {
			can_switch = 1;
		}

		/*
		 * The first four options (0, 1, 2, 3) all render the digits
		 * in software every time, options 4 and 5 use the DMA2
		 * device to render the digits
		 */
		if (opt < 4) {
			display_clock(25, 20, mtime());
		} else {
			dma2d_clock(25, 20, mtime(), ds);
		}
		for (i = 0; i < 10; i++) {
			if (opt < 4) {
				draw_digit(25 + i * (DISP_WIDTH + 8), 350, i, GFX_COLOR_GREEN, GFX_COLOR_BLACK);
			} else {
				if (ds) {
					dma2d_digit(35 + i * (DISP_WIDTH + 8), 360, i, SHADOW, SHADOW);
				}
				dma2d_digit(25 + i * (DISP_WIDTH + 8), 350, i, 0xff40c040, 0xff000000);
			}
		}

		/* In both cases we write the notes using the graphics library */
		gfx_setTextColor(0, 0);
		gfx_setTextSize(3);
		gfx_setCursor(25, 30 + DISP_HEIGHT + gfx_getTextHeight() + 2);
		gfx_puts((unsigned char *)"Hello world for DMA2D!");
		lcd_flip(te_lock);
		t1 = mtime();

		/* this computes a running average of the last 10 frames */
		frame_times[f_ndx] = t1 - t0;
		f_ndx = (f_ndx + 1) % N_FRAMES;
		for (i = 0, avg_frame = 0; i < N_FRAMES; i++) {
			avg_frame += frame_times[i];
		}
		avg_frame = avg_frame / (float) N_FRAMES;
		snprintf(buf, 35, "FPS: %6.2f", 1000.0 / avg_frame);
		gfx_setCursor(25, 30 + DISP_HEIGHT + 2 * (gfx_getTextHeight() + 2));
		gfx_puts((unsigned char *)buf);
		gfx_puts((unsigned char *)" ");
		gfx_setCursor(25, 30 + DISP_HEIGHT + 3 * (gfx_getTextHeight() + 2));
		gfx_puts((unsigned char *)scr_opt);
		/*
		 * The demo runs continuously but it watches for characters
		 * typed at the console. There are a few options you can select.
		 */
		i = console_getc(0);
		switch (i) {
		case 's':
			opt = (opt + 1) % MAX_OPTS;
			printf("Switched to : %s\n", demo_options[opt]);
			break;
		case 'd':
			can_switch = -1;
			printf("Auto switching disabled\n");
			break;
		case 'e':
			can_switch = 0;
			printf("Auto switching enabled\n");
			break;
		case 't':
			te_lock = (te_lock == 0);
			printf("We are %s for the TE bit to be set\n", (te_lock) ? "WAITING" : "NOT WAITING");
			break;
		default:
			printf("Options:\n");
			printf("\ts - switch demo mode\n");
			printf("\td - disable auto-switching of demo mode\n");
			printf("\te - enable auto-switching of demo mode\n");
			printf("\tt - enable/disable Tearing effect lock wait\n");
		case 0:
			break;
		}
		t0 = t1;
	}
}