Skip to content

Commit 960f08c

Browse files
authored
Merge pull request #17 from Nefry-Community/develop
Develop
2 parents 9456853 + f632942 commit 960f08c

16 files changed

+462
-168
lines changed

cores/esp32/main.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,34 @@
1616
void loopTask(void *pvParameters)
1717
{
1818
Nefry.nefry_init();
19-
if (Nefry.getBootFlg() != true) {
19+
if (Nefry.getWriteMode() != true) {
2020
setup();
2121
}
2222
NefryWebServer.begin();
2323
for(;;) {
2424
micros(); //update overflow
25-
if (Nefry.getBootFlg() != true) {
25+
if (Nefry.getWriteMode() != true) {
2626
loop();
2727
}
2828
Nefry.nefry_loop();
2929
}
3030
}
3131

32-
void Nefryserver(void *pvParameters) {
32+
void NefryBackEnd(void *pvParameters) {
3333
TickType_t xLastWakeTime;
3434
xLastWakeTime = xTaskGetTickCount();
3535
for (;;) {
3636
vTaskDelayUntil(&xLastWakeTime,100/portTICK_PERIOD_MS);
3737
NefryWebServer.run();
38-
}
39-
}
40-
void NefrySWpolling(void *pvParameters) {
41-
TickType_t xLastWakeTime;
42-
xLastWakeTime = xTaskGetTickCount();
43-
Nefry.enableSW();
44-
for (;;) {
45-
vTaskDelayUntil(&xLastWakeTime, 100 / portTICK_PERIOD_MS);
4638
Nefry.pollingSW();
4739
}
4840
}
41+
4942
extern "C" void app_main()
5043
{
5144
initArduino();
52-
xTaskCreatePinnedToCore(loopTask, "loopTask", 4096, NULL, 2, NULL, ARDUINO_RUNNING_CORE);
53-
xTaskCreatePinnedToCore(&Nefryserver, "NefryWeb", 4096, NULL, 1, NULL, ARDUINO_RUNNING_CORE);
54-
xTaskCreatePinnedToCore(&NefrySWpolling, "SWpolling", 4096, NULL, 3, NULL, ARDUINO_RUNNING_CORE);
45+
xTaskCreatePinnedToCore(loopTask, "loopTask", 4096, NULL, 2, NULL, 1);
46+
xTaskCreatePinnedToCore(&NefryBackEnd, "NefryBackEnd", 9192, NULL, 1, NULL,0);
5547
}
5648

5749
#endif

cores/esp32/nefry/Nefry.cpp

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,21 @@ BootMode
2424
1 : WriteMode切替をする
2525
*/
2626

27-
#define LIBVERSION ("0.5.4")
27+
#define LIBVERSION ("0.6.0")
2828
#include "Nefry.h"
2929

3030
Adafruit_NeoPixel _NefryLED[40];
31-
const char * program;
32-
bool _bootMode = true, _swflg = false,_bootflg = false;
31+
3332
//main
3433

3534
void Nefry_lib::nefry_init() {
3635
beginLed(1, 16, NEO_GRB);
36+
enableSW();
3737
setLed(0x00, 0x0f, 0x00);
3838
Serial.begin(115200);
3939
Serial.println(F("\n\nStartup"));
4040
Serial.println(F("\n\nNefry Startup"));
4141
NefryDataStore.begin();
42-
//enableSW();
4342
setLed(0x00, 0x2f, 0x00);
4443
/* Display設定 */
4544
setLed(0x00, 0x4f, 0x00);
@@ -53,25 +52,25 @@ void Nefry_lib::nefry_init() {
5352
/* IPaddress display表示 */
5453
setLed(0x00, 0xcf, 0x00);
5554
setLed(0x00, 0xef, 0x00);
56-
if (NefryDataStore.getBootSelector() == 1) {
57-
//for (int i = 0; i < 20; i++)
58-
//setConfHtmlPrint(1, i);
59-
//println(F("Nefry Write mode"));
55+
if (NefryDataStore.getBootSelector() == 1 || readSW()) {
6056
setLed(0x0f, 0xff, 0xff);
6157
NefryDataStore.setBootSelector(0);
62-
_bootflg = true;
63-
//cssAdd("writemode", F("Write Mode"));
58+
_bootMode = 2;
59+
Serial.println("Write Mode");
60+
} else {
61+
_bootMode = 1;
6462
}
65-
_bootMode = false;
63+
disableSW();
64+
NefryConfig.begin();
6665
Serial.println(F("\nServer started"));
6766
setLed(0x00, 0xff, 0xff);
67+
6868
}
6969

7070
void Nefry_lib::nefry_loop() {
7171
//_dnsServer.processNextRequest();
7272
NefryWiFi.run();
7373

74-
//NefryWebServer.run();
7574
}
7675

7776
/* ModuleID */
@@ -207,25 +206,33 @@ void Nefry_lib::disableSW() {
207206

208207
/* SW の状態を取得します */
209208
bool Nefry_lib::readSW() {
210-
if (_swflg == true) {
211-
_swflg = false;
212-
return true;
209+
if (_swEnableFlg == true) {
210+
if (_swflg == true) {
211+
_swflg = false;
212+
return true;
213+
}
214+
return false;
215+
}
216+
else {
217+
return digitalRead(4);
213218
}
214219
return false;
215220
}
216221

217222
/* SWを押されたときに割り込まれます */
218223
void Nefry_lib::pollingSW() {
219224
if (_swEnableFlg == true && _swflg != true && digitalRead(4) == LOW) {
220-
if (_bootMode == true) {
225+
if (_bootMode == 0) {
221226
Nefry.setLed(0xff, 0x2f, 0x00);
222-
NefryDataStore.setBootSelector(1);
223-
Serial.println("push SW");
224227
}
225228
Serial.println("push SW");
226229
_swflg = true;
227230
}
228231
}
232+
bool Nefry_lib::getPollingSW()
233+
{
234+
return _swEnableFlg;
235+
}
229236

230237
//LED
231238
void Nefry_lib::beginLed(const int num, const int pin, uint8_t t = NEO_GRB) {
@@ -259,7 +266,36 @@ int Nefry_lib::hextonum(char c)
259266
return n;
260267
}
261268

262-
bool Nefry_lib::getBootFlg() {
263-
return _bootflg;
269+
bool Nefry_lib::getWriteMode() {
270+
if (_bootMode == 2)return true;
271+
return false;
264272
}
273+
274+
void Nefry_lib::setStoreTitle(const char set[15], const int num)
275+
{
276+
NefryConfig.setStoreTitle(set, num);
277+
return ;
278+
}
279+
280+
/*
281+
String Nefry_Conf::setDefaultModuleId() {
282+
uint8_t macAddr[WL_MAC_ADDR_LENGTH];
283+
String moduleName;
284+
WiFi.macAddress(macAddr);
285+
switch (boardId)
286+
{
287+
case 1:
288+
moduleName = "Nefry";
289+
break;
290+
case 2:
291+
moduleName = "CocoaBit";
292+
break;
293+
}
294+
moduleName += "-";
295+
moduleName += macAddr[WL_MAC_ADDR_LENGTH - 2];
296+
moduleName += macAddr[WL_MAC_ADDR_LENGTH - 1];
297+
return moduleName
298+
}
299+
*/
300+
265301
Nefry_lib Nefry;

cores/esp32/nefry/Nefry.h

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifndef Nefry_h
1+
#ifndef Nefry_h
22
#define Nefry_h
33

44
#include <Esp.h>
@@ -7,6 +7,7 @@
77
//#include "NefryWebServer.h"
88
#include "NefryWiFi.h"
99
#include "./NefryDataStore.h"
10+
#include "NefryConfig.h"
1011

1112
// Offset: W R G B
1213
#define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2))
@@ -28,13 +29,19 @@ class Nefry_lib
2829
setUser(String user),
2930
setUserPass(String pass),
3031
setStorageValue(long value, int pointer),
31-
setStorageStr(String str, int pointer);
32+
setStorageStr(String str, int pointer),
33+
getWriteMode(),
34+
readSW(),
35+
getPollingSW();
3236

3337
String
3438
getModuleID(),
3539
getModuleClass(),
3640
getUser(),
37-
getStorageStr(int pointer);
41+
getStorageStr(int pointer),
42+
getVersion(),
43+
getProgramName(),
44+
getAddressStr(IPAddress ip);
3845

3946
long
4047
getStorageValue(int pointer);
@@ -50,54 +57,28 @@ class Nefry_lib
5057
addWiFi(String ssid,String pass),
5158
deleteWiFi(int id),
5259
saveWiFi(),
53-
/*
54-
println(float text),
55-
println(double text),
56-
println(char text),
57-
println(int text),
58-
println(long text),
59-
println(unsigned char text),
60-
println(unsigned int text),
61-
println(unsigned long text),
62-
print(float text),
63-
print(double text),
64-
print(char text),
65-
print(int text),
66-
print(long text),
67-
print(unsigned char text),
68-
print(unsigned int text),
69-
print(unsigned long text),
70-
print(String text, int ln = 0),
71-
println(String text),
72-
*/
7360
nefry_init(),
7461
nefry_loop(),
75-
ndelay(unsigned long ms);
62+
ndelay(unsigned long ms),
7663

77-
void enableSW();
64+
setStoreTitle(const char set[15], const int num),
7865

79-
void disableSW();
80-
81-
bool
82-
readSW();
83-
84-
void pollingSW();
85-
bool getBootFlg();
86-
87-
88-
String
89-
getVersion(),
90-
getProgramName(),
91-
getAddressStr(IPAddress ip);
66+
enableSW(),
67+
disableSW(),
9268

69+
/* Pollingでスイッチの状態をチェック */
70+
pollingSW();
9371

9472
private:
95-
bool _swEnableFlg;
96-
bool _bootMode = true, _swflg = false;
97-
int hextonum(char c);
73+
bool
74+
_swEnableFlg = false,/* SWの有効無効化 */
75+
_swflg = false; /* SWの状態を保持 */
76+
77+
int
78+
_bootMode = 0, /* Boot状態を管理 0:起動中 1:通常起動 2:書き込みモード */
79+
hextonum(char c);
9880

81+
const char * program;
9982
};
10083
extern Nefry_lib Nefry;
101-
#endif
102-
103-
void _swcallback_function();
84+
#endif

cores/esp32/nefry/NefryConfig.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
Nefry Config
3+
4+
Copyright (c) 2016 wami
5+
6+
This software is released under the MIT License.
7+
http://opensource.org/licenses/mit-license.php
8+
*/
9+
10+
/*
11+
ModuleID : Nefryモジュール名 & Nefryが発信するSSID
12+
ModulePass : Nefryが発信するWiFiパスワード
13+
ModuleClass : Nefryのモジュールが属するクラス
14+
user : Nefryでログイン機能を使うときに使用するユーザ名
15+
userPass : Nefryでログイン機能を使うときに使用するパスワード
16+
StorageValue: Nefryの環境変数を保存するときに使用する。(0-7)の範囲で保存する。末端に数字が追加される long型
17+
StorageStr : Nefryの環境変数を保存するときに使用する。(0-7)の範囲で保存する。末端に数字が追加される String型
18+
*/
19+
20+
#include "NefryConfig.h"
21+
22+
23+
24+
String Nefry_Conf::beginWeb(String link) {
25+
26+
if (link.equals("config")) {
27+
String content = F("<h1>Nefry DataStore Setup</h1><p>このページはプログラム内から読み書きした値を表示、編集することができます。</p>"
28+
"<p>わざわざプログラムを書き換えずに値を変更できるためWebサービスでアクセスキーが必要になる場合など環境変数として扱うことができます。</p>"
29+
"<ul><li>setStorageValue or setStorageStr : 値の保存</li><li>getStorageValue or getStorageStr : 値の取得</li><li>setStoreTitle : 内容の表示</li></ul>"
30+
"<p>それぞれの関数の使い方はNefry公式サイトをご覧になるか、サンプルプログラムを参考にしてください。</p><form method='get'action='set_config'>");
31+
int formNumber,printCounter = 0;
32+
for (formNumber = 0; formNumber < 10; formNumber++) {
33+
if (htmlPrint[formNumber] == 1) {
34+
content += F("<div class=\"row\"><label>");
35+
content += module_input[formNumber];
36+
content += F("</label><div><input name=\"smo");
37+
content += formNumber;
38+
content += F("\"maxlength=\"128\"value=\"");
39+
content += NefryDataStore.getStorageStr(formNumber);
40+
content += F("\"></div></div>");
41+
printCounter++;
42+
}
43+
}
44+
for (formNumber = 10; formNumber < 20; formNumber++) {
45+
if (htmlPrint[formNumber] == 1) {
46+
content += F("<div class=\"row\"><label>");
47+
content += module_input[formNumber];
48+
content += F("</label><div><input name=\"imo");
49+
content += formNumber - 10;
50+
content += F("\"type=\"number\"value=\"");
51+
content += NefryDataStore.getStorageValue(formNumber - 10);
52+
content += F("\"></div></div>");
53+
printCounter++;
54+
}
55+
}
56+
delay(1);
57+
if(printCounter == 0){
58+
content += F("<p>表示するものがひとつもありません。setStoreTitle関数を使って表示をするか、WriteModeにしてください。</p>");
59+
60+
}
61+
else {
62+
content += F("<div class=\"row\"><div><input type=\"button\"value=\"Save\"onclick=\"return jsSubmit(this.form);\"></div></form></div>");
63+
}
64+
content += F("<div class=\"writemode\">");
65+
if (Nefry.getWriteMode())content += "WriteMode";
66+
content += F("</div><a href=\"/\">Back to top</a>");
67+
return NefryWeb.createHtml(F("Nefry DataStore"), "", content);
68+
}
69+
return "";
70+
}
71+
/* HTMLに表示するのか */
72+
void Nefry_Conf::setStoreTitle(const char set[15], const int num) {
73+
if (0 <= num&&num < 20) {
74+
strcpy(module_input[num], set);
75+
htmlPrint[num] = 1;
76+
}
77+
78+
}
79+
80+
void Nefry_Conf::begin()
81+
{
82+
for (int i = 0; i < 10; i++) {
83+
sprintf(module_input[i], "String %d", i);
84+
sprintf(module_input[10+i], "Value %d", 10+i);
85+
if (Nefry.getWriteMode()) {
86+
htmlPrint[i] = 1;
87+
htmlPrint[10+i] = 1;
88+
}
89+
else {
90+
htmlPrint[i] = 0;
91+
htmlPrint[10 + i] = 0;
92+
}
93+
}
94+
}
95+
Nefry_Conf NefryConfig;

0 commit comments

Comments
 (0)