void gfx_init() { int cnt, err; if (gfxInitialized) return; gfxInitialized = 1; scale = INITIAL_SCALE; emu_window_width = INITIAL_SCALE * selected_model->pixel_width; emu_window_height = INITIAL_SCALE * selected_model->pixel_height; bws = malloc(selected_model->text_width * selected_model->text_height); lineWidth = selected_model->pixel_width / 8; lines = selected_model->pixel_height; pixelRamSize = lineWidth * lines; pixelRam = malloc(pixelRamSize); colorRamSize = selected_model->text_width * selected_model->text_height; colorRam = malloc(colorRamSize); cutBuffer = malloc( selected_model->text_width * selected_model->text_height + selected_model->text_height); for (cnt = 0; cnt < selected_model->text_width * selected_model->text_height; cnt++) { bws[cnt] = rand() & 0xff; colorRam[cnt] = rand() & 0xff; } for (cnt = 0; cnt < selected_model->pixel_width / 8 * selected_model->pixel_height; cnt++) { pixelRam[cnt] = rand() & 0xff; } err = pthread_create(&(tid), NULL, &doSomeThing, NULL); if (err != 0) { printf("can't create thread :[%s]\n", strerror(err)); } else { printf("UI-Thread created successfully\n"); } while (!initialized) { } printf("UI-Thread initialized\n"); gfx_putchar(0x0c); gfx_putchar(0x0d); gfx_putchar(0x0d); gfx_puts("Z1013+K7659/2.028 RB"); gfx_putchar(0x0d); gfx_puts(" # J 100"); gfx_putchar(0x0d); }
/* * Callback function when APP_ERROR_CHECK() fails * * - Display the filename, line number and error code. * - Flash all neopixels red for 5 seconds. * - Reset the system. */ void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) { static int error_displayed = 0; uint8_t count = 50; if(!error_displayed) { char error_msg[128]; error_info_t *err_info = (error_info_t *) info; snprintf(error_msg, sizeof(error_msg), "%s:%u -> error 0x%08x\r\n", err_info->p_file_name, (unsigned int)err_info->line_num, (unsigned int)err_info->err_code); puts(error_msg); gfx_setCursor(0, 0); gfx_puts(error_msg); gfx_update(); error_displayed = 1; } init_WS2812FX(); setBrightness_WS2812FX(64); setSpeed_WS2812FX(200); setColor_WS2812FX(255, 0, 0); setMode_WS2812FX(FX_MODE_BLINK); start_WS2812FX(); while (count > 0) { service_WS2812FX(); nrf_delay_ms(100); count--; } NVIC_SystemReset(); }
void show_warning(void) { gfx_fillRect(0, 8, 128, 56, SSD1306_BLACK); gfx_setCursor(0, 8); // We calculate the number of character we can use // we keep that value for scrolling char buffer[MAX_CHAR_UNDER_STATUS_BAR] = {0}; text_index = MAX_CHAR_UNDER_STATUS_BAR; strncpy(buffer, warning_notice, text_index); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(buffer); gfx_update(); }
void show_actual_control(void) { bool control = isRunning_WS2812FX(); char actual[10] = {0}; if (control) { snprintf(actual, 50, "Now: %s", "ON"); } else { snprintf(actual, 50, "Now: %s", "OFF"); } gfx_fillRect(12, 20, 128, 65, SSD1306_BLACK); gfx_setCursor(0, 12); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(actual); }
void show_actual_reverse(void) { bool reverse = getReverse_WS2812FX(); char actual[10] = {0}; if (reverse) { snprintf(actual, 50, "Now: %s", "True"); } else { snprintf(actual, 50, "Now: %s", "False"); } gfx_fillRect(12, 20, 128, 65, SSD1306_BLACK); gfx_setCursor(0, 12); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(actual); }
/* * Callback function when the battery status timeout expires */ static void battery_status_timeout_handler(void *p_context) { char msg[256]; gfx_fillRect(0, 8, 128, 56, SSD1306_BLACK); gfx_setCursor(0, 12); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); snprintf(msg, sizeof(msg), "Battery status:\n" " Voltage: %04d mV\n" " Charging: %s\n" " USB plugged: %s\n", battery_get_voltage(), battery_is_charging() ? "Yes" : "No", battery_is_usb_plugged() ? "Yes" : "No"); gfx_puts(msg); gfx_update(); }
void scroll_down_warning(bool change_direction) { if (text_index > strlen(warning_notice)) { return; } gfx_fillRect(0, 8, 128, 56, SSD1306_BLACK); gfx_setCursor(0, 8); if (change_direction) { text_index += MAX_CHAR_UNDER_STATUS_BAR; } char buffer[MAX_CHAR_UNDER_STATUS_BAR] = {0}; strncpy(buffer, warning_notice + text_index, MAX_CHAR_UNDER_STATUS_BAR); text_index += MAX_CHAR_UNDER_STATUS_BAR; gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(buffer); gfx_update(); }
void show_actual_speed(void) { uint16_t speed = getSpeed_WS2812FX(); char actual[50] = {0}; if (speed >= SUPER_SLOW_SPEED) { snprintf(actual, 50, "Now: %s", "Super slow"); } else if (speed >= SLOW_SPEED) { snprintf(actual, 50, "Now: %s", "Slow"); } else if (speed >= MEDIUM_SPEED) { snprintf(actual, 50, "Now: %s", "Medium"); } else if (speed >= FAST_SPEED) { snprintf(actual, 50, "Now: %s", "Fast"); } else { snprintf(actual, 50, "Now: %s", "Super fast"); } gfx_fillRect(12, 20, 128, 65, SSD1306_BLACK); gfx_setCursor(0, 12); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(actual); }
void show_actual_brightness(void) { uint8_t brightness = getBrightness_WS2812FX(); char actual[50] = {0}; if (brightness <= SUPER_LOW_BRIGHTNESS) { snprintf(actual, 50, "Now: %s", "Super Low"); } else if (brightness <= LOW_BRIGHTNESS) { snprintf(actual, 50, "Now: %s", "Low"); } else if (brightness <= MEDIUM_BRIGHTNESS) { snprintf(actual, 50, "Now: %s", "Medium"); } else if (brightness <= HIGH_BRIGHTNESS) { snprintf(actual, 50, "Now: %s", "High"); } else { snprintf(actual, 50, "Now: %s", "Max"); } gfx_fillRect(12, 20, 128, 65, SSD1306_BLACK); gfx_setCursor(0, 12); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(actual); }
void show_actual_color(void) { uint32_t color; if (_state == SETTING_STATE_FIRST_COLOR) { color = getArrayColor_WS2812FX(0); } else if (_state == SETTING_STATE_SECOND_COLOR) { color = getArrayColor_WS2812FX(1); } else { color = getArrayColor_WS2812FX(2); } char actual[50] = {0}; if (color == RED) { snprintf(actual, 50, "Now: %s", "Red"); } else if (color == GREEN) { snprintf(actual, 50, "Now: %s", "Green"); } else if (color == BLUE) { snprintf(actual, 50, "Now: %s", "Blue"); } else if (color == WHITE) { snprintf(actual, 50, "Now: %s", "White"); } else if (color == BLACK) { snprintf(actual, 50, "Now: %s", "Black"); } else if (color == YELLOW) { snprintf(actual, 50, "Now: %s", "Yellow"); } else if (color == CYAN) { snprintf(actual, 50, "Now: %s", "Cyan"); } else if (color == PURPLE) { snprintf(actual, 50, "Now: %s", "Purple"); } else { snprintf(actual, 50, "Now: %s", "Orange"); } gfx_fillRect(12, 20, 128, 65, SSD1306_BLACK); gfx_setCursor(0, 12); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(actual); }
/* * 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; } }