mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
examples: format all .ino files
This formats all the example source files using Arduino style rules.
This commit is contained in:
committed by
Ivan Grokhotkov
parent
e226251b27
commit
61cd8d8385
@ -7,23 +7,21 @@
|
||||
#include <TFTv2.h>
|
||||
#include <SPI.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
TFT_BL_ON; //turn on the background light
|
||||
|
||||
Tft.TFTinit(); //init TFT library
|
||||
void setup() {
|
||||
TFT_BL_ON; //turn on the background light
|
||||
|
||||
Tft.drawCircle(100, 100, 30,YELLOW); //center: (100, 100), r = 30 ,color : YELLOW
|
||||
|
||||
Tft.drawCircle(100, 200, 40,CYAN); // center: (100, 200), r = 10 ,color : CYAN
|
||||
|
||||
Tft.fillCircle(200, 100, 30,RED); //center: (200, 100), r = 30 ,color : RED
|
||||
|
||||
Tft.fillCircle(200, 200, 30,BLUE); //center: (200, 200), r = 30 ,color : BLUE
|
||||
Tft.TFTinit(); //init TFT library
|
||||
|
||||
Tft.drawCircle(100, 100, 30, YELLOW); //center: (100, 100), r = 30 ,color : YELLOW
|
||||
|
||||
Tft.drawCircle(100, 200, 40, CYAN); // center: (100, 200), r = 10 ,color : CYAN
|
||||
|
||||
Tft.fillCircle(200, 100, 30, RED); //center: (200, 100), r = 30 ,color : RED
|
||||
|
||||
Tft.fillCircle(200, 200, 30, BLUE); //center: (200, 200), r = 30 ,color : BLUE
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
|
@ -7,23 +7,21 @@
|
||||
#include <stdint.h>
|
||||
#include <TFTv2.h>
|
||||
#include <SPI.h>
|
||||
void setup()
|
||||
{
|
||||
TFT_BL_ON; // turn on the background light
|
||||
Tft.TFTinit(); //init TFT library
|
||||
void setup() {
|
||||
TFT_BL_ON; // turn on the background light
|
||||
Tft.TFTinit(); //init TFT library
|
||||
|
||||
Tft.drawLine(0,0,239,319,RED); //start: (0, 0) end: (239, 319), color : RED
|
||||
|
||||
Tft.drawVerticalLine(60,100,100,GREEN); // Draw a vertical line
|
||||
// start: (60, 100) length: 100 color: green
|
||||
|
||||
Tft.drawHorizontalLine(30,60,150,BLUE); //Draw a horizontal line
|
||||
//start: (30, 60), high: 150, color: blue
|
||||
Tft.drawLine(0, 0, 239, 319, RED); //start: (0, 0) end: (239, 319), color : RED
|
||||
|
||||
Tft.drawVerticalLine(60, 100, 100, GREEN); // Draw a vertical line
|
||||
// start: (60, 100) length: 100 color: green
|
||||
|
||||
Tft.drawHorizontalLine(30, 60, 150, BLUE); //Draw a horizontal line
|
||||
//start: (30, 60), high: 150, color: blue
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************************************************
|
||||
|
@ -8,31 +8,29 @@
|
||||
#include <TFTv2.h>
|
||||
#include <SPI.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
TFT_BL_ON; // turn on the background light
|
||||
|
||||
Tft.TFTinit(); // init TFT library
|
||||
|
||||
Tft.drawNumber(1024, 0, 0, 1, RED); // draw a integer: 1024, Location: (0, 0), size: 1, color: RED
|
||||
|
||||
Tft.drawNumber(1024, 0, 20, 2, BLUE); // draw a integer: 1024, Location: (0, 20), size: 2, color: BLUE
|
||||
|
||||
Tft.drawNumber(1024, 0, 50, 3, GREEN); // draw a integer: 1024, Location: (0, 50), size: 3, color: GREEN
|
||||
|
||||
Tft.drawNumber(1024, 0, 90, 4, BLUE); // draw a integer: 1024, Location: (0, 90), size:4, color: BLUE
|
||||
|
||||
Tft.drawFloat(1.2345, 0, 150, 4, YELLOW); // draw a float number: 1.2345, Location: (0, 150), size: 4, color: YELLOW
|
||||
|
||||
Tft.drawFloat(1.2345, 2, 0, 200, 4, BLUE); // draw a float number: 1.2345: Location: (0, 200), size: 4, decimal: 2, color: BLUE
|
||||
|
||||
Tft.drawFloat(1.2345, 4, 0, 250, 4, RED); // draw a float number: 1.2345 Location: (0, 250), size: 4, decimal: 4, color: RED
|
||||
|
||||
void setup() {
|
||||
TFT_BL_ON; // turn on the background light
|
||||
|
||||
Tft.TFTinit(); // init TFT library
|
||||
|
||||
Tft.drawNumber(1024, 0, 0, 1, RED); // draw a integer: 1024, Location: (0, 0), size: 1, color: RED
|
||||
|
||||
Tft.drawNumber(1024, 0, 20, 2, BLUE); // draw a integer: 1024, Location: (0, 20), size: 2, color: BLUE
|
||||
|
||||
Tft.drawNumber(1024, 0, 50, 3, GREEN); // draw a integer: 1024, Location: (0, 50), size: 3, color: GREEN
|
||||
|
||||
Tft.drawNumber(1024, 0, 90, 4, BLUE); // draw a integer: 1024, Location: (0, 90), size:4, color: BLUE
|
||||
|
||||
Tft.drawFloat(1.2345, 0, 150, 4, YELLOW); // draw a float number: 1.2345, Location: (0, 150), size: 4, color: YELLOW
|
||||
|
||||
Tft.drawFloat(1.2345, 2, 0, 200, 4, BLUE); // draw a float number: 1.2345: Location: (0, 200), size: 4, decimal: 2, color: BLUE
|
||||
|
||||
Tft.drawFloat(1.2345, 4, 0, 250, 4, RED); // draw a float number: 1.2345 Location: (0, 250), size: 4, decimal: 4, color: RED
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************************************************
|
||||
|
@ -7,19 +7,17 @@
|
||||
#include <TFTv2.h>
|
||||
#include <SPI.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
TFT_BL_ON; // turn on the background light
|
||||
Tft.TFTinit(); // init TFT library
|
||||
void setup() {
|
||||
TFT_BL_ON; // turn on the background light
|
||||
Tft.TFTinit(); // init TFT library
|
||||
|
||||
Tft.fillScreen(80, 160, 50, 150,RED);
|
||||
Tft.fillRectangle(30, 120, 100,65,YELLOW);
|
||||
Tft.drawRectangle(100, 170, 120,60,BLUE);
|
||||
Tft.fillScreen(80, 160, 50, 150, RED);
|
||||
Tft.fillRectangle(30, 120, 100, 65, YELLOW);
|
||||
Tft.drawRectangle(100, 170, 120, 60, BLUE);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
/*********************************************************************************************************
|
||||
END FILE
|
||||
|
@ -14,41 +14,35 @@ unsigned int colors[8] = {BLACK, RED, GREEN, BLUE, CYAN, YELLOW, WHITE, GRAY1};
|
||||
|
||||
TouchScreen ts = TouchScreen(XP, YP, XM, YM); //init TouchScreen port pins
|
||||
|
||||
void setup()
|
||||
{
|
||||
Tft.TFTinit(); //init TFT library
|
||||
Serial.begin(115200);
|
||||
//Draw the pallet
|
||||
for(int i = 0; i<8; i++)
|
||||
{
|
||||
Tft.fillRectangle(i*30, 0, 30, ColorPaletteHigh, colors[i]);
|
||||
}
|
||||
void setup() {
|
||||
Tft.TFTinit(); //init TFT library
|
||||
Serial.begin(115200);
|
||||
//Draw the pallet
|
||||
for (int i = 0; i < 8; i++) {
|
||||
Tft.fillRectangle(i * 30, 0, 30, ColorPaletteHigh, colors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// a point object holds x y and z coordinates.
|
||||
Point p = ts.getPoint();
|
||||
void loop() {
|
||||
// a point object holds x y and z coordinates.
|
||||
Point p = ts.getPoint();
|
||||
|
||||
//map the ADC value read to into pixel co-ordinates
|
||||
//map the ADC value read to into pixel co-ordinates
|
||||
|
||||
p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
|
||||
p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
|
||||
p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
|
||||
p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
|
||||
|
||||
// we have some minimum pressure we consider 'valid'
|
||||
// pressure of 0 means no pressing!
|
||||
// we have some minimum pressure we consider 'valid'
|
||||
// pressure of 0 means no pressing!
|
||||
|
||||
if (p.z > __PRESURE) {
|
||||
// Detect paint brush color change
|
||||
if(p.y < ColorPaletteHigh+2)
|
||||
{
|
||||
color = colors[p.x/30];
|
||||
}
|
||||
else
|
||||
{
|
||||
Tft.fillCircle(p.x,p.y,2,color);
|
||||
}
|
||||
if (p.z > __PRESURE) {
|
||||
// Detect paint brush color change
|
||||
if (p.y < ColorPaletteHigh + 2) {
|
||||
color = colors[p.x / 30];
|
||||
} else {
|
||||
Tft.fillCircle(p.x, p.y, 2, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*********************************************************************************************************
|
||||
END FILE
|
||||
|
@ -4,19 +4,16 @@
|
||||
#include <TFTv2.h>
|
||||
#include <SPI.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
TFT_BL_ON; // turn on the background light
|
||||
Tft.TFTinit(); // init TFT library
|
||||
void setup() {
|
||||
TFT_BL_ON; // turn on the background light
|
||||
Tft.TFTinit(); // init TFT library
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for(int r=0;r<115;r=r+2) //set r : 0--115
|
||||
{
|
||||
Tft.drawCircle(119,160,r,random(0xFFFF)); //draw circle, center:(119, 160), color: random
|
||||
}
|
||||
delay(10);
|
||||
void loop() {
|
||||
for (int r = 0; r < 115; r = r + 2) { //set r : 0--115
|
||||
Tft.drawCircle(119, 160, r, random(0xFFFF)); //draw circle, center:(119, 160), color: random
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
/*********************************************************************************************************
|
||||
END FILE
|
||||
|
@ -7,29 +7,27 @@
|
||||
#include <TFTv2.h>
|
||||
#include <SPI.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
TFT_BL_ON; // turn on the background light
|
||||
Tft.TFTinit(); // init TFT library
|
||||
|
||||
Tft.drawChar('S',0,0,1,RED); // draw char: 'S', (0, 0), size: 1, color: RED
|
||||
|
||||
Tft.drawChar('E',10,10,2,BLUE); // draw char: 'E', (10, 10), size: 2, color: BLUE
|
||||
|
||||
Tft.drawChar('E',20,40,3,GREEN); // draw char: 'E', (20, 40), size: 3, color: GREEN
|
||||
|
||||
Tft.drawChar('E',30,80,4,YELLOW); // draw char: 'E', (30, 80), size: 4, color: YELLOW
|
||||
|
||||
Tft.drawChar('D',40,120,4,YELLOW); // draw char: 'D', (40, 120), size: 4, color: YELLOW
|
||||
|
||||
Tft.drawString("Hello",0,180,3,CYAN); // draw string: "hello", (0, 180), size: 3, color: CYAN
|
||||
|
||||
Tft.drawString("World!!",60,220,4,WHITE); // draw string: "world!!", (80, 230), size: 4, color: WHITE
|
||||
|
||||
void setup() {
|
||||
TFT_BL_ON; // turn on the background light
|
||||
Tft.TFTinit(); // init TFT library
|
||||
|
||||
Tft.drawChar('S', 0, 0, 1, RED); // draw char: 'S', (0, 0), size: 1, color: RED
|
||||
|
||||
Tft.drawChar('E', 10, 10, 2, BLUE); // draw char: 'E', (10, 10), size: 2, color: BLUE
|
||||
|
||||
Tft.drawChar('E', 20, 40, 3, GREEN); // draw char: 'E', (20, 40), size: 3, color: GREEN
|
||||
|
||||
Tft.drawChar('E', 30, 80, 4, YELLOW); // draw char: 'E', (30, 80), size: 4, color: YELLOW
|
||||
|
||||
Tft.drawChar('D', 40, 120, 4, YELLOW); // draw char: 'D', (40, 120), size: 4, color: YELLOW
|
||||
|
||||
Tft.drawString("Hello", 0, 180, 3, CYAN); // draw string: "hello", (0, 180), size: 3, color: CYAN
|
||||
|
||||
Tft.drawString("World!!", 60, 220, 4, WHITE); // draw string: "world!!", (80, 230), size: 4, color: WHITE
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
/*
|
||||
TFT Touch Shield 2.0 examples - tftbmp
|
||||
|
||||
|
||||
loovee
|
||||
2013-1-21
|
||||
|
||||
|
||||
this demo can show specified bmp file in root Directory of SD card
|
||||
please ensure that your image file is 320x240 size.
|
||||
please ensure that your image file is 320x240 size.
|
||||
|
||||
change __Gnfile_num and __Gsbmp_files to display your image
|
||||
*/
|
||||
@ -30,64 +30,57 @@ unsigned char __Gnbmp_image_offset = 0; // offset
|
||||
|
||||
int __Gnfile_num = 3; // num of file
|
||||
|
||||
char __Gsbmp_files[3][FILENAME_LEN] = // add file name here
|
||||
{
|
||||
"flower.BMP",
|
||||
"hibiscus.bmp",
|
||||
"test.bmp",
|
||||
char __Gsbmp_files[3][FILENAME_LEN] = { // add file name here
|
||||
"flower.BMP",
|
||||
"hibiscus.bmp",
|
||||
"test.bmp",
|
||||
};
|
||||
|
||||
|
||||
File bmpFile;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
void setup() {
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
pinMode(PIN_SD_CS,OUTPUT);
|
||||
digitalWrite(PIN_SD_CS,HIGH);
|
||||
Serial.begin(9600);
|
||||
|
||||
Tft.TFTinit();
|
||||
pinMode(PIN_SD_CS, OUTPUT);
|
||||
digitalWrite(PIN_SD_CS, HIGH);
|
||||
|
||||
Sd2Card card;
|
||||
card.init(SPI_FULL_SPEED, PIN_SD_CS);
|
||||
|
||||
if(!SD.begin(PIN_SD_CS))
|
||||
{
|
||||
Serial.println("failed!");
|
||||
while(1); // init fail, die here
|
||||
}
|
||||
|
||||
Serial.println("SD OK!");
|
||||
Tft.TFTinit();
|
||||
|
||||
TFT_BL_ON;
|
||||
Sd2Card card;
|
||||
card.init(SPI_FULL_SPEED, PIN_SD_CS);
|
||||
|
||||
if (!SD.begin(PIN_SD_CS)) {
|
||||
Serial.println("failed!");
|
||||
while (1); // init fail, die here
|
||||
}
|
||||
|
||||
Serial.println("SD OK!");
|
||||
|
||||
TFT_BL_ON;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for(unsigned char i=0; i<__Gnfile_num; i++)
|
||||
{
|
||||
bmpFile = SD.open(__Gsbmp_files[i]);
|
||||
if (! bmpFile)
|
||||
{
|
||||
Serial.println("didnt find image");
|
||||
while (1);
|
||||
}
|
||||
|
||||
if(! bmpReadHeader(bmpFile))
|
||||
{
|
||||
Serial.println("bad bmp");
|
||||
return;
|
||||
}
|
||||
|
||||
bmpdraw(bmpFile, 0, 0);
|
||||
bmpFile.close();
|
||||
|
||||
delay(1000);
|
||||
void loop() {
|
||||
for (unsigned char i = 0; i < __Gnfile_num; i++) {
|
||||
bmpFile = SD.open(__Gsbmp_files[i]);
|
||||
if (! bmpFile) {
|
||||
Serial.println("didnt find image");
|
||||
while (1);
|
||||
}
|
||||
|
||||
if (! bmpReadHeader(bmpFile)) {
|
||||
Serial.println("bad bmp");
|
||||
return;
|
||||
}
|
||||
|
||||
bmpdraw(bmpFile, 0, 0);
|
||||
bmpFile.close();
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*********************************************/
|
||||
@ -100,109 +93,103 @@ void loop()
|
||||
#define BUFFPIXEL 60 // must be a divisor of 240
|
||||
#define BUFFPIXEL_X3 180 // BUFFPIXELx3
|
||||
|
||||
void bmpdraw(File f, int x, int y)
|
||||
{
|
||||
bmpFile.seek(__Gnbmp_image_offset);
|
||||
void bmpdraw(File f, int x, int y) {
|
||||
bmpFile.seek(__Gnbmp_image_offset);
|
||||
|
||||
uint32_t time = millis();
|
||||
uint32_t time = millis();
|
||||
|
||||
uint8_t sdbuffer[BUFFPIXEL_X3]; // 3 * pixels to buffer
|
||||
uint8_t sdbuffer[BUFFPIXEL_X3]; // 3 * pixels to buffer
|
||||
|
||||
for (int i=0; i< __Gnbmp_height; i++)
|
||||
{
|
||||
for (int i = 0; i < __Gnbmp_height; i++) {
|
||||
|
||||
for(int j=0; j<(240/BUFFPIXEL); j++)
|
||||
{
|
||||
bmpFile.read(sdbuffer, BUFFPIXEL_X3);
|
||||
uint8_t buffidx = 0;
|
||||
int offset_x = j*BUFFPIXEL;
|
||||
|
||||
unsigned int __color[BUFFPIXEL];
|
||||
|
||||
for(int k=0; k<BUFFPIXEL; k++)
|
||||
{
|
||||
__color[k] = sdbuffer[buffidx+2]>>3; // read
|
||||
__color[k] = __color[k]<<6 | (sdbuffer[buffidx+1]>>2); // green
|
||||
__color[k] = __color[k]<<5 | (sdbuffer[buffidx+0]>>3); // blue
|
||||
|
||||
buffidx += 3;
|
||||
}
|
||||
for (int j = 0; j < (240 / BUFFPIXEL); j++) {
|
||||
bmpFile.read(sdbuffer, BUFFPIXEL_X3);
|
||||
uint8_t buffidx = 0;
|
||||
int offset_x = j * BUFFPIXEL;
|
||||
|
||||
Tft.setCol(offset_x, offset_x+BUFFPIXEL);
|
||||
Tft.setPage(i, i);
|
||||
Tft.sendCMD(0x2c);
|
||||
|
||||
TFT_DC_HIGH;
|
||||
TFT_CS_LOW;
|
||||
unsigned int __color[BUFFPIXEL];
|
||||
|
||||
for(int m=0; m < BUFFPIXEL; m++)
|
||||
{
|
||||
SPI.transfer(__color[m]>>8);
|
||||
SPI.transfer(__color[m]);
|
||||
}
|
||||
for (int k = 0; k < BUFFPIXEL; k++) {
|
||||
__color[k] = sdbuffer[buffidx + 2] >> 3; // read
|
||||
__color[k] = __color[k] << 6 | (sdbuffer[buffidx + 1] >> 2); // green
|
||||
__color[k] = __color[k] << 5 | (sdbuffer[buffidx + 0] >> 3); // blue
|
||||
|
||||
TFT_CS_HIGH;
|
||||
}
|
||||
|
||||
buffidx += 3;
|
||||
}
|
||||
|
||||
Tft.setCol(offset_x, offset_x + BUFFPIXEL);
|
||||
Tft.setPage(i, i);
|
||||
Tft.sendCMD(0x2c);
|
||||
|
||||
TFT_DC_HIGH;
|
||||
TFT_CS_LOW;
|
||||
|
||||
for (int m = 0; m < BUFFPIXEL; m++) {
|
||||
SPI.transfer(__color[m] >> 8);
|
||||
SPI.transfer(__color[m]);
|
||||
}
|
||||
|
||||
TFT_CS_HIGH;
|
||||
}
|
||||
|
||||
Serial.print(millis() - time, DEC);
|
||||
Serial.println(" ms");
|
||||
|
||||
}
|
||||
|
||||
Serial.print(millis() - time, DEC);
|
||||
Serial.println(" ms");
|
||||
}
|
||||
|
||||
boolean bmpReadHeader(File f)
|
||||
{
|
||||
// read header
|
||||
uint32_t tmp;
|
||||
uint8_t bmpDepth;
|
||||
|
||||
if (read16(f) != 0x4D42) {
|
||||
// magic bytes missing
|
||||
return false;
|
||||
}
|
||||
boolean bmpReadHeader(File f) {
|
||||
// read header
|
||||
uint32_t tmp;
|
||||
uint8_t bmpDepth;
|
||||
|
||||
// read file size
|
||||
tmp = read32(f);
|
||||
Serial.print("size 0x");
|
||||
Serial.println(tmp, HEX);
|
||||
|
||||
// read and ignore creator bytes
|
||||
read32(f);
|
||||
|
||||
__Gnbmp_image_offset = read32(f);
|
||||
Serial.print("offset ");
|
||||
Serial.println(__Gnbmp_image_offset, DEC);
|
||||
|
||||
// read DIB header
|
||||
tmp = read32(f);
|
||||
Serial.print("header size ");
|
||||
Serial.println(tmp, DEC);
|
||||
|
||||
|
||||
int bmp_width = read32(f);
|
||||
int bmp_height = read32(f);
|
||||
|
||||
if(bmp_width != __Gnbmp_width || bmp_height != __Gnbmp_height) // if image is not 320x240, return false
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (read16(f) != 1)
|
||||
if (read16(f) != 0x4D42) {
|
||||
// magic bytes missing
|
||||
return false;
|
||||
}
|
||||
|
||||
bmpDepth = read16(f);
|
||||
Serial.print("bitdepth ");
|
||||
Serial.println(bmpDepth, DEC);
|
||||
// read file size
|
||||
tmp = read32(f);
|
||||
Serial.print("size 0x");
|
||||
Serial.println(tmp, HEX);
|
||||
|
||||
if (read32(f) != 0) {
|
||||
// compression not supported!
|
||||
return false;
|
||||
}
|
||||
// read and ignore creator bytes
|
||||
read32(f);
|
||||
|
||||
Serial.print("compression ");
|
||||
Serial.println(tmp, DEC);
|
||||
__Gnbmp_image_offset = read32(f);
|
||||
Serial.print("offset ");
|
||||
Serial.println(__Gnbmp_image_offset, DEC);
|
||||
|
||||
return true;
|
||||
// read DIB header
|
||||
tmp = read32(f);
|
||||
Serial.print("header size ");
|
||||
Serial.println(tmp, DEC);
|
||||
|
||||
|
||||
int bmp_width = read32(f);
|
||||
int bmp_height = read32(f);
|
||||
|
||||
if (bmp_width != __Gnbmp_width || bmp_height != __Gnbmp_height) { // if image is not 320x240, return false
|
||||
return false;
|
||||
}
|
||||
|
||||
if (read16(f) != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bmpDepth = read16(f);
|
||||
Serial.print("bitdepth ");
|
||||
Serial.println(bmpDepth, DEC);
|
||||
|
||||
if (read32(f) != 0) {
|
||||
// compression not supported!
|
||||
return false;
|
||||
}
|
||||
|
||||
Serial.print("compression ");
|
||||
Serial.println(tmp, DEC);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*********************************************/
|
||||
@ -210,26 +197,24 @@ boolean bmpReadHeader(File f)
|
||||
// (the data is stored in little endian format!)
|
||||
|
||||
// LITTLE ENDIAN!
|
||||
uint16_t read16(File f)
|
||||
{
|
||||
uint16_t d;
|
||||
uint8_t b;
|
||||
b = f.read();
|
||||
d = f.read();
|
||||
d <<= 8;
|
||||
d |= b;
|
||||
return d;
|
||||
uint16_t read16(File f) {
|
||||
uint16_t d;
|
||||
uint8_t b;
|
||||
b = f.read();
|
||||
d = f.read();
|
||||
d <<= 8;
|
||||
d |= b;
|
||||
return d;
|
||||
}
|
||||
|
||||
// LITTLE ENDIAN!
|
||||
uint32_t read32(File f)
|
||||
{
|
||||
uint32_t d;
|
||||
uint16_t b;
|
||||
uint32_t read32(File f) {
|
||||
uint32_t d;
|
||||
uint16_t b;
|
||||
|
||||
b = read16(f);
|
||||
d = read16(f);
|
||||
d <<= 16;
|
||||
d |= b;
|
||||
return d;
|
||||
b = read16(f);
|
||||
d = read16(f);
|
||||
d <<= 16;
|
||||
d |= b;
|
||||
return d;
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
/*
|
||||
TFT Touch Shield 2.0 examples - tftbmp2
|
||||
|
||||
|
||||
loovee
|
||||
2013-1-21
|
||||
|
||||
|
||||
this demo can show all bmp file in root Directory of SD card
|
||||
please ensure that your image file is 320x240 size.
|
||||
please ensure that your image file is 320x240 size.
|
||||
|
||||
MAX_BMP can config the max file to display
|
||||
FILENAME_LEN can config the max length of file name
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <SD.h>
|
||||
@ -34,147 +34,139 @@ char __Gsbmp_files[MAX_BMP][FILENAME_LEN]; // file name
|
||||
File bmpFile;
|
||||
|
||||
// if bmp file return 1, else return 0
|
||||
bool checkBMP(char *_name, char r_name[])
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
if(NULL == _name)return false;
|
||||
|
||||
while(*_name)
|
||||
{
|
||||
r_name[len++] = *(_name++);
|
||||
if(len>FILENAME_LEN)return false;
|
||||
}
|
||||
|
||||
r_name[len] = '\0';
|
||||
|
||||
if(len < 5)return false;
|
||||
|
||||
// if xxx.bmp or xxx.BMP
|
||||
if( r_name[len-4] == '.' \
|
||||
&& (r_name[len-3] == 'b' || (r_name[len-3] == 'B')) \
|
||||
&& (r_name[len-2] == 'm' || (r_name[len-2] == 'M')) \
|
||||
&& (r_name[len-1] == 'p' || (r_name[len-1] == 'P')) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool checkBMP(char *_name, char r_name[]) {
|
||||
int len = 0;
|
||||
|
||||
if (NULL == _name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (*_name) {
|
||||
r_name[len++] = *(_name++);
|
||||
if (len > FILENAME_LEN) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
r_name[len] = '\0';
|
||||
|
||||
if (len < 5) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if xxx.bmp or xxx.BMP
|
||||
if (r_name[len - 4] == '.' \
|
||||
&& (r_name[len - 3] == 'b' || (r_name[len - 3] == 'B')) \
|
||||
&& (r_name[len - 2] == 'm' || (r_name[len - 2] == 'M')) \
|
||||
&& (r_name[len - 1] == 'p' || (r_name[len - 1] == 'P'))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// search root to find bmp file
|
||||
void searchDirectory()
|
||||
{
|
||||
File root = SD.open("/"); // root
|
||||
while(true)
|
||||
{
|
||||
File entry = root.openNextFile();
|
||||
|
||||
if (! entry)
|
||||
{
|
||||
break;
|
||||
}
|
||||
void searchDirectory() {
|
||||
File root = SD.open("/"); // root
|
||||
while (true) {
|
||||
File entry = root.openNextFile();
|
||||
|
||||
if(!entry.isDirectory())
|
||||
{
|
||||
char *ptmp = entry.name();
|
||||
|
||||
char __Name[20];
|
||||
|
||||
if(checkBMP(ptmp, __Name))
|
||||
{
|
||||
Serial.println(__Name);
|
||||
|
||||
strcpy(__Gsbmp_files[__Gnfile_num++], __Name);
|
||||
}
|
||||
}
|
||||
entry.close();
|
||||
if (! entry) {
|
||||
break;
|
||||
}
|
||||
|
||||
Serial.print("get ");
|
||||
Serial.print(__Gnfile_num);
|
||||
Serial.println(" file: ");
|
||||
|
||||
for(int i=0; i<__Gnfile_num; i++)
|
||||
{
|
||||
Serial.println(__Gsbmp_files[i]);
|
||||
|
||||
if (!entry.isDirectory()) {
|
||||
char *ptmp = entry.name();
|
||||
|
||||
char __Name[20];
|
||||
|
||||
if (checkBMP(ptmp, __Name)) {
|
||||
Serial.println(__Name);
|
||||
|
||||
strcpy(__Gsbmp_files[__Gnfile_num++], __Name);
|
||||
}
|
||||
}
|
||||
entry.close();
|
||||
}
|
||||
|
||||
Serial.print("get ");
|
||||
Serial.print(__Gnfile_num);
|
||||
Serial.println(" file: ");
|
||||
|
||||
for (int i = 0; i < __Gnfile_num; i++) {
|
||||
Serial.println(__Gsbmp_files[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
pinMode(PIN_SD_CS,OUTPUT);
|
||||
digitalWrite(PIN_SD_CS,HIGH);
|
||||
Serial.begin(115200);
|
||||
|
||||
Tft.TFTinit();
|
||||
pinMode(PIN_SD_CS, OUTPUT);
|
||||
digitalWrite(PIN_SD_CS, HIGH);
|
||||
|
||||
Sd2Card card;
|
||||
card.init(SPI_FULL_SPEED, PIN_SD_CS);
|
||||
|
||||
if(!SD.begin(PIN_SD_CS))
|
||||
{
|
||||
Serial.println("failed!");
|
||||
while(1); // init fail, die here
|
||||
}
|
||||
|
||||
Serial.println("SD OK!");
|
||||
|
||||
searchDirectory();
|
||||
Tft.TFTinit();
|
||||
|
||||
TFT_BL_ON;
|
||||
Sd2Card card;
|
||||
card.init(SPI_FULL_SPEED, PIN_SD_CS);
|
||||
|
||||
if (!SD.begin(PIN_SD_CS)) {
|
||||
Serial.println("failed!");
|
||||
while (1); // init fail, die here
|
||||
}
|
||||
|
||||
Serial.println("SD OK!");
|
||||
|
||||
searchDirectory();
|
||||
|
||||
TFT_BL_ON;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
/*
|
||||
static int dirCtrl = 0;
|
||||
for(unsigned char i=0; i<__Gnfile_num; i++)
|
||||
{
|
||||
bmpFile = SD.open(__Gsbmp_files[i]);
|
||||
if (! bmpFile)
|
||||
{
|
||||
Serial.println("didnt find image");
|
||||
while (1);
|
||||
}
|
||||
void loop() {
|
||||
/*
|
||||
static int dirCtrl = 0;
|
||||
for(unsigned char i=0; i<__Gnfile_num; i++)
|
||||
{
|
||||
bmpFile = SD.open(__Gsbmp_files[i]);
|
||||
if (! bmpFile)
|
||||
{
|
||||
Serial.println("didnt find image");
|
||||
while (1);
|
||||
}
|
||||
|
||||
if(! bmpReadHeader(bmpFile))
|
||||
{
|
||||
Serial.println("bad bmp");
|
||||
return;
|
||||
}
|
||||
if(! bmpReadHeader(bmpFile))
|
||||
{
|
||||
Serial.println("bad bmp");
|
||||
return;
|
||||
}
|
||||
|
||||
dirCtrl = 1-dirCtrl;
|
||||
bmpdraw(bmpFile, 0, 0, dirCtrl);
|
||||
bmpFile.close();
|
||||
dirCtrl = 1-dirCtrl;
|
||||
bmpdraw(bmpFile, 0, 0, dirCtrl);
|
||||
bmpFile.close();
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
*/
|
||||
delay(1000);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
bmpFile = SD.open("pfvm_1.bmp");
|
||||
|
||||
if (! bmpFile)
|
||||
{
|
||||
Serial.println("didnt find image");
|
||||
while (1);
|
||||
}
|
||||
bmpFile = SD.open("pfvm_1.bmp");
|
||||
|
||||
if(! bmpReadHeader(bmpFile))
|
||||
{
|
||||
Serial.println("bad bmp");
|
||||
return;
|
||||
}
|
||||
if (! bmpFile) {
|
||||
Serial.println("didnt find image");
|
||||
while (1);
|
||||
}
|
||||
|
||||
bmpdraw(bmpFile, 0, 0, 1);
|
||||
bmpFile.close();
|
||||
if (! bmpReadHeader(bmpFile)) {
|
||||
Serial.println("bad bmp");
|
||||
return;
|
||||
}
|
||||
|
||||
while(1);
|
||||
bmpdraw(bmpFile, 0, 0, 1);
|
||||
bmpFile.close();
|
||||
|
||||
while (1);
|
||||
}
|
||||
|
||||
/*********************************************/
|
||||
@ -193,129 +185,118 @@ void loop()
|
||||
|
||||
// dir - 1: up to down
|
||||
// dir - 2: down to up
|
||||
void bmpdraw(File f, int x, int y, int dir)
|
||||
{
|
||||
void bmpdraw(File f, int x, int y, int dir) {
|
||||
|
||||
if(bmpFile.seek(__Gnbmp_image_offset))
|
||||
{
|
||||
Serial.print("pos = ");
|
||||
Serial.println(bmpFile.position());
|
||||
if (bmpFile.seek(__Gnbmp_image_offset)) {
|
||||
Serial.print("pos = ");
|
||||
Serial.println(bmpFile.position());
|
||||
}
|
||||
|
||||
uint32_t time = millis();
|
||||
|
||||
uint8_t sdbuffer[BUFFPIXEL_X3]; // 3 * pixels to buffer
|
||||
|
||||
for (int i = 0; i < __Gnbmp_height; i++) {
|
||||
if (dir) {
|
||||
bmpFile.seek(__Gnbmp_image_offset + (__Gnbmp_height - 1 - i) * 240 * 3);
|
||||
}
|
||||
|
||||
uint32_t time = millis();
|
||||
|
||||
uint8_t sdbuffer[BUFFPIXEL_X3]; // 3 * pixels to buffer
|
||||
for (int j = 0; j < (240 / BUFFPIXEL); j++) {
|
||||
|
||||
for (int i=0; i< __Gnbmp_height; i++)
|
||||
{
|
||||
if(dir)
|
||||
{
|
||||
bmpFile.seek(__Gnbmp_image_offset+(__Gnbmp_height-1-i)*240*3);
|
||||
}
|
||||
bmpFile.read(sdbuffer, BUFFPIXEL_X3);
|
||||
uint8_t buffidx = 0;
|
||||
int offset_x = j * BUFFPIXEL;
|
||||
|
||||
for(int j=0; j<(240/BUFFPIXEL); j++)
|
||||
{
|
||||
|
||||
bmpFile.read(sdbuffer, BUFFPIXEL_X3);
|
||||
uint8_t buffidx = 0;
|
||||
int offset_x = j*BUFFPIXEL;
|
||||
|
||||
unsigned int __color[BUFFPIXEL];
|
||||
|
||||
for(int k=0; k<BUFFPIXEL; k++)
|
||||
{
|
||||
__color[k] = sdbuffer[buffidx+2]>>3; // read
|
||||
__color[k] = __color[k]<<6 | (sdbuffer[buffidx+1]>>2); // green
|
||||
__color[k] = __color[k]<<5 | (sdbuffer[buffidx+0]>>3); // blue
|
||||
|
||||
buffidx += 3;
|
||||
}
|
||||
unsigned int __color[BUFFPIXEL];
|
||||
|
||||
Tft.setCol(offset_x, offset_x+BUFFPIXEL);
|
||||
for (int k = 0; k < BUFFPIXEL; k++) {
|
||||
__color[k] = sdbuffer[buffidx + 2] >> 3; // read
|
||||
__color[k] = __color[k] << 6 | (sdbuffer[buffidx + 1] >> 2); // green
|
||||
__color[k] = __color[k] << 5 | (sdbuffer[buffidx + 0] >> 3); // blue
|
||||
|
||||
if(dir)
|
||||
{
|
||||
Tft.setPage(i, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
Tft.setPage(__Gnbmp_height-i-1, __Gnbmp_height-i-1);
|
||||
}
|
||||
buffidx += 3;
|
||||
}
|
||||
|
||||
Tft.sendCMD(0x2c);
|
||||
|
||||
TFT_DC_HIGH;
|
||||
TFT_CS_LOW;
|
||||
Tft.setCol(offset_x, offset_x + BUFFPIXEL);
|
||||
|
||||
for(int m=0; m < BUFFPIXEL; m++)
|
||||
{
|
||||
SPI.transfer(__color[m]>>8);
|
||||
SPI.transfer(__color[m]);
|
||||
|
||||
delay(10);
|
||||
}
|
||||
if (dir) {
|
||||
Tft.setPage(i, i);
|
||||
} else {
|
||||
Tft.setPage(__Gnbmp_height - i - 1, __Gnbmp_height - i - 1);
|
||||
}
|
||||
|
||||
TFT_CS_HIGH;
|
||||
}
|
||||
|
||||
Tft.sendCMD(0x2c);
|
||||
|
||||
TFT_DC_HIGH;
|
||||
TFT_CS_LOW;
|
||||
|
||||
for (int m = 0; m < BUFFPIXEL; m++) {
|
||||
SPI.transfer(__color[m] >> 8);
|
||||
SPI.transfer(__color[m]);
|
||||
|
||||
delay(10);
|
||||
}
|
||||
|
||||
TFT_CS_HIGH;
|
||||
}
|
||||
|
||||
Serial.print(millis() - time, DEC);
|
||||
Serial.println(" ms");
|
||||
|
||||
}
|
||||
|
||||
Serial.print(millis() - time, DEC);
|
||||
Serial.println(" ms");
|
||||
}
|
||||
|
||||
boolean bmpReadHeader(File f)
|
||||
{
|
||||
// read header
|
||||
uint32_t tmp;
|
||||
uint8_t bmpDepth;
|
||||
|
||||
if (read16(f) != 0x4D42) {
|
||||
// magic bytes missing
|
||||
return false;
|
||||
}
|
||||
boolean bmpReadHeader(File f) {
|
||||
// read header
|
||||
uint32_t tmp;
|
||||
uint8_t bmpDepth;
|
||||
|
||||
// read file size
|
||||
tmp = read32(f);
|
||||
Serial.print("size 0x");
|
||||
Serial.println(tmp, HEX);
|
||||
|
||||
// read and ignore creator bytes
|
||||
read32(f);
|
||||
|
||||
__Gnbmp_image_offset = read32(f);
|
||||
Serial.print("offset ");
|
||||
Serial.println(__Gnbmp_image_offset, DEC);
|
||||
|
||||
// read DIB header
|
||||
tmp = read32(f);
|
||||
Serial.print("header size ");
|
||||
Serial.println(tmp, DEC);
|
||||
|
||||
int bmp_width = read32(f);
|
||||
int bmp_height = read32(f);
|
||||
|
||||
if(bmp_width != __Gnbmp_width || bmp_height != __Gnbmp_height) // if image is not 320x240, return false
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (read16(f) != 1)
|
||||
if (read16(f) != 0x4D42) {
|
||||
// magic bytes missing
|
||||
return false;
|
||||
}
|
||||
|
||||
bmpDepth = read16(f);
|
||||
Serial.print("bitdepth ");
|
||||
Serial.println(bmpDepth, DEC);
|
||||
// read file size
|
||||
tmp = read32(f);
|
||||
Serial.print("size 0x");
|
||||
Serial.println(tmp, HEX);
|
||||
|
||||
if (read32(f) != 0) {
|
||||
// compression not supported!
|
||||
return false;
|
||||
}
|
||||
// read and ignore creator bytes
|
||||
read32(f);
|
||||
|
||||
Serial.print("compression ");
|
||||
Serial.println(tmp, DEC);
|
||||
__Gnbmp_image_offset = read32(f);
|
||||
Serial.print("offset ");
|
||||
Serial.println(__Gnbmp_image_offset, DEC);
|
||||
|
||||
return true;
|
||||
// read DIB header
|
||||
tmp = read32(f);
|
||||
Serial.print("header size ");
|
||||
Serial.println(tmp, DEC);
|
||||
|
||||
int bmp_width = read32(f);
|
||||
int bmp_height = read32(f);
|
||||
|
||||
if (bmp_width != __Gnbmp_width || bmp_height != __Gnbmp_height) { // if image is not 320x240, return false
|
||||
return false;
|
||||
}
|
||||
|
||||
if (read16(f) != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bmpDepth = read16(f);
|
||||
Serial.print("bitdepth ");
|
||||
Serial.println(bmpDepth, DEC);
|
||||
|
||||
if (read32(f) != 0) {
|
||||
// compression not supported!
|
||||
return false;
|
||||
}
|
||||
|
||||
Serial.print("compression ");
|
||||
Serial.println(tmp, DEC);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*********************************************/
|
||||
@ -323,26 +304,24 @@ boolean bmpReadHeader(File f)
|
||||
// (the data is stored in little endian format!)
|
||||
|
||||
// LITTLE ENDIAN!
|
||||
uint16_t read16(File f)
|
||||
{
|
||||
uint16_t d;
|
||||
uint8_t b;
|
||||
b = f.read();
|
||||
d = f.read();
|
||||
d <<= 8;
|
||||
d |= b;
|
||||
return d;
|
||||
uint16_t read16(File f) {
|
||||
uint16_t d;
|
||||
uint8_t b;
|
||||
b = f.read();
|
||||
d = f.read();
|
||||
d <<= 8;
|
||||
d |= b;
|
||||
return d;
|
||||
}
|
||||
|
||||
// LITTLE ENDIAN!
|
||||
uint32_t read32(File f)
|
||||
{
|
||||
uint32_t d;
|
||||
uint16_t b;
|
||||
uint32_t read32(File f) {
|
||||
uint32_t d;
|
||||
uint16_t b;
|
||||
|
||||
b = read16(f);
|
||||
d = read16(f);
|
||||
d <<= 16;
|
||||
d |= b;
|
||||
return d;
|
||||
b = read16(f);
|
||||
d = read16(f);
|
||||
d <<= 16;
|
||||
d |= b;
|
||||
return d;
|
||||
}
|
||||
|
Reference in New Issue
Block a user