void setup(void) { Serial.begin(9600); // If your TFT's plastic wrap has a Red Tab, use the following: tft.initR(INITR_REDTAB); // initialize a ST7735R chip, red tab // If your TFT's plastic wrap has a Green Tab, use the following: //tft.initR(INITR_GREENTAB); // initialize a ST7735R chip, green tab // how much memory have we got left at this point? Serial.print("Avail mem (bytes):"); Serial.println(AVAIL_MEM); Serial.print("Initializing SD card..."); if (!SD.begin(SD_CS)) { Serial.println("failed!"); return; } Serial.println("OK!"); // clear to yellow tft.fillScreen(tft.Color565(0xff, 0xff, 0x00)); lcd_image_draw(&map_image, &tft, 0, 0, 0, 0, 128, 128); // how much memory have we got left at this point? Serial.print("Avail mem (bytes):"); Serial.println(AVAIL_MEM); // test out reading blocks from the SD card if (!card.init(SPI_HALF_SPEED, SD_CS)) { Serial.println("Raw SD Initialization has failed"); while (1) {}; // Just wait, stuff exploded. } // how much memory have we got left at this point? Serial.print("Avail mem (bytes):"); Serial.println(AVAIL_MEM); uint32_t block_num = 4000000; uint32_t start = millis(); for (int l=0; l<135; l++) { card.readBlock( block_num, (uint8_t *) block_buf); // Serial.println(block_buf[1].name); } uint32_t stop = millis(); //Serial.println(stop - start); //dump_block((uint8_t *) block_buf, BLOCK_LEN); // Serial.println(block_buf[1].name); for(int i = 0; i < 1066; i++) { printRest(i); } }
void draw_path(uint16_t length, coord_t path[]) { for (int i = 0; i < length-1; ++i) { //get coords int x1 = longitude_to_x(current_map_num, path[ i ].lon) - screen_map_x; int y1 = latitude_to_y( current_map_num, path[ i ].lat) - screen_map_y; int x2 = longitude_to_x(current_map_num, path[i+1].lon) - screen_map_x; int y2 = latitude_to_y( current_map_num, path[i+1].lat) - screen_map_y; //clipping //draw tft.drawLine(x1, y1, x2, y2, tft.Color565(255,0,0)); } }
void bmpDraw(Adafruit_ST7735 tft, String fileName, uint8_t x, uint8_t y) { file_t handle; int bmpWidth, bmpHeight; // W+H in pixels uint8_t bmpDepth; // Bit depth (currently must be 24) uint32_t bmpImageoffset; // Start of image data in file uint32_t rowSize; // Not always = bmpWidth; may have padding uint8_t sdbuffer[3 * BUFFPIXEL]; // pixel buffer (R+G+B per pixel) uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer boolean goodBmp = false; // Set to true on valid header parse boolean flip = true; // BMP is stored bottom-to-top int w, h, row, col; uint8_t r, g, b; uint32_t pos = 0, startTime = millis(); if ((x >= tft.width()) || (y >= tft.height())) return; Serial.println(); Serial.print("Loading image '"); Serial.print(fileName); Serial.println('\''); handle = fileOpen(fileName.c_str(), eFO_ReadOnly); if (handle == -1) { debugf("File wasn't found: %s", fileName.c_str()); fileClose(handle); return; } // Parse BMP header if (read16(handle) == 0x4D42) { // BMP signature debugf("File size: %d\n", read32(handle)); // get File Size (void)read32(handle); // Read & ignore creator bytes bmpImageoffset = read32(handle); // Start of image data debugf("Image Offset: %d\n", bmpImageoffset); debugf("Header size: %d\n", read32(handle)); // Read DIB header bmpWidth = read32(handle); bmpHeight = read32(handle); if(read16(handle) == 1) { // # planes -- must be '1' bmpDepth = read16(handle); // bits per pixel debugf("Bit Depth: %d\n", bmpDepth); if((bmpDepth == 24) && (read32(handle) == 0)) { // 0 = uncompressed goodBmp = true; // Supported BMP format -- proceed! debugf("Image size: %d x %d\n", bmpWidth, bmpHeight); // BMP rows are padded (if needed) to 4-byte boundary rowSize = (bmpWidth * 3 + 3) & ~3; // If bmpHeight is negative, image is in top-down order. // This is not canon but has been observed in the wild. if(bmpHeight < 0) { bmpHeight = -bmpHeight; flip = false; } // Crop area to be loaded w = bmpWidth; h = bmpHeight; if((x+w-1) >= tft.width()) w = tft.width() - x; if((y+h-1) >= tft.height()) h = tft.height() - y; // Set TFT address window to clipped image bounds tft.setAddrWindow(x, y, x+w-1, y+h-1); for (row=0; row<h; row++) { // For each scanline... // Seek to start of scan line. It might seem labor- // intensive to be doing this on every line, but this // method covers a lot of gritty details like cropping // and scanline padding. Also, the seek only takes // place if the file position actually needs to change // (avoids a lot of cluster math in SD library). if(flip) // Bitmap is stored bottom-to-top order (normal BMP) pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize; else // Bitmap is stored top-to-bottom pos = bmpImageoffset + row * rowSize; if (fileTell(handle) != pos) { fileSeek(handle, pos, eSO_FileStart); buffidx = sizeof(sdbuffer); // Force buffer reload } for (col=0; col<w; col++) { // For each pixel... // Time to read more pixel data? if (buffidx >= sizeof(sdbuffer)) { // Indeed fileRead(handle, sdbuffer, sizeof(sdbuffer)); buffidx = 0; // Set index to beginning } // Convert pixel from BMP to TFT format, push to display b = sdbuffer[buffidx++]; g = sdbuffer[buffidx++]; r = sdbuffer[buffidx++]; tft.pushColor(tft.Color565(r,g,b)); } // end pixel } // end scanline Serial.printf("Loaded in %d ms\n", millis() - startTime); } // end goodBmp } } fileClose(handle); if(!goodBmp) Serial.println("BMP format not recognized."); }
void drawMap() { // clear to yellow tft.fillScreen(tft.Color565(0xff, 0xff, 0x00)); lcd_image_draw(&map_image, &tft, 0, 0, 0, 0, 128, 128); }
void setup(void) { Serial.begin(9600); // set buttonPin to INPUT and // turn on internal pull up resistor pinMode(BUTTJOY, INPUT); digitalWrite(BUTTJOY, HIGH); // establish interrupts on joystick button falling (when the button is initially pushed) // NOTE: BUTTJOY has been set up with a debounced circut attachInterrupt(BUTTJOY, buttonPress, FALLING); // Define the cursor radius to be 2 pixles cursor.r = CURSOR_RADIUS; // Read initial joystick position iniJoy.x = analogRead(HORZJOY); iniJoy.y = analogRead(VERTJOY); // If your TFT's plastic wrap has a Red Tab, use the following: tft.initR(INITR_REDTAB); // initialize a ST7735R chip, red tab // If your TFT's plastic wrap has a Green Tab, use the following: //tft.initR(INITR_GREENTAB); // initialize a ST7735R chip, green tab #if DEBUG Serial.print("Initializing SD card..."); #endif if (!SD.begin(SD_CS)) { Serial.println("failed!"); return; } #if DEBUG Serial.println("OK!"); #endif // test out reading blocks from the SD card if (!card.init(SPI_HALF_SPEED, SD_CS)) { #if DEBUG Serial.println("Raw SD Initialization has failed"); #endif while (1) {}; // Just wait, stuff exploded. } // Centers map on pre-selected coord m_map.x = m_map.x - tft.width()/2; m_map.y = m_map.y - tft.height()/2; // Places cursor in the center of the screen cursor.position.x = (int) tft.width()/2.; cursor.position.y = (int) tft.height()/2.; // clear to blue tft.fillScreen(tft.Color565(137, 207, 240)); // Added for debug purposes #if DEBUG Serial.print("TFT Height: "); Serial.print( tft.height() ); Serial.print(", TFT Width: "); Serial.println( tft.width() ); #endif // Draw initial screen lcd_image_draw(&map_image, &tft, &m_map, &c_zero, tft.width(), tft.height()); // Draw Cursor on map drawCursor(&tft, &cursor); }