Skip to content

Commit fca6312

Browse files
committed
Add Example
1 parent 57b9926 commit fca6312

File tree

10 files changed

+184
-65
lines changed

10 files changed

+184
-65
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
11
# stackchan-arduino
22
Stack Chan Library for ArduinoFramework
3+
4+
# 使い方
5+
6+
platformio.iniのlib_depsに下記の記述を追加してください。(そのうち公開します。)
7+
8+
```
9+
lib_deps =
10+
11+
arminjo/ServoEasing@^2.4.0
12+
madhephaestus/ESP32Servo @ 0.13.0
13+
bblanchon/ArduinoJson @ ^6
14+
tobozo/YAMLDuino
15+
https://github.com/mongonta0716/stackchan-arduino.git
16+
https://github.com/mongonta0716/SCServo
17+
lib_ldf_mode = deep ; これを忘れるとリンクエラーになります。
18+
```
19+
20+
# 設定ファイル
21+
- [SC_BasicConfig.yaml](./data/yaml/SC_BasicConfig.yaml)<br>スタックチャンを起動するために必要な基本的なパラメータを集めています。
22+
- [SC_SecConfig.yaml](./data/yaml/SC_SecConfig.yaml)<br>個人情報用の設定ファイルです。(WiFiやAPIKey等)
23+
- [SC_ExConfig.yaml](./data/yaml/SC_ExConfig.yaml)<br>アプリケーション側で、設定を追加したいときに使用します。使い方はexamples/Advanceを参照してください。
24+

data/yaml/SC_ExtConfig.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1-
# アプリケーションで利用する設定を書きます。
2-
role:
1+
# 各アプリケーションで利用する設定を書きます。
2+
# '#'を使うとコメントとして働きます。
3+
app_parameters1:
4+
item1: "アイテム1のデータ" # 文字列
5+
item2: 123456789 # 数値
6+
item3: True # True or False or 0 or 1
7+
8+
app_parameters2:
9+
item4: "リストのサンプル"
10+
list_str: # リストの書き方1
11+
- "文字列1"
12+
- "文字列2"
13+
- "文字列3"
14+
list_num: [ 1, -2, 3, -4] # リストの書き方2

data/yaml/SC_SecConfig.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# 個人情報用の設定ファイル
12
wifi:
23
ssid: "YOUR_WIFI_SSID"
34
password: "YOUR_WIFI_PASSWORD"

