diff --git a/.gitignore b/.gitignore index 07c1cea..b038a82 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,7 @@ .DS_Store +# サンプルソースの全ビルドテストログ +SampleSrc/log.txt +# サンプルソースコンパイル時にファイル名を仮置きするためのファイル +SampleSrc/TestBuild/ino_filename diff --git a/M5StickCPlus_FactoryTest2022.ino b/M5StickCPlus_FactoryTest2022.ino index 9216c8a..120a32a 100644 --- a/M5StickCPlus_FactoryTest2022.ino +++ b/M5StickCPlus_FactoryTest2022.ino @@ -1683,7 +1683,7 @@ } #ifdef ENABLE_OTA -const char *ssid = "miura2g"; +const char *ssid = "ics-ap"; const char *password = "jikkenics"; void OTA_Setup() { diff --git a/SampleSrc/TestBuild/compile.sh b/SampleSrc/TestBuild/compile.sh index aa75950..804bba0 100755 --- a/SampleSrc/TestBuild/compile.sh +++ b/SampleSrc/TestBuild/compile.sh @@ -2,4 +2,11 @@ # get folder name, and set to [dir] variable. dir=${PWD##*/} -arduino-cli compile --fqbn esp32:esp32:m5stick-c --export-binaries ${dir}.ino +arduino-cli compile --fqbn esp32:esp32:m5stick-c --export-binaries --output-dir build ${dir}.ino + +if [ -f ino_filename ]; then + tmpfname=`cat ino_filename` + fname="${tmpfname%.*}" + echo ${fname} + cp build/TestBuild.ino.bin build/${fname}.bin.img +fi diff --git a/SampleSrc/Upload.sh b/SampleSrc/Upload.sh index 9fc6e91..852ae5f 100755 --- a/SampleSrc/Upload.sh +++ b/SampleSrc/Upload.sh @@ -6,6 +6,7 @@ port=$2 echo "compile ${file} and upload to ${port}" cp ${file} TestBuild/TestBuild.ino + echo ${file} > TestBuild/ino_filename cd TestBuild ./compile.sh 2>&1 && ./upload.sh ${port} 2>&1 cd .. @@ -18,6 +19,7 @@ file=$1 echo "compile ${file} and upload" cp ${file} TestBuild/TestBuild.ino + echo ${file} > TestBuild/ino_filename cd TestBuild ./compile.sh 2>&1 && ./upload.sh cd .. @@ -47,6 +49,7 @@ echo "$input : ${ary[$input]}" file=${ary[$input]} cp ${file} TestBuild/TestBuild.ino + echo ${file} > TestBuild/ino_filename cd TestBuild ./compile.sh && ./upload.sh #&& ./monitor.sh cd .. diff --git a/SampleSrc/_AllBuildTest.sh b/SampleSrc/_AllBuildTest.sh new file mode 100755 index 0000000..d05bef4 --- /dev/null +++ b/SampleSrc/_AllBuildTest.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +for p in *.ino ; do + echo ${p} Build Test + echo ${p} >> log.txt + cp ${p} TestBuild/TestBuild.ino + echo ${p} > TestBuild/ino_filename + cd TestBuild + ./compile.sh 2>>../log.txt + cd .. +done diff --git a/SampleSrc/_filememo.txt b/SampleSrc/_filememo.txt index c663eb1..bea2ec6 100644 --- a/SampleSrc/_filememo.txt +++ b/SampleSrc/_filememo.txt @@ -11,7 +11,6 @@ espnow01.ino :blue:: ESPNOW通信(数値の配列) espnow02.ino :blue:: ESPNOW通信(数値の配列:条件によって受信処理) espnow03.ino :blue:: ESPNOW通信(float,double,charをbyte配列にして送信) -factorytest.ino ::: x gasunit.ino :green:: CO2・ガスセンサ httpclient01.ino :#f09:: Web Client httpserver01.ino :#f09:: Web Server diff --git a/SampleSrc/espnow03.ino b/SampleSrc/espnow03.ino index c1f0d24..f228114 100644 --- a/SampleSrc/espnow03.ino +++ b/SampleSrc/espnow03.ino @@ -76,7 +76,7 @@ M5.Beep.update(); if (M5.BtnA.wasReleased()) { - uint8_t data[100] = {234}; // 送信データ uint8_tは0〜255の数値(1Byte) + uint8_t data[100] = {234}; // 送信データ 長さ100のbyte配列 uint8_tは0〜255の数値(1Byte) float pi = 3.14159265f; double dpi = 3.14159265358979323; const void* ppi = π @@ -84,8 +84,8 @@ // data[0] は1byte char 234 を、宣言時に設定した。 // そのあと、floatとdoubleを混載する。data[1]~data[4]はfloat (4byte) // data[5]~data[12]はdouble (8byte) - memcpy(data+1, ppi, sizeof(pi)); - memcpy(data+5, pdpi, sizeof(dpi)); + memcpy(data+1, ppi, sizeof(pi)); // data[1]〜data[4]に、piの値をfloat形式で保存 + memcpy(data+5, pdpi, sizeof(dpi)); // data[5]〜data[12]に、dpiの値をdouble形式で保存 // さらに、文字列をdata[13]から格納する sprintf((char *)data+13,"ABCDEFG_abcdefg"); // Store string (Line86) // さらに、送信側プログラムのコンパイル時刻をdata[28]から格納する @@ -104,10 +104,10 @@ M5.Lcd.setCursor(0, 0, 1); M5.Lcd.setTextColor(BLACK, CYAN); - float *ppi = (float*)&data[1]; + float *ppi = (float*)&data[1]; // byte列に保存していたfloat値を読み取るためのポインタ double *dppi = (double*)&data[5]; - M5.Lcd.printf("%.8f\n", *ppi); - M5.Lcd.printf("%.16f\n", *dppi); + M5.Lcd.printf("%.8f\n", *ppi); // float値を読み取って表示 + M5.Lcd.printf("%.16f\n", *dppi); // double値を読み取って表示 M5.Lcd.printf("%s\n", &data[13] ); // Print string stored at Line86 M5.Lcd.printf("%s\n", &data[28] ); // 送信側プログラムのコンパイル時刻 } diff --git a/SampleSrc/httpclient01.ino b/SampleSrc/httpclient01.ino index bd28bd7..aa5f107 100644 --- a/SampleSrc/httpclient01.ino +++ b/SampleSrc/httpclient01.ino @@ -2,7 +2,7 @@ #include #include // ステータスコードの定義もここにある -const char* ssid = "miura2g"; +const char* ssid = "ics-ap"; const char* password = "jikkenics"; diff --git a/SampleSrc/httpserver01.ino b/SampleSrc/httpserver01.ino index 1fb09c7..f7beb63 100644 --- a/SampleSrc/httpserver01.ino +++ b/SampleSrc/httpserver01.ino @@ -1,6 +1,6 @@ #include -const char* ssid = "miura2g"; +const char* ssid = "ics-ap"; const char* password = "jikkenics"; WiFiServer server(80); diff --git a/SampleSrc/line01.ino b/SampleSrc/line01.ino index e0f7c04..2e81a40 100644 --- a/SampleSrc/line01.ino +++ b/SampleSrc/line01.ino @@ -8,7 +8,7 @@ void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); - WiFiMulti.addAP("miura2g", "jikkenics"); + WiFiMulti.addAP("ics-ap", "jikkenics"); // wait for WiFi connection Serial.print("Waiting for WiFi to connect..."); diff --git a/SampleSrc/mqtt01pub.ino b/SampleSrc/mqtt01pub.ino index dad8d18..35e56f1 100644 --- a/SampleSrc/mqtt01pub.ino +++ b/SampleSrc/mqtt01pub.ino @@ -4,7 +4,7 @@ // ライブラリで PubSubClient をいれておく ★★★ 重要 ★★★ #include -const char* ssid = "miura2g"; +const char* ssid = "ics-ap"; const char* password = "jikkenics"; const char* server = "192.168.11.11"; // "mqtt.istlab.info"; diff --git a/SampleSrc/mqtt01sub.ino b/SampleSrc/mqtt01sub.ino index 0c4d2e5..41321b7 100644 --- a/SampleSrc/mqtt01sub.ino +++ b/SampleSrc/mqtt01sub.ino @@ -7,7 +7,7 @@ // (注意:Arduino_Json v0.1.0 は別物) #include -const char* ssid = "miura2g"; +const char* ssid = "ics-ap"; const char* password = "jikkenics"; const char* server = "192.168.11.11"; // "mqtt.istlab.info"; diff --git a/SampleSrc/ntp01.ino b/SampleSrc/ntp01.ino index 22487b6..fdf1dc1 100644 --- a/SampleSrc/ntp01.ino +++ b/SampleSrc/ntp01.ino @@ -1,6 +1,6 @@ #include -const char* ssid = "miura2g"; +const char* ssid = "ics-ap"; const char* password = "jikkenics"; void setup() { diff --git a/SampleSrc/ota01.ino b/SampleSrc/ota01.ino index 307dab3..ad448e7 100644 --- a/SampleSrc/ota01.ino +++ b/SampleSrc/ota01.ino @@ -2,7 +2,7 @@ #include #include -const char *ssid = "miura2g"; +const char *ssid = "ics-ap"; const char *password = "jikkenics"; void setup() diff --git a/SampleSrc/regexp01.ino b/SampleSrc/regexp01.ino index 5ac99bf..878e3a3 100644 --- a/SampleSrc/regexp01.ino +++ b/SampleSrc/regexp01.ino @@ -1,25 +1,59 @@ -#include +/** + * 辞書クラスの使用例 (&正規表現の利用) + */ +#include #include +#include Dictionary *dict = new Dictionary(); // 辞書/ハッシュ。キー文字列→値 を保持するデータ構造 -void match_callback (const char * match, // matching string (not null-terminated) - const unsigned int length, // length of matching string - const MatchState & ms) // MatchState in use (to get captures) +// param2dict関数のなかで使われるコールバック関数 +void match_callback(const char *match, // matching string (not null-terminated) + const unsigned int length, // length of matching string + const MatchState &ms) // MatchState in use (to get captures) { - char k [10]; // size must be large enough to hold captures - char v [10]; // size must be large enough to hold captures + char k[10]; // 配列サイズに注意。size must be large enough to hold captures + char v[10]; // 配列サイズに注意。size must be large enough to hold captures ms.GetCapture(k, 0); ms.GetCapture(v, 1); dict->insert(k, v); // 辞書に追加 (たとえば、 red→120 を追加) -} // end of match_callback +} // end of match_callback -// たとえば、*cbuf = "red=120&green=255&blue=9" のような文字列を想定する -void param2dict(char *cbuf){ - MatchState ms (cbuf); //正規表現マッチャーの作成 - ms.GlobalMatch ("([a-z]+)=([0-9]+)", match_callback); // (key)=(value) で複数回マッチングする。match_callback は別関数。 - int r = dict->search("red").toInt(); // 辞書 dict - int g = dict->search("green").toInt(); - int b = dict->search("blue").toInt(); - int32_t bgcolor = (int(r * 31 / 255) << 11) | (int(g * 63 / 255) << 5) | (int(b * 31 / 255)); +// 下のsetupからは使用していないが、文字列で受け取った複数のパラメータを辞書に設定するサンプル +// たとえば、*cbuf = "red=120&green=255&blue=100" のような文字列をうけとると、辞書に設定する。その後、色を表す整数値として返す +int32_t param2dict(char *cbuf) +{ + MatchState ms(cbuf); // 正規表現マッチャーの作成 + ms.GlobalMatch("([a-z]+)=([0-9]+)", match_callback); // (key)=(value) で複数回マッチングする。match_callback は別関数。 + int r = dict->search("red").toInt(); // 辞書 dict + int g = dict->search("green").toInt(); + int b = dict->search("blue").toInt(); + int32_t color = (int(r * 31 / 255) << 11) | (int(g * 63 / 255) << 5) | (int(b * 31 / 255)); + return color; } + +void setup() +{ + M5.begin(115200); // M5StickCPlusの初期化処理 + M5.Lcd.setRotation(3); // Aボタンが左側になる向きで画面を使用するよう設定 + M5.Lcd.fillScreen(CYAN); // 画面を塗りつぶす + M5.Lcd.setTextColor( BLUE, GREENYELLOW ); + M5.Lcd.setCursor(0, 0, 4); // 左から0,上から0ピクセルの位置にフォントサイズ3の文字を出力するよう設定 + + dict->insert("apple", 200); // 辞書に追加 + dict->insert("banana", 100); + dict->insert("cherry", 300); + + char keys[3][10] = {"banana", "cherry", "apple"}; + for (int k = 0; k < 3; k++) + { + Serial.printf("key %s => val %d\n", keys[k], dict->search(keys[k]).toInt()); + M5.Lcd.printf("key %s => val %d\n", keys[k], dict->search(keys[k]).toInt()); + } +} + +void loop() +{ + // do nothing + delay(100); +} \ No newline at end of file diff --git a/SampleSrc/rtc01.ino b/SampleSrc/rtc01.ino index fc1fead..d98f83c 100644 --- a/SampleSrc/rtc01.ino +++ b/SampleSrc/rtc01.ino @@ -10,7 +10,7 @@ DateStruct.Month = lt.tm_mon + 1; DateStruct.Date = lt.tm_mday; DateStruct.WeekDay = lt.tm_wday; - M5.Rtc.SetData(&DateStruct); + M5.Rtc.SetDate(&DateStruct); RTC_TimeTypeDef TimeStruct; TimeStruct.Hours = lt.tm_hour; @@ -22,7 +22,7 @@ void getRTC(char* buf) { RTC_DateTypeDef DateStruct; RTC_TimeTypeDef TimeStruct; - M5.Rtc.GetData(&DateStruct); + M5.Rtc.GetDate(&DateStruct); M5.Rtc.GetTime(&TimeStruct); sprintf(buf, "%04d/%02d/%02d %02d:%02d:%02d", DateStruct.Year, DateStruct.Month, DateStruct.Date, @@ -35,9 +35,9 @@ M5.Lcd.setRotation(3); if (USE_NTP) { - const char* ssid = "miura2g"; + const char* ssid = "ics-ap"; const char* password = "jikkenics"; - const char* ntpserver = "192.168.11.11"; // or ntp.nict.jp"; // or 10.64.7.184 for CIT-ap1x + const char* ntpserver = "ntp.nict.jp"; // or 10.64.7.184 for CIT-ap1x WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { // 接続中... Serial.print("."); diff --git a/SampleSrc/telnet01.ino b/SampleSrc/telnet01.ino index 558b8e4..585eb40 100644 --- a/SampleSrc/telnet01.ino +++ b/SampleSrc/telnet01.ino @@ -26,7 +26,7 @@ //how many clients should be able to telnet to this ESP32 #define MAX_SRV_CLIENTS 3 -const char* ssid = "miura2g"; +const char* ssid = "ics-ap"; const char* password = "jikkenics"; WiFiServer server(23); diff --git a/SampleSrc/wifi01.ino b/SampleSrc/wifi01.ino index 71b26f6..74776b6 100644 --- a/SampleSrc/wifi01.ino +++ b/SampleSrc/wifi01.ino @@ -1,7 +1,7 @@ #include #include -const char* ssid = "miura2g"; +const char* ssid = "ics-ap"; const char* password = "jikkenics"; void setup() { diff --git a/SampleSrc/wifi02.ino b/SampleSrc/wifi02.ino index f34f7b5..3b08bc9 100644 --- a/SampleSrc/wifi02.ino +++ b/SampleSrc/wifi02.ino @@ -4,7 +4,7 @@ #include WiFiMulti wifiMulti; -const char *ssid1 = "miura2g"; // 2.4GHzのみ。5GHzはNG +const char *ssid1 = "ics-ap"; // 2.4GHzのみ。5GHzはNG const char *password1 = "jikkenics"; const char *ssid2 = "your_wifi"; const char *password2 = "xxxxx"; diff --git a/SampleSrc/wifimac.ino b/SampleSrc/wifimac.ino index af5db73..9c0bc44 100644 --- a/SampleSrc/wifimac.ino +++ b/SampleSrc/wifimac.ino @@ -1,7 +1,7 @@ #include #include -const char *ssid = "miura2g"; +const char *ssid = "ics-ap"; const char *password = "jikkenics"; void setup()