プログラムの解説記事で、ソースコードの表示で、プラグインを使ったり、GISTから挿入する方法がありますが、CSSをいじったりするのを避けたいので、コンテンツだけでいじる方法を考えました。
デフォルト機能のテーブルを使う方法を使うと、慣れているので、簡単にできました。
表をつくるのは、EXCELにAruduinoIDEからコピーして貼りこんで、行数分の表ができるので丸ごと
コピーして、WordPressの投稿にペーストすれば、ソースコードの表ができます。
テーブル 表のプロパティ 高度な設定 背景色 で黒にして、
あとは、文字色を変えて、説明文をいれれれば、簡単で、見やすいソースコード説明表ができます。
// Simple test of USB Host Mouse/Keyboard |
// |
// This example is in the public domain |
//—–SD log |
#include <SD.h> |
#include <SPI.h> |
int i,j,k,n; |
const int chipSelect =BUILTIN_SDCARD;// 10; |
String dataString,dataString1; |
//—–USB HOST |
#include “USBHost_t36.h” |
#define USBBAUD 115200 |
uint32_t baud = USBBAUD; |
uint32_t format = USBHOST_SERIAL_8N1; |
USBHost myusb; |
USBHub hub1(myusb); |
USBHub hub2(myusb); |
USBHIDParser hid1(myusb); |
USBHIDParser hid2(myusb); |
USBHIDParser hid3(myusb); |
USBSerial_BigBuffer userial(myusb); |
USBSerial_BigBuffer userialb(myusb); |
USBSerial_BigBuffer userialb2(myusb); |
uint8_t buf1[200],buf2[200],buf3[200]; |
uint8_t dummy; |
char data0,datab,datab2; |
USBDriver *drivers[] = {&hub1, &hub2, &hid1, &hid2, &hid3, &userial, &userialb, &userialb2}; |
#define CNT_DEVICES (sizeof(drivers)/sizeof(drivers[0])) |
const char * driver_names[CNT_DEVICES] = {“Hub1”, “Hub2”, “HID1”, “HID2”, “HID3”, “USERIAL1”, “USERIALB”, “USERIALB2” }; |
bool driver_active[CNT_DEVICES] = {false, false, false, false}; |
//Data |
uint8_t Buf172[172]; |
uint8_t PVTdata[100]; |
long PVTval[33]; |
uint8_t RELPOSdata[72]; |
long RELPOSval[21]; |
long itowP,itowP_1; |
long itowR,itowR_1; |
uint8_t fdata[4]; |
uint8_t UShead[20],USBhead[20],USB2head[20]; |
int bufN_1,bufN_2,bufN_3; |
uint8_t buff[100]; |
int Num1,Num2,Num3; |
int oldNum1,oldNum2,oldNum3; |
int OKflag=0; |
int PVTflag=0; |
int RELPOSflag=0; |
int Firstflag=1; |
char keyin; |
int Startflag=0; |
//timestamp |
char fnameB[30];//UBX Binary File name |
char fnameV[30];//UBX Value File name NAV-PVT+NAV-RELPOSNED |
int Sflag=0; |
//================================================================= |
void setup() |
{ |
Serial.begin(460800); |
pinMode(13, OUTPUT); |
pinMode(2, OUTPUT); |
pinMode(3, OUTPUT); |
for (int i = 0; i < 5; i++) { |
digitalWrite(2, HIGH); |
delayMicroseconds(50); |
digitalWrite(2, LOW); |
delayMicroseconds(50); |
} |
while (!Serial && (millis() < 5000)) ; // wait for Arduino Serial Monitor |
Serial.println(“\n\nUSB Host Testing – Serial”); |
myusb.begin(); |
Serial1.begin(115200); // We will echo stuff Through Serial1… |
//———–SD CARD Initialize—————— |
// see if the card is present and can be initialized: |
if (!SD.begin(chipSelect)) { |
Serial.println(“Card failed, or not present”); |
} |
//SD.remove(“datalog.txt”);//旧ファイルを消去 |
Serial.println(“card initialized.”); |
Sflag=0; |
}//set up |
//======================================================================================= |
//==========LOOP ======================================================================== |
//======================================================================================= |
void loop(){ |
digitalWrite(13, !digitalRead(13)); |
myusb.Task(); |
updateDeviceList(); |
//*********************************************************** |
//****************DATA ACQUSITION From USB HOST************** |
//*********************************************************** |
//—USB HOST Ports read————————– |
//2ポートのデータをBuf172[]にまとめて収納1周期トータル172byteなので順不同で配列に格納して後で、ばらす。 |
while(userial.available()){ |
Buf172[Num1]=userial.read(); |
Num1++; |
}//—USERIAL read finished——————— |
//—USERIALB Port read——————- |
while(userialb.available()){ |
Buf172[Num1]=userialb.read(); |
Num1++; |
}//useralb read finished |
//:::::::::: Logging & Monitoring data process 172bytes:::::::::::::::::::::: |
//1周期分のデータ取得終了であと90msecあるのでその間に各種処理を行う |
if(Num1>=172){ //a MB data read finished |
Num1=0; |
//—-PVT RELPOS Deviding— 172byteのデータの先頭がPVTかRELPSOか判別して、PVTdata[]RELPOSdata[]に仕分ける—————————————– |
if(Buf172[0] == 0xB5 && Buf172[1] == 0x62 && Buf172[2] == 0x01 && Buf172[3] == 0x07){//1st PVT Header |
for (i=0;i<100;i++){ |
PVTdata[i]=Buf172[i]; |
} |
for (i=100;i<172;i++){ |
RELPOSdata[i-100]=Buf172[i]; |
} |
}//if end |
else if(Buf172[0] == 0xB5 && Buf172[1] == 0x62 && Buf172[2] == 0x01 && Buf172[3] == 0x3C){//1st RELPOS Header |
for(i=0;i<72;i++){ |
RELPOSdata[i]=Buf172[i]; |
} |
for(i=72;i<172;i++){ |
PVTdata[i-72]=Buf172[i]; |
} |
}//else end |
//PVTdataとRELPOSdataをUBX実データに変換してPVTval[33]とRELPOSval[21]に格納 |
//——-PVTcnv,RELPOScnv———- |
int result=PVTcnv(PVTdata,PVTval); |
result=RELPOScnv(RELPOSdata,RELPOSval); |
if (PVTval[11]==131 && Sflag==0){//start |
Sflag=1; |
//ファイル名をタイムスタンプで作る |
//PVTval[1]=Year/[2]=Month/[3]=Day/[4]=Hour/[5]=Min/[6]=sec |
int JST=(PVTval[4]+9)%24;//UTC hourをJSTに変換 |
String stime=String(PVTval[2],DEC)+”-“+String(PVTval[3],DEC)+”-“+String(JST,DEC)+”-“+String(PVTval[5],DEC);//MMDDHHMM |
String stimeB=”/”+stime+”.ubx”;//UBX Binary File |
String stimeV=”/”+stime+”.txt”;//UBX Value Text File |
int slenB=stimeB.length()+1; |
int slenV=stimeV.length()+1; |
//ファイル名はchar配列なのでStringからchar配列変換 fname[]を得る |
stimeB.toCharArray(fnameB,slenB);//stimeB to fnameB[] chara Array |
stimeV.toCharArray(fnameV,slenV);//stimeV to fnameV[] chara Array |
Serial.println(); |
Serial.print(“fnameB=”); |
Serial.print(stimeB); |
Serial.print(“/fnameV=”); |
Serial.println(stimeV); |
Serial.print(“TimeStamp:Sflag=”); |
Serial.println(Sflag); |
} |
//SD Write |
if (PVTval[11]==131 ){//start |
Serial.print(“SD OPEN_time=”); |
Serial.println(millis()); |
//File dataFile = SD.open(“PVT_RELPOS.ubx”, FILE_WRITE); |
File dataFile = SD.open(fnameB, FILE_WRITE); |
delay(1);//<==このdelay重要これがないとコケル(外部デバイスとのアクセス初めでCPUが待てないで突っ走ることがあるので1msecほど外部デバイスの余裕をあげる必要有) |
n=0; |
Serial.print(“PVT_Binary_dataFile=”); |
Serial.println(dataFile); |
if (dataFile) { |
while(n<100){//PVT write to SD card |
//delayMicroseconds(20); |
//–if (dataFile) { |
dataFile.write(PVTdata[n%100]); |
//} else { |
// if the file isn’t open, pop up an error: |
// Serial.println(“PVT write error opening datalog.txt”); |
//} |
n++; |
}//PVT write finished |
n=0; |
while(n<72){; |
if (dataFile) { |
dataFile.write(RELPOSdata[n%72]); |
} else { |
// if the file isn’t open, pop up an error: |
//Serial.println(“RELPOS write error opening datalog.txt”); |
} |
n++; |
}//RELPOS write finished |
} else { |
// if the file isn’t open, pop up an error: |
Serial.println(“PVT write error opening datalog.txt”); |
} |
dataFile.close(); |
Serial.print(“SD closed time=”); |
Serial.print(millis()); |
//Serial.println(“SD closed write Finished”); |
}//SD Write end |
/* |
Serial.println(); |
Serial.print(“PVTval:”); |
for(i=0;i<33;i++){ |
Serial.print(PVTval[i]); |
Serial.print(“,”); |
} |
Serial.println(); |
Serial.println(); |
Serial.print(“RELPOSval:”); |
for(i=0;i<21;i++){ |
Serial.print(RELPOSval[i]); |
Serial.print(“,”); |
} |
Serial.println(); |
*/ |
/* |
//SD LOGの自動開始タイミングは、PVTのflags=131でRTK FIXする時LOGスタート=>PVTval[11]=131まで待つ |
Serial.print(PVTval[11]); |
Serial.print(“,”); |
if (PVTval[11]==131 && Sflag==0){//start |
Sflag=1; |
//ファイル名をタイムスタンプで作る |
//PVTval[1]=Year/[2]=Month/[3]=Day/[4]=Hour/[5]=Min/[6]=sec |
int JST=(PVTval[4]+9)%24;//UTC hourをJSTに変換 |
String stime=String(PVTval[2],DEC)+”-“+String(PVTval[3],DEC)+”-“+String(JST,DEC)+”-“+String(PVTval[5],DEC);//MMDDHHMM |
String stimeB=”/”+stime+”.ubx”;//UBX Binary File |
String stimeV=”/”+stime+”.txt”;//UBX Value Text File |
int slenB=stimeB.length()+1; |
int slenV=stimeV.length()+1; |
//ファイル名はchar配列なのでStringからchar配列変換 fname[]を得る |
stimeB.toCharArray(fnameB,slenB);//stimeB to fnameB[] chara Array |
stimeV.toCharArray(fnameV,slenV);//stimeV to fnameV[] chara Array |
Serial.println(); |
Serial.print(“fnameB=”); |
Serial.print(stimeB); |
Serial.print(“/fnameV=”); |
Serial.println(stimeV); |
Serial.print(“TimeStamp:Sflag=”); |
Serial.println(Sflag); |
} |
//================SD CARD Writing======================================== |
//RTK周期100msecと時間余裕があるので毎回ファイルをOPEN CLOSEする |
// open the file. |
Serial.print(“Loop:Sflag=”); |
Serial.println(Sflag); |
if(Sflag==1){ |
Serial.println(“—Binary FILE Open”); |
//Binaryファイル保存 NAV-PVT+NAV-RELPOSNED |
File dataFile = SD.open(“BinaryFile.UBX”, FILE_WRITE);//追記モード |
if (dataFile){ |
Serial.println(“DataFile writing Binary”); |
dataFile.write(PVTdata[0]); |
/* |
for(i=0;i<100;i++){//PVTdata log |
dataFile.write(PVTdata[i]); |
} |
for(i=0;i<72;i++){ |
dataFile.write(RELPOSdata[i]); |
} |
} |
dataFile.close(); |
//TEXTファイル保存 NAV-PVT値とNAV-RELPOSNED値 |
Serial.println(“—Text FILE Open”) ; |
dataFile=SD.open(“TextFile.txt”,FILE_WRITE);//追記モード |
if(dataFile){ |
Serial.println(“DataFile writing Text”); |
for(i=0;i<33;i++){//PVTval log |
dataFile.print(PVTval[i]); |
} |
dataFile.println();//改行 |
for(i=0;i<21;i++){//RELPOSval log |
dataFile.print(RELPOSval[i]); |
} |
} |
dataFile.close(); |
}// SD log end |
*/ |
}// if 172 end |
}//loop finished |
//====================================================================================== |
//==================LOOP END============================================================ |
//====================================================================================== |
void updateDeviceList() { |
// Print out information about different devices. |
for (uint8_t i = 0; i < CNT_DEVICES; i++) { |
if (*drivers[i] != driver_active[i]) { |
if (driver_active[i]) { |
Serial.printf(“*** Device %s – disconnected ***\n”, driver_names[i]); |
driver_active[i] = false; |
} else { |
Serial.printf(“*** Device %s %x:%x – connected ***\n”, driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct()); |
driver_active[i] = true; |
const uint8_t *psz = drivers[i]->manufacturer(); |
if (psz && *psz) Serial.printf(” manufacturer: %s\n”, psz); |
psz = drivers[i]->product(); |
if (psz && *psz) Serial.printf(” product: %s\n”, psz); |
psz = drivers[i]->serialNumber(); |
if (psz && *psz) Serial.printf(” Serial: %s\n”, psz); |
// If this is a new Serial device. |
if (drivers[i] == &userial) { |
// Lets try first outputting something to our USerial to see if it will go out… |
userial.begin(baud); |
} |
if (drivers[i] == &userialb) { |
// Lets try first outputting something to our USerial to see if it will go out… |
userialb.begin(baud); |
} |
if (drivers[i] == &userialb2) { |
// Lets try first outputting something to our USerial to see if it will go out… |
userialb2.begin(baud); |
} |
} |
} |
} |
} |
bool CompareStrings(const char *sz1, const char *sz2) { |
while (*sz2 != 0) { |
if (toupper(*sz1) != toupper(*sz2)) |
return false; |
sz1++; |
sz2++; |
} |
return true; // end of string so show as match |
} |
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
int PVTcnv(uint8_t d[100],long pvt[33]){ |
//PVT header[0-6] |
//0:itow[6-9] |
pvt[0]=B2L(d[9],d[8],d[7],d[6]); |
//1:year[10-12] |
pvt[1]=d[10]+d[11]*256; |
//2:month[12] |
pvt[2]=d[12]; |
//3:day[13] |
pvt[3]=d[13]; |
//4:hour[14] |
pvt[4]=d[14]; |
//5:min[15] |
pvt[5]=d[15]; |
//6:sec[16] |
pvt[6]=d[16]; |
//7:valid[17] |
pvt[7]=d[17]; |
//8:tAcc[18-21] |
pvt[8]=B2L(d[21],d[20],d[19],d[18]); |
//9:nano[22-25] |
pvt[9]=B2L(d[25],d[24],d[23],d[22]); |
//10:fixType[26] |
pvt[10]=d[26]; |
//11:flags[27] This is Fix status 131 |
pvt[11]=d[27]; |
//12:flags2[28] |
pvt[12]=d[28]; |
//13:numSV[29] |
pvt[13]=d[29]; |
//14:lon[30-33] |
pvt[14]=B2L(d[33],d[32],d[31],d[30]); |
//15:lat[34-37] |
pvt[15]=B2L(d[37],d[36],d[35],d[34]); |
//16:height[38-41] |
pvt[16]=B2L(d[41],d[40],d[39],d[38]); |
//17:hMSL[42-45] |
pvt[17]=B2L(d[45],d[44],d[43],d[42]); |
//18:hAcc[46-49] |
pvt[18]=B2L(d[49],d[48],d[47],d[46]); |
//19:vAcc[50-53] |
pvt[19]=B2L(d[53],d[52],d[51],d[50]); |
//20:velN[54-57] |
pvt[20]=B2L(d[57],d[56],d[55],d[54]); |
//21:velE[58-61] |
pvt[21]=B2L(d[61],d[60],d[59],d[58]); |
//22:velD[62-65] |
pvt[22]=B2L(d[65],d[64],d[63],d[62]); |
//23:gSpeed[66-69] |
pvt[23]=B2L(d[69],d[68],d[67],d[66]); |
//24:headMot[70-73] |
pvt[24]=B2L(d[73],d[72],d[71],d[70]); |
//25:sAcc[74-77] |
pvt[25]=B2L(d[77],d[76],d[75],d[74]); |
//26:headAcc[78-81] |
pvt[26]=B2L(d[81],d[80],d[79],d[78]); |
//27:pDOP[82-83] |
pvt[27]=d[82]+d[83]*256; |
//28:flags3[84] |
pvt[28]=d[84]; |
//29:reserved1[85] |
pvt[29]=d[85]; |
//30:headVeh[86-89] |
pvt[30]=B2L(d[89],d[88],d[87],d[86]); |
//31:magDec[90-91] |
pvt[31]=d[90]+d[91]*256; |
//32:magAcc[92-93] |
pvt[32]=d[92]+d[93]*256; |
}//PVTcnv() end |
//–RELPOScnv————————— |
int RELPOScnv(uint8_t d[72],long relpos[20]){ |
//RELPOS header[0-5] |
int s=0; |
//0:ver[6] |
relpos[0]=d[s+6]; |
//1:reserved1[7] |
relpos[1]=d[s+7]; |
//2:refStationId[8] |
relpos[2]=d[s+8]; |
//3:itow[10-13] |
relpos[3]=B2L(d[s+13],d[s+12],d[s+11],d[s+10]); |
//4:relposN[14-17] |
relpos[4]=B2L(d[s+17],d[s+16],d[s+15],d[s+14]); |
//5:relposE[18-21] |
relpos[5]=B2L(d[s+21],d[s+20],d[s+19],d[s+18]); |
//6:relposD[22-25] |
relpos[6]=B2L(d[s+25],d[s+24],d[s+23],d[s+22]); |
//7:relposLength[26-29] |
relpos[7]=B2L(d[s+29],d[s+28],d[s+27],d[s+26]); |
//8:relposHeading[30-33] |
relpos[8]=B2L(d[s+33],d[s+32],d[s+31],d[s+30]); |
//9:reserved2[34] |
relpos[9]=B2L(d[s+34],d[s+33],d[s+32],d[s+31]); |
//10:relposHPN[35] |
relpos[10]=127-int(d[s+35]); |
//11:relposHPE[36] |
relpos[11]=127-int(d[s+36]); |
//12:relposHPD[37] |
relpos[12]=127-int(d[s+37]); |
//13:relposHPLength[38] |
relpos[13]=127-int(d[s+38]); |
//14:accN[38-41] |
relpos[14]=B2L(d[s+41],d[s+40],d[s+39],d[s+38]); |
//15:accE[42-45] |
relpos[15]=B2L(d[s+45],d[s+44],d[s+43],d[s+42]); |
//16:accD[46-49] |
relpos[16]=B2L(d[s+49],d[s+48],d[s+47],d[s+46]); |
//17:accLength[50-53] |
relpos[17]=B2L(d[s+53],d[s+52],d[s+51],d[s+50]); |
//18:accHeading[54-57] |
relpos[18]=B2L(d[s+57],d[s+56],d[s+55],d[s+54]); |
//19:reserved[57-60] |
relpos[19]=B2L(d[s+60],d[s+59],d[s+58],d[s+57]); |
//20:flags[60-63] |
relpos[20]=B2L(d[s+63],d[s+62],d[s+61],d[s+60]); |
} |
//+++++++++++++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); |
long su; |
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; |
} |
//================================================================================= |
//+++++++++++++++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; |
} |
//++++++++++++++++String to CharArray Trans++++++++++++++++++++ |
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); |
} |