examples/Basic/platformio.ini

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[platformio]
2+
default_envs = m5stack-core2
3+
4+
[env]
5+
platform = espressif32 @ 6.5.0
6+
framework = arduino
7+
upload_speed = 1500000
8+
monitor_speed = 115200
9+
board_build.f_flash = 80000000L
10+
board_build.filesystem = spiffs
11+
board_build.partitions = default_16MB.csv
12+
build_flags = -DCORE_DEBUG_LEVEL=4
13+
lib_deps =
14+
15+
lib_deps =
16+
17+
arminjo/ServoEasing@^2.4.0
18+
madhephaestus/ESP32Servo @ 0.13.0
19+
bblanchon/ArduinoJson @ ^6
20+
tobozo/YAMLDuino
21+
https://github.com/mongonta0716/stackchan-arduino.git
22+
https://github.com/mongonta0716/SCServo
23+
lib_ldf_mode = deep ; これを忘れるとリンクエラーになります。
24+
25+
[env:m5stack-core2]
26+
board = m5stack-conre2
27+
28+
[env:m5stack-cores3]
29+
board = m5stack-cores3
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
#include "Stackchan_ex_config.h"
3+
4+
StackchanExConfig::StackchanExConfig() {};
5+
StackchanExConfig::~StackchanExConfig() {};
6+
7+
void StackchanConfig::loadExtendConfig(fs::FS& fs, const char *yaml_filename, uint32_t yaml_size) {
8+
M5_LOGI("----- StackchanExConfig::loadConfig:%s\n", yaml_filename);
9+
File file = fs.open(yaml_filename);
10+
if (file) {
11+
DynamicJsonDocument doc(yaml_size);
12+
auto err = deserializeYml( doc, file);
13+
if (err) {
14+
M5_LOGE("yaml file read error: %s\n", yaml_filename);
15+
M5_LOGE("error%s\n", err.c_str());
16+
}
17+
serializeJsonPretty(doc, Serial);
18+
setExtendSettings(doc);
19+
}
20+
}
21+
22+
void StackchanExConfig::setExtendSettings(DynamicJsonDocument doc) {
23+
JsonObject app_param1 = doc["app_parameters1"];
24+
_ex_parameters.item1 = app_param1["item1"].as<String>(); // 文字列はこのように記述
25+
_ex_parameters.item2 = app_param1["item2"] // 数値
26+
_ex_parameters.item3 = app_param1["item3"].as<bool>(); // True/False/0/1
27+
JsonObject app_param2 = doc["app_parameters2"];
28+
29+
JsonArray list_str = app_param2["list_str"];
30+
_list_str_count = list_str.size();
31+
for (int i=0; i<_list_str_count; i++) {
32+
_list_str[i] = list_str[i].as<String>();
33+
}
34+
JsonArray list_num = app_param2["list_num"];
35+
_list_num_count = list_num.size();
36+
for (int i=0; i<_list_num_count; i++) {
37+
_list_num[i] = list_num[i];
38+
}
39+
}
40+
41+
42+
void StackchanExConfig::printExtParameters(void) {
43+
M5_LOGI("item1:%s\n", _ex_parameters.item1.c_str());
44+
M5_LOGI("item2:%d\n", _ex_parameters.item2);
45+
M5_LOGI("item3:%s\n", _ex_parameters.item3 ? "true":"false");
46+
M5_LOGI("item4:%s\n", _item4);
47+
for (int i=0; i<_list_str_count; i++) {
48+
M5_LOGI("list_str[%d]: %s\n", i, _list_str[i]);
49+
}
50+
for (int i=0; i<_list_num_count; i++) {
51+
M5_LOGI("list_num[%d]: %d\n", i, _list_num[i]);
52+
}
53+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef __STACKCHAN_EX_CONFIG_H__
2+
#define __STACKCHAN_EX_CONFIG_H__
3+
4+
#include <Stackchan_system_config.h>
5+
6+
typedef struct ExConfig {
7+
String item1;
8+
int item2;
9+
bool item3;
10+
} ex_config_s;
11+
12+
13+
// StackchanSystemConfigを継承します。
14+
class StackchanExConfig : public StackchanSystemConfig
15+
{
16+
protected:
17+
ex_config_s _ex_parameters;
18+
String _item4;
19+
uint8_t _list_str_count;
20+
String _list_str[10];
21+
uint8_t _list_num_count;
22+
int _list_num[10];
23+
24+
public:
25+
StackchanExConfig();
26+
~StackchanExConfig();
27+
28+
void loadExtendConfig(fs::FS& fs, const char *yaml_filename, uint32_t yaml_size) override;
29+
void setExtendSettings(DynamicJsonDocument doc) override;
30+
void printExtParameters(void) override;
31+
ex_config_s getExConfig() { return _ex_parameters; }
32+
uint8_t getListStrCount() { return _list_str_count; }
33+
String getListStr(uint8_t no) { return _list_str[no]; }
34+
uint8_t getListNumCount() { return _list_num_count; }
35+
int getListNum(uint8_t no) { return _list_num[no]; }
36+
void setItem1(String item1) { _ex_parameters.item1 = item1; }
37+
void setItem2(int item2) { _ex_parameters.item2 = item2; }
38+
void setItem3(bool item3) { _ex_parameters.item3 = item3; }
39+
void setExConfig(ex_config_s config) { _ex_parameters = config; }
40+
};
41+
42+
#endif // __STACKCHAN_EX_CONFIG_H__

examples/Basic/src/main.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <Arduino.h>
2+
#include <M5Unified.h>
3+
#include <SD.h>
4+
#include "Stackchan_ex_config.h"
5+
6+
StackchanExConfig config;
7+
8+
void setup() {
9+
auto cfg = M5.config();
10+
M5.begin(cfg);
11+
M5.Log.setLogLevel(m5::log_target_display, ESP_LOG_INFO);
12+
M5.Log.setEnableColor(m5::log_target_serial, false);
13+
SD.begin(GPIO_NUM_4, SPI, 25000000);
14+
delay(2000);
15+
config.loadConfig(SD, "/yaml/SC_BasicConfig.yaml");
16+
17+
}
18+
19+
void loop() {
20+
// put your main code here, to run repeatedly:
21+
}
22+

src/AIStackchan_config.cpp

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/AIStackchan_config.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Stackchan_system_config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void StackchanSystemConfig::printAllParameters() {
191191
M5_LOGI("use takao_base:%s\n", _takao_base ? "true":"false");
192192
M5_LOGI("ServoTypeStr:%s\n", _servo_type_str.c_str());
193193
M5_LOGI("ServoType: %d\n", _servo_type);
194-
M5_LOGI("ExtendConfigFileName: %s\n", _extend_config_filename);
194+
M5_LOGI("ExtendConfigFileName: %s\n", _extend_config_filename.c_str());
195195
M5_LOGI("ExtendConfigFileSize: %d\n", _extend_config_filesize);
196196

197197
printExtParameters();

0 commit comments

Comments
 (0)