//========================== #define PIN_LED1 5 //LED1 #define PIN_LED2 6 //LED2 #define PIN_key1 A6 //按键1 //========================== #define init_oled 600 //OLED刷新时间 #define init_oled_updata 2000 //按键动作时,提示持续时间 #define init_updata 500 //gps数据刷新时间 #define init_sdwrite 3000 //SD卡写入间隔 //========================== #define timezone 6 int DaysAMonth[] = { //number of days a month 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; unsigned long time_oled = millis(); unsigned long time_oled_updata = millis(); unsigned long timer = millis(); unsigned long time_sdwrite = millis(); boolean b_oled_updata=false; //按键动作触发OLED //key========================= boolean key1; //按键 boolean key1_cache; //检测按键松开缓存 //========================== boolean STA; //GPS状态 float f_latitude,f_longitude; //经纬度 char c_lat,c_lon; //经纬极向 int itime[3]; //时间 int idate[3]; //日期 float f_Speed; //速度 int i_Speed[2]; //速度格式化 float f_Height; //海拔 int i_satellites; //卫星数 float f_fixquality; //信号质量 //PKJ======================================= #define num_name 13 //文件名字长 char file_name[num_name]=""; //文件名 String file_name_cache =""; //文件名缓存 boolean file_updata; //是否更新新的GPX文件 boolean sd_sta,file_sta; //SD卡状态、文件状态 int file_num; //文件名后两位序号 int idate_cache; //日期(日)缓存 //oled======================================= #include U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11) //-------字体设置,大、中、小 #define setFont_L u8g.setFont(u8g_font_courB14) #define setFont_M u8g.setFont(u8g_font_fixed_v0r) #define setFont_S u8g.setFont(u8g_font_chikitar) /* font: u8g.setFont(u8g_font_7x13) u8g.setFont(u8g_font_fixed_v0r); u8g.setFont(u8g_font_chikitar); u8g.setFont(u8g_font_osb21); */ #define u8g_logo_width 128 #define u8g_logo_height 18 const unsigned char u8g_logo_bits[] U8G_PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00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F, 0xFF, 0xF3, 0x71, 0xDC, 0x7F, 0x00, 0x00, 0x7E, 0xFC, 0xE7, 0xE3, 0xBF, 0x03, 0xFC, 0xE3, 0x3F, 0xFE, 0xF3, 0x71, 0x9C, 0x7F, 0x00, 0x00, 0xC1, 0x03, 0xF8, 0xCF, 0xE7, 0x0F, 0xF0, 0x00, 0x7F, 0xFC, 0xFC, 0xFF, 0x3E, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; //========================== #include #include Adafruit_GPS GPS(&Serial); // Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console // Set to 'true' if you want to debug and listen to the raw GPS sentences #define GPSECHO false //lat_lon_transform================================ void lat_lon_transform() { f_latitude=(int(f_latitude)/100)+((int(f_latitude)%100)/60.0)+((f_latitude-int(f_latitude))/60.0); if(c_lat=='S') //南纬 f_latitude=-f_latitude; //--------------------------------- f_longitude=(int(f_longitude)/100)+((int(f_longitude)%100)/60.0)+((f_longitude-int(f_longitude))/60.0); if(c_lon=='W') //西经 f_longitude=-f_longitude; } // FileName_StringtoChar================================ void vostring() { String s_file_name=""; for(int a=0;a<3;a++) { if(idate[a]<10) s_file_name+="0"; s_file_name+=idate[a]; } if(file_num<10) s_file_name+="0"; s_file_name+=file_num; s_file_name+=".gpx"; for(int a=0;a<(num_name-1);a++) { file_name[a]=s_file_name[a]; } } //GPS======================================== void vogps_databegin() { digitalWrite(PIN_LED2,true); //LED2亮:GPS开始读取 char c = GPS.read(); // if you want to debug, this is a good time to do it! // if a sentence is received, we can check the checksum, parse it... if (GPS.newNMEAreceived()) { // a tricky thing here is if we print the NMEA sentence, or data // we end up not listening and catching other sentences! // so be very wary if using OUTPUT_ALLDATA and trytng to print out data if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false return; // we can fail to parse a sentence in which case we should just wait for another } digitalWrite(PIN_LED2,false); //LED2灭:GPS结束读取 } void vogps_dataread() { if (timer > millis()) timer = millis(); if (millis() - timer > init_updata) { timer = millis(); // reset the timer itime[2]=GPS.seconds; itime[1]=GPS.minute; itime[0]=GPS.hour+timezone; idate[2]=GPS.day; idate[1]=GPS.month; idate[0]=GPS.year; if (itime[0]>23) { idate[2]+=1; itime[0]-=24; } if (idate[0]%4 ==0) DaysAMonth[1] = 29; if (idate[2]>DaysAMonth[idate[1]-1]) { idate[1]+=1; idate[2]-=DaysAMonth[idate[1]-1]; } if (idate[1]>12) { idate[0]+=1; idate[1]-=12; } f_fixquality=GPS.fixquality; //信号质量 STA=GPS.fix; //GPS定位状态 if (STA) //当GPS定位上 { f_latitude=GPS.latitude; f_longitude=GPS.longitude; c_lat=GPS.lat; c_lon=GPS.lon; lat_lon_transform(); //经纬度转化 f_Speed=1.852*GPS.speed; //速度转化 i_Speed[0]=int(f_Speed*10)%10; //速度格式化 i_Speed[1]=int(f_Speed); //速度格式化 f_Height=GPS.altitude; //海拔 i_satellites=GPS.satellites; //卫星数 } } } //OLED=================================================== void vooled() { if (time_oled > millis()) time_oled = millis(); if(millis()-time_oled>init_oled) { u8g.firstPage(); do { draw(); } while( u8g.nextPage() ); time_oled=millis(); } } void volcdlogo(unsigned int x, unsigned int y) { u8g.firstPage(); do { u8g.drawXBMP( x, y, u8g_logo_width, u8g_logo_height, u8g_logo_bits); } while( u8g.nextPage() ); } void draw(void) { setFont_L; u8g.setPrintPos(2, 18); u8g.print("Speed:"); if(STA) { u8g.print(i_Speed[1]); setFont_M; u8g.print("."); u8g.print(i_Speed[0]); } else { u8g.print("N/A"); setFont_M; } u8g.setPrintPos(2, 32); u8g.print("Lat.: "); u8g.print( c_lat); u8g.print(" "); u8g.print( f_latitude,4); u8g.setPrintPos(2, 41); u8g.print("Lon.: "); u8g.print( c_lon); u8g.print(" "); u8g.print(f_longitude,4); u8g.drawLine(0, 44, 128, 44); u8g.drawLine(0, 55, 128, 55); u8g.setPrintPos(2, 53); u8g.print(idate[2]); u8g.print("."); u8g.print(idate[1]); u8g.print("."); u8g.print("20"); u8g.print(idate[0]); u8g.print(" "); u8g.print(itime[0]); u8g.print(":"); u8g.print(itime[1]); u8g.print(":"); u8g.print(itime[2]); for(int a=0;a<3;a++) { u8g.drawFrame(2+(5*a), 61-(a*2), 4, 3+(a*2)); } for(int a=0;a