Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dj1711572002/e6ae2e482128a2ae10b33da1b8c30984 to your computer and use it in GitHub Desktop.
Save dj1711572002/e6ae2e482128a2ae10b33da1b8c30984 to your computer and use it in GitHub Desktop.
M5Core2  ESP-NOW RTK Logger
//#include <M5Stack.h>
#include <M5Core2.h>
#include <esp_now.h>
#include <WiFi.h>
esp_now_peer_info_t slave;
#include "SD.h"
#define MAGENTA 0xF81F
#define GREENYELLOW 0xAFE5 /* 173, 255, 47 */
#define YELLOW 0xFFE0 /* 255, 255, 0 */
#define WHITE 0xFFFF /* 255, 255, 255 */
#define FORMAT_SPIFFS_IF_FAILED true
uint16_t Col1,Col2;
//---esp-now--
uint8_t cdata[1];
uint8_t CH0data[57];//CH0 right data
uint8_t CH1data[57];//CH1 leftdata
//File declaraation
//#include "FS.h"
//#include "SPIFFS.h"
#define LED_PIN 10
//sd Para-----------------------
char GGAc[83];
File file;
File f;
File root;
String stime;//filename
int kaisu=0;
int ch0N,ch1N;
String sdfname[100];
char fname[30];//File name char Array
String str;
String strTotal;
int i,j,k;
String Listname[100] ;
char file_name[20] = "/GGA.txt";
int var_size = 2000;
//Graphic-------------
uint8_t sdFlag,sdFlag_1;
uint8_t sdFlag1;
uint8_t sdFlag2;
int firstFlag=0;
uint8_t dFlag;//Dump Mode
uint8_t monFlag;//Monitor Flag
int t,t_1,tim;
char Logmark;
int ch0Flag,ch1Flag;
int ch_Flag;
int Nextchflag=0;
int initFlag=1;
int autoFlag=0;
int logFlag=0;
int p0x=160;
int p0y=60;
int xoff=40;
int yoff=20;
int ch;
static float dvx,dvy;
static int Rxw,Ryw;
//----------plot function
int px,py;
int Lx,Ly;
int px1,py1;
int Lx1,Ly1;
//NAV-------------------
int n;
//=============monitor data================
int data_len;
static int iyear;
static int imonth;
static int iday;
static int ihour;
static int imin;
static int isec;
static int csec;
// ch change-----------------
//int ch=0;
int sNo=0;
static int iTow[2];
static long relN[2];
static long relE[2];
static long relD[2];
static long Long[2];
static long Lati[2];
static long Acc2d[2];
static int Acc2d0[2];
static int Acc2d1[2];
static int numSV[2];
//static int numSV0[2];
//static int numSV1[2];//satellite number
static int Length[2];
static long Head[2];
//static int Length0[2];
//static int Length1[2];
//static int Long0[2];
//static int Lati0[2];
static long gSpeed[2];//2021/3/16 add
static long headMot[2];//2021/3/16 add
static long Seah[2];//2021/3/17 add
String sdata;
//----------------------------
//long Acc2d;
//char numSV;//satellite number
//long Length;
long su;
//+++++++++++++4byte Binary to Long ++++++++++++++++++++++++++++++++++++++++++++++
long B2L(uint8_t b4 , uint8_t b3 ,uint8_t b2 , uint8_t b1 ) {
//pc.printf("B2L IN=%s,%x,%x,%x,%x,b4&0x80=%d\n\r",sen,b4,b3,b2,b1,b4 &0x80);
//pc.printf("B2L IN=b4&0x80=%d\n\r",b4 & 0x80);
if ((b4 & 0x80) && 0x80){//最上位ビットたっていればマイナス
su = -(256-(int)b1)+(255-(int)b2)*256+(255-(int)b3)*65536+(255-(int)b4)*256*256*256;
//pc.printf("B2L-:sen=%s,%d,%d,%d,%d,%d\n\r",sen,b4,b3,b2,b1,su);
}
else {
su=(int)b1+(int)b2*256+(int)b3* 65536+(int)b4*256*256*256;
//pc.printf("B2L+:sen=%s,%d,%d,%d,%d,%d,%d\n\r",sen,b4,b3,b2,b1,su);
}
return su;
}
// 送信コールバック
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
char macStr[18];
snprintf(macStr, sizeof(macStr), "%02X:%02X:%02X:%02X:%02X:%02X",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
/*
Serial.print("Last Packet Sent to: ");
Serial.println(macStr);
Serial.print("Last Packet Send Status: ");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
// 画面にも描画
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 0);
M5.Lcd.print("Last Packet Sent to: \n ");
M5.Lcd.println(macStr);
M5.Lcd.print("Last Packet Send Status: \n ");
M5.Lcd.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
*/
}
//---------------------SPIFFS Utility-------------------------------------
void str2char(char c[],String dataS)
{
//String dataS;
//dataS="HELLO dataS";
int dataS_len=dataS.length()+1;
char char_array[dataS_len];
dataS.toCharArray(c,dataS_len);
}
//*************************************************************************************************
//+++++++++++++++i_to_char+++++++++++++++++
// i=IntegerValueData,*d=Array pointer, n=Array start No
void i_to_char(int i, uint8_t *d, int n)
{
d[n] = i & 0x000000ff;
d[n + 1] = (i & 0x0000ff00) >> 8;
d[n + 2] = (i & 0x00ff0000) >> 16;
d[n + 3] = (i & 0xff000000) >> 24;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Display data Cal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void dataCal(int ch,uint8_t data[])
{
int sNo=0;
// iTow U4
iTow[ch]=B2L(data[sNo+4],data[sNo+3],data[sNo+2],data[sNo+1]);//headMot上位ー>下位 ofset64+6
numSV[ch]=data[sNo+12];
Long[ch]=B2L(data[sNo+16],data[sNo+15],data[sNo+14],data[sNo+13]);//Longtitude上位ー>下位
Long[ch]=Long[ch];//%100000;
Lati[ch]=B2L(data[sNo+20],data[sNo+19],data[sNo+18],data[sNo+17]);//latitude 上位ー>下位
Lati[ch]=Lati[ch];//%100000;
Seah[ch]=B2L(data[sNo+24],data[sNo+23],data[sNo+22],data[sNo+21]);//headMot上位ー>下位 ofset64+6
Seah[ch]=Seah[ch];//*0.001;//mm=>m
Acc2d[ch]=B2L(data[sNo+28],data[sNo+27],data[sNo+26],data[sNo+25]);//Accuracy 2D 上位ー>下位
gSpeed[ch]=B2L(data[sNo+33],data[sNo+32],data[sNo+31],data[sNo+30]);//gSpeed上位ー>下位 ofset60+6
gSpeed[ch]=gSpeed[ch];//*0.0036;// gSpeed 1mm/sec=> 0.0036kmh
headMot[ch]=B2L(data[sNo+37],data[sNo+36],data[sNo+35],data[sNo+34]);//headMot上位ー>下位 ofset64+6
headMot[ch]=headMot[ch];///100000;//headMot 1= 0.00001 deg
relN[ch]=B2L(data[sNo+41],data[sNo+40],data[sNo+39],data[sNo+38]);
relE[ch]=B2L(data[sNo+45],data[sNo+44],data[sNo+43],data[sNo+42]);
relD[ch]=B2L(data[sNo+49],data[sNo+48],data[sNo+47],data[sNo+46]);
Length[ch]=B2L(data[sNo+53],data[sNo+52],data[sNo+51],data[sNo+50]);
Head[ch]=B2L(data[sNo+57],data[sNo+56],data[sNo+55],data[sNo+54]);
Head[ch]=int(Head[ch]/100000);
Serial.print("dataCal():Head[");
Serial.print(ch);
Serial.print("]=");
Serial.print(Head[ch]);
Serial.print("data[54]=");
Serial.print(data[sNo+54],HEX);
Serial.print("data[55]=");
Serial.print(data[sNo+55],HEX);
Serial.print("data[56]=");
Serial.print(data[sNo+56],HEX);
Serial.print("data[57]=");
Serial.print(data[sNo+57],HEX);
Serial.println();
Serial.print("dataCal:iTow[");
Serial.print(ch);
Serial.print("]=");
Serial.println(iTow[ch]);
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// ESP-NOW 受信コールバック
//----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
char macStr[18];
snprintf(macStr, sizeof(macStr), "%02X:%02X:%02X:%02X:%02X:%02X",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
// Serial.printf("Last Packet Recv from: %s\n", macStr);
// Serial.printf("Last Packet Recv Time=%d,Datalength=%d \n\r", millis(),data_len);
if(data_len!=58)
{
Serial.printf("Last Packet Recv from: %s\n", macStr);
Serial.printf("Last Packet Recv Time=%d,Datalength=%d \n\r", millis(),data_len);
}
if (data_len==58)
{
monFlag=1;
}
//-------------------ch read-----------------------
n++;
if (mac_addr[5]==0x4c)//BOX 1
{
ch=0;
ch0N++;
ch0Flag=1;
ch_Flag=0;
}//BOX No1
if (mac_addr[5]==0x30)//BOX 2
{
ch=1;
ch1N++;
ch1Flag=1;
ch_Flag=1;
}//BOX No2
//Serial.print("Rcved:ch=");
//Serial.print(ch);
//Serial.print("data_len=");
//Serial.println(data_len);
delay(5);
//Serial.print("data[29]=");
// Serial.println(data[29],HEX);
//========= sdFlag=Loggin Trigger===========================
sdFlag_1=sdFlag;
//sdFlag=data[29];
if (sdFlag==1 && sdFlag_1==0)
{
//firstFlag=1;
Serial.println("------------sdFlag chaged =>1---------------");
t_1=millis();
}
else if (sdFlag==0 && sdFlag_1==1)
{
//firstFlag=0;
Serial.println("------------sdFlag chaged =>0---------------");
}
else if (sdFlag==sdFlag_1 )
{
//firstFlag=0;
}
//=============================================
/*
Serial.print("RCVED():Head[");
Serial.print(ch);
Serial.print("]=");
Serial.print(Head[ch]);
Serial.print("data[54]=");
Serial.print(data[sNo+54],HEX);
Serial.print("data[55]=");
Serial.print(data[sNo+55],HEX);
Serial.print("data[56]=");
Serial.print(data[sNo+56],HEX);
Serial.print("data[57]=");
Serial.print(data[sNo+57],HEX);
*/
//timestamp--------------------------------------------------------------------
imonth=int(data[sNo+7]);//52=>7
iday=int(data[sNo+8]);//53=>8
ihour=int(data[sNo+9])+9;//54=>9
if (ihour>24)
{
ihour=ihour-24;
iday=iday+1;
}
imin=int(data[sNo+10]);//55=>10
isec=int(data[sNo+11]);//56=>11
String timestr=String(imonth)+"-"+String(iday)+"-"+String(ihour)+"-"+String(imin)+"-"+String(isec);
if(sdFlag==0x01)//LogTime tim
{
t=millis();
tim=int((t-t_1)/60000);
M5.Lcd.fillRect(0,80,80,15,BLACK);
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(0,80);
M5.Lcd.printf("Log=%2dmin",tim);
//M5.Lcd.setCursor(240,30);
//M5.Lcd.print(tim);
}
//--------------------------------------------------------------------------------------------
//SD writing----------------------------
//SD logging-----------------------------------------------------------------------------
String str="";
String strTotal="";
if (sdFlag==1)
{
//-----Filename make and FileOpen---------------------------
if(firstFlag==1)//sdFlag 0=1 changed firstFlag=1
{
Serial.print("======sdFlag=1 GO sd MonitorLog=====");
sNo=0;
stime="/"+timestr+".txt";//timestr YY-MM-HH-MM-SS
Serial.print("OPEN SD fname=");
Serial.println(stime);
file = SD.open(stime, FILE_WRITE);
if(!file){
Serial.println("Failed to open file for writing");
return;
}
firstFlag=0;
}
// uint8_t data文字列変換 => str => charArray
int ci;
//ch header print file
strTotal=String(ch);
for(ci=0;ci<57;ci++)
{
str=String(data[ci],HEX);
strTotal=strTotal+","+str;
}
strTotal=strTotal+"\n\r";// Last add CRLF
Serial.print(strTotal);
file.print(strTotal);
}//SD flag==1
//}// A set SDwriting finished
//--------------------------------------------------
//Display Pameter Claculation & Plot
//BOX 1 Log Color Change----------------
if (sdFlag==0x01 )//Logging ON
{
Col1=0xF81F;
Col2=0xF81F;
}
else if (sdFlag==0x00)//Loggin OFF
{
Col1=0xffff;
Col2=0xFFE0;
tim=0;
}
// M5.Lcd.setTextSize(1);
// Serial.print("ch=");
// Serial.print(ch);
//Serial.print("Nextchflag=");
// Serial.println(Nextchflag);
//^^^^^^^^^^^^Data Cal^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// for (i=0;i<57;i++)
// {
// if (ch==0)
// {
// CH0data[i]=data[i];
// }
// else
// {
// CH1data[i]=data[i];
// }
// }
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//^^^^^^^^^^^^^^^^^^500msec period Display^^^^^^^^^^^^^^^^^^^^^^^^^^
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if (ch0N%8==0 || ch1N%8==0 ) // one Display time at 500msec 2chx4
{
if(monFlag==1)
{
//=================Flag check=======================================
Serial.print("monFlag=");
Serial.print(monFlag);
Serial.print("sdFlag=");
Serial.print(sdFlag);
Serial.print(":");
//----dataCal-----------------------
int sNo=0;
// iTow U4
iTow[ch]=B2L(data[sNo+4],data[sNo+3],data[sNo+2],data[sNo+1]);//headMot上位ー>下位 ofset64+6
numSV[ch]=data[sNo+12];
Long[ch]=B2L(data[sNo+16],data[sNo+15],data[sNo+14],data[sNo+13]);//Longtitude上位ー>下位
Long[ch]=Long[ch];//%100000;
Lati[ch]=B2L(data[sNo+20],data[sNo+19],data[sNo+18],data[sNo+17]);//latitude 上位ー>下位
Lati[ch]=Lati[ch];//%100000;
Seah[ch]=B2L(data[sNo+24],data[sNo+23],data[sNo+22],data[sNo+21]);//headMot上位ー>下位 ofset64+6
Seah[ch]=Seah[ch];//*0.001;//mm=>m
Acc2d[ch]=B2L(data[sNo+28],data[sNo+27],data[sNo+26],data[sNo+25]);//Accuracy 2D 上位ー>下位
gSpeed[ch]=B2L(data[sNo+33],data[sNo+32],data[sNo+31],data[sNo+30]);//gSpeed上位ー>下位 ofset60+6
gSpeed[ch]=gSpeed[ch];//*0.0036;// gSpeed 1mm/sec=> 0.0036kmh
headMot[ch]=B2L(data[sNo+37],data[sNo+36],data[sNo+35],data[sNo+34]);//headMot上位ー>下位 ofset64+6
headMot[ch]=headMot[ch];///100000;//headMot 1= 0.00001 deg
relN[ch]=B2L(data[sNo+41],data[sNo+40],data[sNo+39],data[sNo+38]);
relE[ch]=B2L(data[sNo+45],data[sNo+44],data[sNo+43],data[sNo+42]);
relD[ch]=B2L(data[sNo+49],data[sNo+48],data[sNo+47],data[sNo+46]);
Length[ch]=B2L(data[sNo+53],data[sNo+52],data[sNo+51],data[sNo+50]);
Head[ch]=B2L(data[sNo+57],data[sNo+56],data[sNo+55],data[sNo+54]);
Head[ch]=int(Head[ch]/100000);
/*
Serial.print("dataCal():Head[");
Serial.print(ch);
Serial.print("]=");
Serial.print(Head[ch]);
Serial.print("data[54]=");
Serial.print(data[sNo+54],HEX);
Serial.print("data[55]=");
Serial.print(data[sNo+55],HEX);
Serial.print("data[56]=");
Serial.print(data[sNo+56],HEX);
Serial.print("data[57]=");
Serial.print(data[sNo+57],HEX);
Serial.println();
Serial.print("dataCal:iTow[");
Serial.print(ch);
Serial.print("]=");
Serial.println(iTow[ch]);
//--CH0 CAL----------------------------------------
int sNo=0;
// iTow U4
iTow[0]=B2L(CH0data[sNo+4],CH0data[sNo+3],CH0data[sNo+2],CH0data[sNo+1]);//headMot上位ー>下位 ofset64+6
numSV[0]=CH0data[sNo+12];
Long[0]=B2L(CH0data[sNo+16],CH0data[sNo+15],CH0data[sNo+14],CH0data[sNo+13]);//Longtitude上位ー>下位
Long[0]=Long[ch];//%100000;
Lati[0]=B2L(CH0data[sNo+20],CH0data[sNo+19],CH0data[sNo+18],CH0data[sNo+17]);//latitude 上位ー>下位
Lati[0]=Lati[ch];//%100000;
Seah[0]=B2L(CH0data[sNo+24],CH0data[sNo+23],CH0data[sNo+22],CH0data[sNo+21]);//headMot上位ー>下位 ofset64+6
Seah[0]=Seah[ch];//*0.001;//mm=>m
Acc2d[0]=B2L(CH0data[sNo+28],CH0data[sNo+27],CH0data[sNo+26],CH0data[sNo+25]);//Accuracy 2D 上位ー>下位
gSpeed[0]=B2L(CH0data[sNo+33],CH0data[sNo+32],CH0data[sNo+31],CH0data[sNo+30]);//gSpeed上位ー>下位 ofset60+6
gSpeed[0]=gSpeed[ch];//*0.0036;// gSpeed 1mm/sec=> 0.0036kmh
headMot[0]=B2L(CH0data[sNo+37],CH0data[sNo+36],CH0data[sNo+35],CH0data[sNo+34]);//headMot上位ー>下位 ofset64+6
headMot[0]=headMot[ch];///100000;//headMot 1= 0.00001 deg
relN[0]=B2L(CH0data[sNo+41],CH0data[sNo+40],CH0data[sNo+39],CH0data[sNo+38]);
relE[0]=B2L(CH0data[sNo+45],CH0data[sNo+44],CH0data[sNo+43],CH0data[sNo+42]);
relD[0]=B2L(CH0data[sNo+49],CH0data[sNo+48],CH0data[sNo+47],CH0data[sNo+46]);
Length[0]=B2L(CH0data[sNo+53],CH0data[sNo+52],CH0data[sNo+51],CH0data[sNo+50]);
Head[0]=B2L(CH0data[sNo+57],CH0data[sNo+56],CH0data[sNo+55],CH0data[sNo+54]);
Head[0]=int(Head[ch]/100000);
//------------------------------------------------------------
//dataCal(1,CH1data);
//CH1Cal------------------------------------------------------------------------------------------------
//int sNo=0;
// iTow U4
iTow[1]=B2L(CH1data[sNo+4],CH1data[sNo+3],CH1data[sNo+2],CH1data[sNo+1]);//headMot上位ー>下位 ofset64+6
numSV[1]=CH1data[sNo+12];
Long[1]=B2L(CH1data[sNo+16],CH1data[sNo+15],CH1data[sNo+14],CH1data[sNo+13]);//Longtitude上位ー>下位
Long[1]=Long[ch];//%100000;
Lati[1]=B2L(CH1data[sNo+20],CH1data[sNo+19],CH1data[sNo+18],CH1data[sNo+17]);//latitude 上位ー>下位
Lati[1]=Lati[ch];//%100000;
Seah[1]=B2L(CH1data[sNo+24],CH1data[sNo+23],CH1data[sNo+22],CH1data[sNo+21]);//headMot上位ー>下位 ofset64+6
Seah[1]=Seah[ch];//*0.001;//mm=>m
Acc2d[1]=B2L(CH1data[sNo+28],CH1data[sNo+27],CH1data[sNo+26],CH1data[sNo+25]);//Accuracy 2D 上位ー>下位
gSpeed[1]=B2L(CH1data[sNo+33],CH1data[sNo+32],CH1data[sNo+31],CH1data[sNo+30]);//gSpeed上位ー>下位 ofset60+6
gSpeed[1]=gSpeed[ch];//*0.0036;// gSpeed 1mm/sec=> 0.0036kmh
headMot[1]=B2L(CH1data[sNo+37],CH1data[sNo+36],CH1data[sNo+35],CH1data[sNo+34]);//headMot上位ー>下位 ofset64+6
headMot[1]=headMot[ch];///100000;//headMot 1= 0.00001 deg
relN[1]=B2L(CH1data[sNo+41],CH1data[sNo+40],CH1data[sNo+39],CH1data[sNo+38]);
relE[1]=B2L(CH1data[sNo+45],CH1data[sNo+44],CH1data[sNo+43],CH1data[sNo+42]);
relD[1]=B2L(CH1data[sNo+49],CH1data[sNo+48],CH1data[sNo+47],CH1data[sNo+46]);
Length[1]=B2L(CH1data[sNo+53],CH1data[sNo+52],CH1data[sNo+51],CH1data[sNo+50]);
Head[1]=B2L(CH1data[sNo+57],CH1data[sNo+56],CH1data[sNo+55],CH1data[sNo+54]);
Head[1]=int(Head[ch]/100000);
//------------------------------------------------------------------------------------------------------
*/
//--------Length Plot----------------------
int Lbaseline=190;
M5.Lcd.drawLine(0,Lbaseline,320,Lbaseline,GREEN);
M5.Lcd.drawLine(0,Lbaseline-20,320,Lbaseline-20,GREEN);
//Length
int px=int(n/8)%320;
int Lpy0=Lbaseline-int((Length[0])-92);
int Lpy1=Lbaseline-int((Length[1])-92);
M5.Lcd.drawPixel(px,Lpy0,RED);
M5.Lcd.drawPixel(px,Lpy1,MAGENTA);
M5.Lcd.setCursor(160,Lbaseline-10);
M5.Lcd.setTextSize(1);
M5.Lcd.setTextColor(GREEN);
M5.Lcd.print("Length 92cm");
//----------hAcc-----------------------------------
int Abaseline=150;
M5.Lcd.drawLine(0,Abaseline,320,Abaseline,BLUE);
M5.Lcd.drawLine(0,Abaseline-30,320,Abaseline-30,BLUE);
int Apy0=Abaseline-int((Acc2d[0]));
int Apy1=Abaseline-int((Acc2d[1]));
M5.Lcd.drawPixel(px,Apy0,WHITE);
M5.Lcd.drawPixel(px,Apy1,YELLOW);
M5.Lcd.setTextColor(BLUE);
M5.Lcd.setCursor(160,Abaseline-10);
M5.Lcd.setTextSize(1);
M5.Lcd.print("Acc2d");
//-------------------------------------------
Serial.print("ch=");
Serial.print(ch);
Serial.print(",");
Serial.print(millis());
Serial.print(",");
Serial.println(sdata);
//Serial.printf("ch%d:Acc2d=%d,numSV=%d,Length=%d,Long=%d,Lati=%d,relN=%d,relE=%d,relD=%d\n\r",ch,Acc2d[ch],numSV[ch],Length[ch],Long,Lati,relN,relE,relD);
//--------------------------------------------
M5.Lcd.fillRect(80,0,320,110,BLACK);
M5.Lcd.setTextSize(2);
M5.Lcd.setTextColor(YELLOW);
M5.Lcd.setCursor(160,0);
M5.Lcd.print(timestr);
M5.Lcd.setTextSize(1);
M5.Lcd.setTextColor(Col1);//White Text
M5.Lcd.setCursor(80,2);
M5.Lcd.printf("Acc:%2d[%2d]\r\n",Acc2d[0],numSV[0]);
//Large print Acc2d[0]-----------------------------------
M5.Lcd.setCursor(160,20);
M5.Lcd.setTextSize(2);
M5.Lcd.printf("Acc:%2d[%2d]",Acc2d[0],numSV[0]);
M5.Lcd.setCursor(160,40);
M5.Lcd.printf("Len:%2d\r\n",Length[0]);
//----------------------------------------------------
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(80,12);
M5.Lcd.printf("Len=%2d\r\n",Length[0]);
M5.Lcd.setCursor(80,22);
M5.Lcd.printf("relN=%2d\r\n",relN[0]);
M5.Lcd.setCursor(80,32);
M5.Lcd.printf("relE=%2d\r\n",relE[0]);
M5.Lcd.setCursor(80,42);
M5.Lcd.printf("relD=%2d\r\n",relD[0]);
M5.Lcd.setCursor(80,52);
M5.Lcd.printf("Ln=%2d\r\n",Long[0]);
M5.Lcd.setCursor(80,62);
M5.Lcd.printf("Lt=%2d\r\n",Lati[0]);
M5.Lcd.setCursor(80,71);
M5.Lcd.printf("Head=%2d\r\n",Head[0]);
//Serial.print("CH0_Head=");
//Serial.print(Head[0]);
M5.Lcd.fillRect(0,0,80,80,BLACK);
M5.Lcd.setTextSize(1);
M5.Lcd.setTextColor(Col2);//YELLOW Text
M5.Lcd.setCursor(0,2);
M5.Lcd.printf("Acc:%2d[%2d]\r\n",Acc2d[1],numSV[1]);
//----------Large Print Acc2d[1],Len[1]-----------------------------------
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(160,60);
M5.Lcd.printf("Acc:%2d[%2d]",Acc2d[1],numSV[1]);
M5.Lcd.setCursor(160,80);
M5.Lcd.printf("Len:%2d",Length[1]);
//----------------------------------------------------
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(0,12);
M5.Lcd.printf("Len=%2d\r\n",Length[1]);
M5.Lcd.setCursor(0,22);
M5.Lcd.printf("relN=%2d\r\n",relN[1]);
M5.Lcd.setCursor(0,32);
M5.Lcd.printf("relE=%2d\r\n",relE[1]);
M5.Lcd.setCursor(0,42);
M5.Lcd.printf("relD=%2d\r\n",relD[1]);
M5.Lcd.setCursor(0,52);
M5.Lcd.printf("Ln=%2d\r\n",Long[1]);
M5.Lcd.setCursor(0,62);
M5.Lcd.printf("Lt=%2d\r\n",Lati[1]);
M5.Lcd.setCursor(0,71);
M5.Lcd.printf("Head=%2d\r\n",Head[1]);
}//monFlag
else if(monFlag==0)
{
//M5.Lcd.fillScreen(BLACK);
}
}//n% 間引き
}//ESP RCV
//=============================================================================================
//================================SET UP=======================================================
//====================M5Stack LCD 320x240==================================================
void setup() {
M5.begin();
///---SD initialize------------
// Start SD card
if (!SD.begin())
{
M5.Lcd.println("ERROR: SD CARD.");
}
monFlag=0;
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setRotation(1); // M5.Lcd.print("ESP-NOW Test\n");
M5.Lcd.print("----SetUP-----\n");
// ESP-NOW初期化
WiFi.mode(WIFI_STA);
WiFi.disconnect();
if (esp_now_init() == ESP_OK) {
Serial.println("ESPNow Init Success");
M5.Lcd.print("ESPNow Init Success\n");
} else {
Serial.println("ESPNow Init Failed");
M5.Lcd.print("ESPNow Init Failed\n");
ESP.restart();
}
// マルチキャスト用Slave登録
memset(&slave, 0, sizeof(slave));
for (int i = 0; i < 6; ++i) {
slave.peer_addr[i] = (uint8_t)0xff;
}
esp_err_t addStatus = esp_now_add_peer(&slave);
if (addStatus == ESP_OK) {
// Pair success
Serial.println("Pair success");
}
// ESP-NOWコールバック登録
esp_now_register_send_cb(OnDataSent);
esp_now_register_recv_cb(OnDataRecv);
//MENU---------------------
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(10,210);
M5.Lcd.setTextColor(BLUE);
M5.Lcd.print("A:LOG");
M5.Lcd.setCursor(135,210);
M5.Lcd.setTextColor(YELLOW);
M5.Lcd.print("B:File");
M5.Lcd.setCursor(235,210);
M5.Lcd.setTextColor(RED);
M5.Lcd.print("C:Reset");
//-------------------------
//Monitor ON send
cdata[0] =0x6d;//'m' mFlag=1or0 Monitor Start
//initFlag=1;//init R zero level Long0,Lati0 Fix
esp_err_t result = esp_now_send(slave.peer_addr, cdata, 1);
}
void loop() {
M5.update();
delay(1);
//digitalWrite(LED_PIN,LOW);
// Aボタンを押したら送信 ---------------------------------------------------------------------
if ( M5.BtnA.wasPressed() ) {// buttonA=>Start SD log
Serial.println("Push Button A");
cdata[0] =0x73;//'s' sdFlag=1or0 Logging Start
esp_err_t result = esp_now_send(slave.peer_addr, cdata, 1);
sdFlag=1;
firstFlag=1;
/*
if (sdFlag==0)
{
sdFlag=1;
M5.Lcd.setCursor(0,90);
M5.Lcd.print("Log");
}
if (sdFlag==1)
{
sdFlag=0;
M5.Lcd.fillRect(0,90,160,100,BLACK);
}
*/
}
delay(1);
//Bボタンを押したら送信 Loggin STOP File Dir---------------------------------------------------------------------
if (M5.BtnB.wasPressed()) {
file.close();
delay(10);
cdata[0] =0x73;//'s' sdFlag=1or0 Logging Start
esp_err_t result = esp_now_send(slave.peer_addr, cdata, 1);
sdFlag=0;
M5.Lcd.fillRect(0,80,160,15,BLACK);
M5.Lcd.setCursor(0,80);
M5.Lcd.setTextSize(1);
M5.Lcd.print(stime);
/*
root = SD.open("/");
printDirectory(root, 0);
for (i=1;i<kaisu;i++)
{
Serial.print(i);
Serial.print(":");
Serial.println(sdfname[i]);
}
M5.Lcd.setCursor(0,120);
M5.Lcd.setTextSize(1);
M5.Lcd.print(kaisu);
M5.Lcd.print(":");
M5.Lcd.print(sdfname[kaisu-1]);
*/
}
//Cボタンを押したら送信 ---------------------------------------------------------------------
if (M5.BtnC.wasPressed()) {
//f.close();
//M5.Lcd.println("C:File close");
esp_restart();
}
}//loop end
//------------------------sd file --------------------------------------
void printDirectory(File dir, int numTabs) {
while(true) {
kaisu++;
File entry = dir.openNextFile();
if (! entry) {
dir.rewindDirectory();
break;
}
for (uint8_t i=0; i<numTabs; i++) {
M5.Lcd.print('\t');
}
//M5.Lcd.setTextSize(1);
//M5.Lcd.print(String(kaisu));
sdfname[kaisu]=entry.name();
//Serial.println(kaisu);
//Serial.print(":");
//Serial.println(sdfname[kaisu]);
//M5.Lcd.printf("Sd read files =%d\n\r",kaisu);
//M5.Lcd.print(entry.name());
if (kaisu>24)
{
// M5.Lcd.setCursor(0,20);
}
if (entry.isDirectory()) {
//M5.Lcd.setCursor(0,20);
//M5.Lcd.println("/");
printDirectory(entry, numTabs+1);
} else {
// M5.Lcd.println("\t\t");
//M5.Lcd.println(entry.size(), DEC);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment