void viewTOTPcode(totp* tkn) { unsigned short key = 0; int keyCol, keyRow; Bdisp_AllClr_VRAM(); drawScreenTitle(tkn->name); int shown_since_beginning = 0; while(key != KEY_PRGM_EXIT && key != KEY_PRGM_LEFT) { int ThirtySecCode = computeTOTP(tkn); char buffer[10]; itoa_zeropad(tkn->totpcode, buffer, 6); long long int ms_spent_ll = currentUTCUEBT() - (long long int)ThirtySecCode * 30LL * 1000LL; int ms_spent = (int)(ms_spent_ll); drawCircularCountdownIndicator(LCD_WIDTH_PX/2, 104, 44, COLOR_BLACK, COLOR_WHITE, (ms_spent*43)/30000, getCurrentSecond() < 30 ? 0 : 1); // fade in/out animation for text int val = 0; if(ms_spent >= 29000) { val += (-29000 + ms_spent)/4; } else if (ms_spent <= 1020) { val += (1020 - ms_spent)/4; } int color = drawRGB24toRGB565(val, val, val); printCentered(buffer, 164, color, COLOR_WHITE); if(ms_spent < 2500) shown_since_beginning = 1; else if(ms_spent < 15000 && shown_since_beginning) DefineStatusMessage((char*)totpHelpMessages[(ms_spent-2500)/2500], 1, 0, 0); else DefineStatusMessage((char*)"", 1, 0, 0); DisplayStatusArea(); Bdisp_PutDisp_DD(); key = PRGM_GetKey(); if(key == KEY_PRGM_MENU) GetKeyWait_OS(&keyCol, &keyRow, 2, 0, 0, &key); //this is here to handle the Menu key if(key == KEY_PRGM_OPTN) { DefineStatusMessage((char*)"", 1, 0, 0); GetKeyWait_OS(&keyCol, &keyRow, 2, 0, 0, &key); // clear keybuffer RTCunadjustedWizard(0, 1); setTimezone(); return; // so we don't have to redraw etc. // Also, this way the Shift+Menu instruction shown in the adjustment wizard becomes vali // immediately, which is great if the user wants to repeat the adjustment. } } DefineStatusMessage((char*)"", 1, 0, 0); // clear keybuffer: GetKeyWait_OS(&keyCol, &keyRow, 2, 0, 0, &key); }
void draw_rb_incorrect_note_at(alt_up_pixel_buffer_dma_dev* pixel_buffer, int location, int x_location) // FUNCTION: Draws the template for an incorrect note in the rock band game mode to the back buffer. // Doesn't write the pitch to the char buffer. This is done inside the update_rb function. // REQUIRES: 1 <= location <= 60 // RETURNS: None { /* // Draw double thickness square in black alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, x_location*4 - 9, location*4 - 12, x_location*4 + 11, location*4 + 8,0x0000, 1); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, x_location*4 - 8, location*4 - 11, x_location*4 + 10, location*4 + 7,0x0000, 1); */ // Fill the inside in green uint16_t fill_colour = drawRGB24toRGB565(0x66, 0x33, 0x00); // Brown cave colour alt_up_pixel_buffer_dma_draw_box(pixel_buffer, x_location*4 - 7, location*4 - 10, x_location*4 + 9, location*4 + 6, fill_colour, 1); }
void welcomeScreen(){ drawFill(drawRGB24toRGB565(nwazetYellowRed, nwazetYellowGreen, nwazetYellowBlue)); lcdSetWindow( 49, 49 + (142 - 1), 82, 82 + (156 - 1)); unsigned short imageSize = 44304; unsigned short* imagePixel = (unsigned short*) &nwazetLogo[0]; while(imageSize){ lcdWriteData(*imagePixel); imagePixel++; imageSize -= 2; } unsigned short y = 10; unsigned short spaceBetweenLines = 2; printString("Touch Display", y); y+=verdanabold14ptFontInfo.height+spaceBetweenLines; printString("By [nwazet", y); y = 295; printString("Raspberry Pi v0.1", y); }
bmp_error_t bmpParseBitmap(uint16_t x, uint16_t y, FIL file) { UINT bytesRead; bmp_header_t header; bmp_infoheader_t infoHeader; // Read the file header // ToDo: Optimise this to read buffer once and parse it f_read(&file, &header.type, sizeof(header.type), &bytesRead); f_read(&file, &header.size, sizeof(header.size), &bytesRead); f_read(&file, &header.reserved1, sizeof(header.reserved1), &bytesRead); f_read(&file, &header.reserved2, sizeof(header.reserved2), &bytesRead); f_read(&file, &header.offset, sizeof(header.offset), &bytesRead); // Make sure this is a bitmap (first two bytes = 'BM' or 0x4D42 on little-endian systems) if (header.type != 0x4D42) return BMP_ERROR_NOTABITMAP; // Read the info header // ToDo: Optimise this to read buffer once and parse it f_read(&file, &infoHeader.size, sizeof(infoHeader.size), &bytesRead); f_read(&file, &infoHeader.width, sizeof(infoHeader.width), &bytesRead); f_read(&file, &infoHeader.height, sizeof(infoHeader.height), &bytesRead); f_read(&file, &infoHeader.planes, sizeof(infoHeader.planes), &bytesRead); f_read(&file, &infoHeader.bits, sizeof(infoHeader.bits), &bytesRead); f_read(&file, &infoHeader.compression, sizeof(infoHeader.compression), &bytesRead); f_read(&file, &infoHeader.imagesize, sizeof(infoHeader.imagesize), &bytesRead); f_read(&file, &infoHeader.xresolution, sizeof(infoHeader.xresolution), &bytesRead); f_read(&file, &infoHeader.yresolution, sizeof(infoHeader.yresolution), &bytesRead); f_read(&file, &infoHeader.ncolours, sizeof(infoHeader.ncolours), &bytesRead); f_read(&file, &infoHeader.importantcolours, sizeof(infoHeader.importantcolours), &bytesRead); // Make sure that this is a 24-bit image if (infoHeader.bits != 24) return BMP_ERROR_INVALIDBITDEPTH; // Check image dimensions if ((infoHeader.width > lcdGetWidth()) | (infoHeader.height > lcdGetHeight())) return BMP_ERROR_INVALIDDIMENSIONS; // Make sure image is not compressed if (infoHeader.compression != BMP_COMPRESSION_NONE) return BMP_ERROR_COMPRESSEDDATA; // Read 24-bit image data uint32_t px, py; FRESULT res; uint8_t buffer[infoHeader.width * 3]; for (py = infoHeader.height; py > 0; py--) { // Read one row at a time res = f_read(&file, &buffer, infoHeader.width * 3, &bytesRead); if (res || bytesRead == 0) { // Error or EOF return BMP_ERROR_PREMATUREEOF; } for (px = 0; px < infoHeader.width; px++) { // Render pixel // ToDo: This is a brutally slow way of rendering bitmaps ... // update to pass one row of data at a time drawPixel(x + px, y + py - 1, drawRGB24toRGB565(buffer[(px * 3) + 2], buffer[(px * 3) + 1], buffer[(px * 3)])); } } return BMP_ERROR_NONE; }
int update_eq_sinc(int amplitude, int green) // FUNCTION: Updates the equaliser for pretty graphics and swaps the pixel buffer // REQUIRES: Initialised pixel buffer // RETURNS: New green value { // Declare variables int i, j, red, blue, height, y_value, original_top, x_axis, x_value; float period = ((rand() % 200) + 600.0) / 100.0; // Randomly generate period between 6.0 and 8.0 uint16_t colour; int random_amplitude; float random_period; if(/* alt_timestamp()/(float) alt_timestamp_freq() > EQ_TIME_CONSTANT_S && */ m == eq) { v.blank_flag = FALSE; rb.background_flag = FALSE; alt_up_char_buffer_clear(v.char_buffer); random_amplitude = (rand() % 50) + 50; random_period = ((rand() % 200) + 600.0) / 100.0; printf("Random amplitude: %d\n", random_amplitude); if(rand() % 1 == 0) { if(green < 251) green += 5; } else if(green > 5) green -= 5; alt_up_pixel_buffer_dma_clear_screen(v.pixel_buffer, 1); // Clear back buffer x_axis = 190; original_top = x_axis - x_axis*amplitude/MAX_AMPLITUDE; for(x_value=0; x_value < 160; x_value++) // Draw two-sided sinc function, almost to each side of the screen { red = 255*(160-x_value)/160; // red will increase towards the middle of the screen // Calculate value of the sinc function for x-coordinate x_value if(x_value>0) height = (x_axis*amplitude/MAX_AMPLITUDE)*sin(x_value/period) /(x_value/period); else height = x_axis*amplitude/MAX_AMPLITUDE; y_value = x_axis - height; if(height>0) // This means the sinc function is above the x-axis { for(j=y_value; j<=x_axis; j++) // j is the y-coordinate { blue = 255*(j - original_top)/(x_axis*amplitude/MAX_AMPLITUDE); // blue will increase towards the x_axis of the screen colour = drawRGB24toRGB565(red, green, blue); i=160-x_value; // i is the x-coordinate alt_up_pixel_buffer_dma_draw(v.pixel_buffer, colour, i, j); i=160+x_value; // i is the x-coordinate alt_up_pixel_buffer_dma_draw(v.pixel_buffer, colour, i, j); } } else // This means the sinc function is on or below the x-axis { for(j=y_value; j>=x_axis; j--) // j is the y-coordinate { blue = 255*(2*x_axis-j - original_top)/(x_axis*amplitude/MAX_AMPLITUDE); // blue will increase towards the x_axis of the screen colour = drawRGB24toRGB565(red, green, blue); i=160-x_value; // i is the x-coordinate alt_up_pixel_buffer_dma_draw(v.pixel_buffer, colour, i, j); i=160+x_value; // i is the x-coordinate alt_up_pixel_buffer_dma_draw(v.pixel_buffer, colour, i, j); } } } // Swap buffers alt_up_pixel_buffer_dma_swap_buffers(v.pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(v.pixel_buffer)); // alt_timestamp_start(); } return green; }