int
rd_SPIFFS(String fname, String &sname) {
File fp = SPIFFS.open(fname,
"r"
) ;
if
(!fp) {
Serial.print(fname) ;
Serial.println(
" : file open error"
) ;
return
-1 ;
}
else
{
sname = fp.readString() ;
fp.close() ;
}
return
0 ;
}
int
rd_mainconf() {
String s_work ;
File fp ;
int
result = 0 ;
if
(SPIFFS.exists(
"/mconf.txt"
)) {
result = rd_SPIFFS(
"/mconf.txt"
,s_work) ;
}
else
{
Serial.println(
"メイン設定ファイルなし"
) ;
result = -1 ;
}
if
(result == 0)
# ifdef DEBUG // デバッグ用表示
Serial.println(
"--- mconf.txt --- "
) ;
Serial.println(s_work ) ;
# endif //
set_conf2pwpkparam(s_work) ;
return
result ;
}
void
set_conf2pwpkparam(String &conf) {
int
pos = 0 ;
int
npos = 0 ;
String s_work ;
String s_name ;
String s_data ;
while
(1) {
if
(conf.charAt(pos) ==
'/'
) {
npos = conf.indexOf(
'\n'
,pos) ;
pos = npos + 1 ;
}
else
{
npos = conf.indexOf(
':'
,pos) ;
if
(npos == -1)
break
;
s_name = conf.substring(pos,npos) ;
s_name.trim() ;
pos = npos+1 ;
npos = conf.indexOf(
'\n'
,pos) ;
if
(npos == -1) npos = conf.length() ;
s_data = conf.substring(pos,npos) ;
s_data.trim() ;
pos = npos+1 ;
set_param(s_name,s_data) ;
}
}
}
void
set_param(String &name, String &data) {
if
(name.compareTo(
"prg_loop"
)==0) {
prg_tbl[0][0] = data.toInt() ;
}
if
(name.compareTo(
"prg_loopnum"
)==0) {
prg_tbl[0][1] = data.toInt() ;
}
if
(name.compareTo(
"prg_1_acc"
)==0) {
prg_tbl[1][2] = data.toInt() ;
}
if
(name.compareTo(
"prg_1_spd"
)==0) {
prg_tbl[1][3] = data.toInt() ;
}
if
(name.compareTo(
"prg_1_tim"
)==0) {
prg_tbl[1][4] = data.toInt() ;
}
if
(name.compareTo(
"prg_2_en"
)==0) {
prg_tbl[2][0] = data.toInt() ;
}
if
(name.compareTo(
"prg_2_trg"
)==0) {
prg_tbl[2][1] = data.toInt() ;
}
if
(name.compareTo(
"prg_2_acc"
)==0) {
prg_tbl[2][2] = data.toInt() ;
}
if
(name.compareTo(
"prg_2_spd"
)==0) {
prg_tbl[2][3] = data.toInt() ;
}
if
(name.compareTo(
"prg_2_tim"
)==0) {
prg_tbl[2][4] = data.toInt() ;
}
if
(name.compareTo(
"prg_3_en"
)==0) {
prg_tbl[3][0] = data.toInt() ;
}
if
(name.compareTo(
"prg_3_trg"
)==0) {
prg_tbl[3][1] = data.toInt() ;
}
if
(name.compareTo(
"prg_3_acc"
)==0) {
prg_tbl[3][2] = data.toInt() ;
}
if
(name.compareTo(
"prg_3_spd"
)==0) {
prg_tbl[3][3] = data.toInt() ;
}
if
(name.compareTo(
"prg_3_tim"
)==0) {
prg_tbl[3][4] = data.toInt() ;
}
if
(name.compareTo(
"prg_4_en"
)==0) {
prg_tbl[4][0] = data.toInt() ;
}
if
(name.compareTo(
"prg_4_trg"
)==0) {
prg_tbl[4][1] = data.toInt() ;
}
if
(name.compareTo(
"prg_4_acc"
)==0) {
prg_tbl[4][2] = data.toInt() ;
}
if
(name.compareTo(
"prg_4_spd"
)==0) {
prg_tbl[4][3] = data.toInt() ;
}
if
(name.compareTo(
"prg_4_tim"
)==0) {
prg_tbl[4][4] = data.toInt() ;
}
if
(name.compareTo(
"prg_5_en"
)==0) {
prg_tbl[5][0] = data.toInt() ;
}
if
(name.compareTo(
"prg_5_trg"
)==0) {
prg_tbl[5][1] = data.toInt() ;
}
if
(name.compareTo(
"prg_5_acc"
)==0) {
prg_tbl[5][2] = data.toInt() ;
}
if
(name.compareTo(
"prg_5_spd"
)==0) {
prg_tbl[5][3] = data.toInt() ;
}
if
(name.compareTo(
"prg_5_tim"
)==0) {
prg_tbl[5][4] = data.toInt() ;
}
}
void
start_STA_server() {
int
lpcnt = 0 ;
int
lpcnt2 = 0 ;
WiFi.config(wifi_ip, wifi_gw, wifi_sm, wifi_dns);
delay(10) ;
WiFi.begin(wifi_ssid, wifi_pass);
lpcnt = 0 ;
lpcnt2 = 0 ;
while
(WiFi.status() != WL_CONNECTED) {
lpcnt += 1 ;
if
(lpcnt > 4) {
WiFi.begin(wifi_ssid, wifi_pass);
lpcnt = 0 ;
lpcnt2 += 1 ;
}
if
(lpcnt2 > 5) {
stamode =
false
;
ESP.restart() ;
}
Serial.print(
"."
);
delay(500);
}
server.begin();
}
void
send_PWPK_html(WiFiClient client) {
String htmlwk ;
htmlwk = html_pwpk ;
htmlwk.replace(
"$pwr"
,String(duty)) ;
htmlwk.replace(
"$pwmin"
,String(base_val)) ;
# ifdef DEBUG_WiFi //
Serial.print(
"radio_local = "
);
Serial.println(local);
Serial.print(
"pwr = "
);
Serial.println(duty);
#endif //
if
(local) {
htmlwk.replace(
"$checked_lo"
,
"checked"
) ;
htmlwk.replace(
"$checked_rm"
,
""
) ;
}
else
{
htmlwk.replace(
"$checked_lo"
,
""
) ;
htmlwk.replace(
"$checked_rm"
,
"checked"
) ;
}
if
(dir_bkwd) {
htmlwk.replace(
"$checked_fw"
,
""
) ;
htmlwk.replace(
"$checked_bw"
,
"checked"
) ;
}
else
{
htmlwk.replace(
"$checked_fw"
,
"checked"
) ;
htmlwk.replace(
"$checked_bw"
,
""
) ;
}
send_html(client,htmlwk) ;
# ifdef DEBUG_HTML //
Serial.print(
"Send Main HTML | "
) ;
# endif //
}
void
send_pwpkRESP_html(WiFiClient client) {
String htmlwk ;
htmlwk = html_mRESP ;
htmlwk.replace(
"$pwr"
,String(duty)) ;
htmlwk.replace(
"$dir"
,String(dir_bkwd)) ;
htmlwk.replace(
"$local"
,String(local)) ;
send_html(client,htmlwk) ;
# ifdef DEBUG_HTML //
Serial.print(
"Send Main XHR Resp | "
) ;
# endif //
# ifdef DEBUG_WiFi //
Serial.println(
""
) ;
Serial.print(
" dir :"
) ;
Serial.print(dir_bkwd) ;
Serial.println(
"|"
) ;
Serial.println(
" response :"
) ;
Serial.print(htmlwk) ;
Serial.println(
""
) ;
#endif //
# ifdef DEBUG //
if
(local) {
Serial.print(
"local"
) ;
}
else
{
Serial.print(
"remot"
) ;
}
#endif //
}
void
send_pwpkCONF_html(WiFiClient client) {
String htmlwk ;
htmlwk = html_mCONF ;
if
(prg_tbl[0][0]) {
htmlwk.replace(
"$checked_loop"
,
"checked"
) ;
}
else
{
htmlwk.replace(
"$checked_loop"
,
""
) ;
}
htmlwk.replace(
"$loopnum"
,String(prg_tbl[0][1])) ;
htmlwk.replace(
"$acc1"
,String(prg_tbl[1][2])) ;
htmlwk.replace(
"$spd1"
,String(prg_tbl[1][3])) ;
htmlwk.replace(
"$tim1"
,String(prg_tbl[1][4])) ;
if
(prg_tbl[2][0]) {
htmlwk.replace(
"$en2"
,
"checked"
) ;
}
else
{
htmlwk.replace(
"$en2"
,
""
) ;
}
if
(prg_tbl[2][1] == 0) {
htmlwk.replace(
"$trg2_sel0"
,
"selected"
) ;
htmlwk.replace(
"$trg2_sel1"
,
""
) ;
}
else
if
(prg_tbl[2][1] == 1) {
htmlwk.replace(
"$trg2_sel0"
,
""
) ;
htmlwk.replace(
"$trg2_sel1"
,
"selected"
) ;
}
htmlwk.replace(
"$acc2"
,String(prg_tbl[2][2])) ;
htmlwk.replace(
"$spd2"
,String(prg_tbl[2][3])) ;
htmlwk.replace(
"$tim2"
,String(prg_tbl[2][4])) ;
if
(prg_tbl[3][0]) {
htmlwk.replace(
"$en3"
,
"checked"
) ;
}
else
{
htmlwk.replace(
"$en3"
,
""
) ;
}
if
(prg_tbl[3][1] == 0) {
htmlwk.replace(
"$trg3_sel0"
,
"selected"
) ;
htmlwk.replace(
"$trg3_sel1"
,
""
) ;
}
else
if
(prg_tbl[3][1] == 1) {
htmlwk.replace(
"$trg3_sel0"
,
""
) ;
htmlwk.replace(
"$trg3_sel1"
,
"selected"
) ;
}
htmlwk.replace(
"$acc3"
,String(prg_tbl[3][2])) ;
htmlwk.replace(
"$spd3"
,String(prg_tbl[3][3])) ;
htmlwk.replace(
"$tim3"
,String(prg_tbl[3][4])) ;
if
(prg_tbl[4][0]) {
htmlwk.replace(
"$en4"
,
"checked"
) ;
}
else
{
htmlwk.replace(
"$en4"
,
""
) ;
}
if
(prg_tbl[4][1] == 0) {
htmlwk.replace(
"$trg4_sel0"
,
"selected"
) ;
htmlwk.replace(
"$trg4_sel1"
,
""
) ;
}
else
if
(prg_tbl[4][1] == 1) {
htmlwk.replace(
"$trg4_sel0"
,
""
) ;
htmlwk.replace(
"$trg4_sel1"
,
"selected"
) ;
}
htmlwk.replace(
"$acc4"
,String(prg_tbl[4][2])) ;
htmlwk.replace(
"$spd4"
,String(prg_tbl[4][3])) ;
htmlwk.replace(
"$tim4"
,String(prg_tbl[4][4])) ;
if
(prg_tbl[5][0]) {
htmlwk.replace(
"$en5"
,
"checked"
) ;
}
else
{
htmlwk.replace(
"$en5"
,
""
) ;
}
if
(prg_tbl[5][1] == 0) {
htmlwk.replace(
"$trg5_sel0"
,
"selected"
) ;
htmlwk.replace(
"$trg5_sel1"
,
""
) ;
}
else
if
(prg_tbl[5][1] == 1) {
htmlwk.replace(
"$trg5_sel0"
,
""
) ;
htmlwk.replace(
"$trg5_sel1"
,
"selected"
) ;
}
htmlwk.replace(
"$acc5"
,String(prg_tbl[5][2])) ;
htmlwk.replace(
"$spd5"
,String(prg_tbl[5][3])) ;
htmlwk.replace(
"$tim5"
,String(prg_tbl[5][4])) ;
send_html(client,htmlwk) ;
# ifdef DEBUG_HTML //
Serial.print(
"Send Main Config HTML | "
) ;
# endif //
}
void
send_pwpkCONF_RESP(WiFiClient client) {
String htmlwk ;
String conf ;
htmlwk = html_wfRESP ;
if
(pwpk_confdl) {
getstr_pwpkconf(conf) ;
htmlwk.replace(
"$conf_text"
,conf) ;
pwpk_confdl =
false
;
}
else
{
htmlwk.replace(
"$conf_text"
,
""
) ;
}
send_html(client,htmlwk) ;
# ifdef DEBUG_HTML //
Serial.print(
"Send PWPK XHR Resp | "
) ;
# endif //
# ifdef DEBUG_WiFi //
Serial.println(
""
) ;
Serial.println(
" response :"
) ;
Serial.print(htmlwk) ;
Serial.println(
""
) ;
# endif //
}
void
send_html(WiFiClient client, String &html ) {
client.println(
"HTTP/1.1 200 OK"
);
client.println(
"Content-type:text/html"
);
client.println();
client.print(html) ;
}
int
proc_main(String &line) {
String s_work =
""
;
bool
workflg =
false
;
int
val ;
int
xhr = 0 ;
if
(line.indexOf(
"GET /?remote"
) != -1) {
s_work = getvalue_s(line,
"?remote="
) ;
if
(s_work==
"local"
) {
local =
true
;
}
else
{
local =
false
;
localen =
false
;
}
}
if
(line.indexOf(
"GET /?dir"
) != -1) {
s_work = getvalue_s(line,
"?dir="
) ;
if
(!local) {
if
(!running) {
workflg = dir_bkwd ;
if
(s_work==
"foward"
) {
dir_bkwd =
false
;
}
else
{
dir_bkwd =
true
;
}
if
(workflg != dir_bkwd) {
dir_change =
true
;
}
}
}
}
if
(line.indexOf(
"GET /?pwr_v"
) != -1) {
val = getvalue_i(line,
"?pwr_v="
) ;
if
(!local) {
if
(val>256) val = 255 ;
duty = val ;
}
}
if
(line.indexOf(
"GET /?slid"
) != -1) {
val = getvalue_i(line,
"?slid="
) ;
if
(!local) {
if
(val>256) val = 255 ;
duty = val ;
}
xhr = 1 ;
}
if
(line.indexOf(
"GET /?ready"
) != -1) {
if
(!local) {
if
(ready ==
false
) {
ready =
true
;
base_val = base ;
rdy_change =
true
;
if
(duty < base_val)
duty = base_val ;
}
else
{
ready =
false
;
base_val = 0 ;
rdy_change =
true
;
duty = base_val ;
}
}
}
if
(line.indexOf(
"GET /?start"
) != -1) {
if
(!local) {
start_sw =
true
;
}
xhr = 1 ;
}
if
(line.indexOf(
"GET /?pol"
) != -1) {
xhr = 1 ;
}
if
(line.indexOf(
"GET /?mconf"
) != -1) {
html_mode=MAIN_CONF;
}
if
(line.indexOf(
"GET /?config"
) != -1) {
html_mode=WIFI_CONF;
}
return
xhr ;
}
int
set_mconf2param(String &line) {
String s_work =
""
;
int
xhr = 0 ;
if
(line.indexOf(
"set="
) != -1) {
if
(line.indexOf(
"loop="
) != -1) {
prg_tbl[0][0] =
true
;
}
else
{
prg_tbl[0][0] =
false
;
}
if
(line.indexOf(
"loopnum="
) != -1) {
prg_tbl[0][1] = getvalue_i(line,
"loopnum="
) ;
}
if
(line.indexOf(
"acc1="
) != -1) {
prg_tbl[1][2] = getvalue_i(line,
"acc1="
) ;
}
if
(line.indexOf(
"spd1="
) != -1) {
prg_tbl[1][3] = getvalue_i(line,
"spd1="
) ;
}
if
(line.indexOf(
"tim1="
) != -1) {
prg_tbl[1][4] = getvalue_i(line,
"tim1="
) ;
}
if
(line.indexOf(
"chk2="
) != -1) {
prg_tbl[2][0] =
true
;
}
else
{
prg_tbl[2][0] =
false
;
}
if
(line.indexOf(
"trg2="
) != -1) {
prg_tbl[2][1] = getvalue_i(line,
"trg2="
) ;
}
if
(line.indexOf(
"acc2="
) != -1) {
prg_tbl[2][2] = getvalue_i(line,
"acc2="
) ;
}
if
(line.indexOf(
"spd2="
) != -1) {
prg_tbl[2][3] = getvalue_i(line,
"spd2="
) ;
}
if
(line.indexOf(
"tim2="
) != -1) {
prg_tbl[2][4] = getvalue_i(line,
"tim2="
) ;
}
if
(line.indexOf(
"chk3="
) != -1) {
prg_tbl[3][0] =
true
;
}
else
{
prg_tbl[3][0] =
false
;
}
if
(line.indexOf(
"trg3="
) != -1) {
prg_tbl[3][1] = getvalue_i(line,
"trg3="
) ;
}
if
(line.indexOf(
"acc3="
) != -1) {
prg_tbl[3][2] = getvalue_i(line,
"acc3="
) ;
}
if
(line.indexOf(
"spd3="
) != -1) {
prg_tbl[3][3] = getvalue_i(line,
"spd3="
) ;
}
if
(line.indexOf(
"tim3="
) != -1) {
prg_tbl[3][4] = getvalue_i(line,
"tim3="
) ;
}
if
(line.indexOf(
"chk4="
) != -1) {
prg_tbl[4][0] =
true
;
}
else
{
prg_tbl[4][0] =
false
;
}
if
(line.indexOf(
"trg4="
) != -1) {
prg_tbl[4][1] = getvalue_i(line,
"trg4="
) ;
}
if
(line.indexOf(
"acc4="
) != -1) {
prg_tbl[4][2] = getvalue_i(line,
"acc4="
) ;
}
if
(line.indexOf(
"spd4="
) != -1) {
prg_tbl[4][3] = getvalue_i(line,
"spd4="
) ;
}
if
(line.indexOf(
"tim4="
) != -1) {
prg_tbl[4][4] = getvalue_i(line,
"tim4="
) ;
}
if
(line.indexOf(
"chk5="
) != -1) {
prg_tbl[5][0] =
true
;
}
else
{
prg_tbl[5][0] =
false
;
}
if
(line.indexOf(
"trg5="
) != -1) {
prg_tbl[5][1] = getvalue_i(line,
"trg5="
) ;
}
if
(line.indexOf(
"acc5="
) != -1) {
prg_tbl[5][2] = getvalue_i(line,
"acc5="
) ;
}
if
(line.indexOf(
"spd5="
) != -1) {
prg_tbl[5][3] = getvalue_i(line,
"spd5="
) ;
}
if
(line.indexOf(
"tim5="
) != -1) {
prg_tbl[5][4] = getvalue_i(line,
"tim5="
) ;
}
if
(line.indexOf(
"save="
) != -1) {
Serial.println(
"write main config "
) ;
wr_pwpkconf() ;
}
Serial.println(
"set html_mode MAIN"
) ;
html_mode = MAIN ;
}
if
(line.indexOf(
"rtn="
) != -1) {
Serial.println(
"retuen MAIN mode"
) ;
html_mode = MAIN ;
}
if
(line.indexOf(
"mcnfld="
) != -1) {
pwpk_confdl =
true
;
xhr = 1 ;
}
return
(xhr) ;
}
void
getstr_pwpkconf(String &conf) {
char
s_work[1024] ;
File fp ;
sprintf
(s_work,
"prg_loop : %d\n"
,prg_tbl[0][0] ) ;
conf = String(s_work) ;
sprintf
(s_work,
"prg_loopnum : %d\n"
,prg_tbl[0][1] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_1_acc : %d\n"
,prg_tbl[1][2] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_1_spd : %d\n"
,prg_tbl[1][3] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_1_tim : %d\n"
,prg_tbl[1][4] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_2_en : %d\n"
,prg_tbl[2][0] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_2_trg : %d\n"
,prg_tbl[2][1] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_2_acc : %d\n"
,prg_tbl[2][2] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_2_spd : %d\n"
,prg_tbl[2][3] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_2_tim : %d\n"
,prg_tbl[2][4] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_3_en : %d\n"
,prg_tbl[3][0] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_3_trg : %d\n"
,prg_tbl[3][1] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_3_acc : %d\n"
,prg_tbl[3][2] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_3_spd : %d\n"
,prg_tbl[3][3] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_3_tim : %d\n"
,prg_tbl[3][4] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_4_en : %d\n"
,prg_tbl[4][0] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_4_trg : %d\n"
,prg_tbl[4][1] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_4_acc : %d\n"
,prg_tbl[4][2] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_4_spd : %d\n"
,prg_tbl[4][3] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_4_tim : %d\n"
,prg_tbl[4][4] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_5_en : %d\n"
,prg_tbl[5][0] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_5_trg : %d\n"
,prg_tbl[5][1] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_5_acc : %d\n"
,prg_tbl[5][2] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_5_spd : %d\n"
,prg_tbl[5][3] ) ;
conf += String(s_work) ;
sprintf
(s_work,
"prg_5_tim : %d\n"
,prg_tbl[5][4] ) ;
conf += String(s_work) ;
}
void
wr_pwpkconf() {
char
s_work[1024] ;
String conf ;
File fp ;
getstr_pwpkconf(conf) ;
fp = SPIFFS.open(
"/mconf.txt"
,FILE_WRITE) ;
if
(!fp) {
Serial.println(
" 設定ファイル オープンエラー !!"
) ;
}
else
{
Serial.println(
"/mconf.txt open complete "
) ;
if
(fp.print(conf)) {
Serial.println(
"m_config written"
) ;
}
else
{
Serial.println(
"m_config write error !!"
) ;
}
fp.close() ;
}
}
void
execTicker() {
ticker_val =
true
;
}
void
do_JOB() {
bool
workflg =
false
;
int
work = 0 ;
if
(local ==
true
) {
if
(!digitalRead(MNT_MODE)) {
if
(!digitalRead(SW_READY)) {
if
(pre_rdy ==
false
) {
if
(stamode ==
false
) {
start_AP_server() ;
sta_exec =
false
;
}
else
{
start_STA_server() ;
sta_exec =
true
;
}
}
pre_rdy =
true
;
}
else
{
pre_rdy =
false
;
}
}
else
{
vol_value = analogRead(PWR_VOL);
if
(localen ==
true
) {
if
(!running) {
workflg = dir_bkwd ;
if
(!digitalRead(SW_FWD)) {
dir_bkwd = 0 ;
}
if
(!digitalRead(SW_BWD)) {
dir_bkwd = 1 ;
}
if
(workflg != dir_bkwd) {
dir_change =
true
;
}
}
if
(!digitalRead(SW_READY)) {
if
(pre_rdy ==
false
) {
if
(ready ==
false
) {
ready =
true
;
base_val = base ;
rdy_change =
true
;
}
else
{
ready =
false
;
base_val = 0 ;
rdy_change =
true
;
}
}
pre_rdy =
true
;
}
else
{
pre_rdy =
false
;
}
if
(!digitalRead(SW_START)) {
if
(pre_strt ==
false
) {
start_sw =
true
;
}
pre_strt =
true
;
}
else
{
pre_strt =
false
;
}
if
(prg_run ==
false
)
duty = ((vol_value*(255-base_val))/4095)+base_val ;
}
else
{
duty = base_val ;
if
(vol_value == 0)
localen =
true
;
}
}
}
else
{
if
(!digitalRead(SW_READY)) {
if
(pre_rdy ==
false
) {
local =
true
;
localen =
false
;
}
pre_rdy =
true
;
}
else
{
pre_rdy =
false
;
}
}
if
(start_sw ==
true
) {
if
(prg_run ==
false
) {
prg_start =
true
;
}
else
{
if
(wait_sw) {
prg_next =
true
;
st_on =
true
;
}
else
{
start =
false
;
stop =
true
;
}
}
start_sw =
false
;
}
if
(prg_start ==
true
) {
prg_no = 1 ;
rate = prg_tbl[1][2] ;
target = prg_tbl[1][3] ;
prg_tim = prg_tbl[1][4] ;
prg_loopnum = prg_tbl[0][1] ;
if
(target < base_val)
target = base_val ;
start =
true
;
stop =
false
;
wait_sw =
false
;
st_on =
true
;
st_val = prg_no ;
prg_start =
false
;
prg_run =
true
;
Serial.print(
"prg_no :"
) ;
Serial.print(prg_no) ;
start_time = millis();
}
if
(prg_run ==
true
) {
now_time = millis() ;
if
(prg_tim <=
((now_time - start_time)/100) ) {
time_ovr =
true
;
}
if
(!wait_sw & time_ovr) {
nextno = prg_no + 1 ;
while
(nextno != prg_no) {
if
(nextno > 5) {
if
( (prg_tbl[0][0] == 1)
&& (prg_loopnum > 1)) {
nextno = 1 ;
prg_loopnum = prg_loopnum -1 ;
Serial.print(
"loopnum:"
) ;
Serial.println(prg_loopnum) ;
}
else
{
nextno = prg_no ;
now_time = millis() ;
now_time = now_time - start_time ;
stop =
true
;
break
;
}
}
if
(prg_tbl[nextno][0] == 0) {
nextno = nextno + 1 ;
}
else
{
prg_no = nextno ;
if
(prg_tbl[prg_no][1] == 0)
prg_next =
true
;
else
{
wait_sw =
true
;
st_blink =
true
;
st_bl_intvl = 5 ;
}
break
;
}
}
time_ovr =
false
;
}
if
(prg_next ==
true
) {
rate = prg_tbl[prg_no][2] ;
target = prg_tbl[prg_no][3] ;
prg_tim = prg_tbl[prg_no][4] ;
if
(target < base_val)
target = base_val ;
start =
true
;
stop =
false
;
wait_sw =
false
;
st_on =
true
;
st_val = prg_no ;
now_time = millis() ;
now_time = now_time - start_time ;
Serial.print(
" | time : "
) ;
Serial.println(now_time) ;
Serial.print(
"prg_no :"
) ;
Serial.print(prg_no) ;
start_time = millis();
prg_next =
false
;
}
if
(start ==
true
) {
autorun =
true
;
if
(duty < target) {
if
(duty < base)
duty = base ;
if
((target - duty) < rate)
duty = target ;
else
duty = duty + rate ;
}
else
if
(duty > target){
if
((duty - target) < rate)
duty = target ;
else
duty = duty - rate ;
}
else
{
now_time = millis() ;
now_time = now_time - start_time ;
Serial.print(
" duty:"
) ;
Serial.print(duty) ;
Serial.print(
" | time : "
);
Serial.print(now_time) ;
Serial.print(
" | "
) ;
start =
false
;
}
}
if
(stop ==
true
) {
autorun =
true
;
if
(duty > base_val){
if
((duty - base_val) < rate)
duty = base_val ;
else
duty = duty - rate ;
}
else
{
stop =
false
;
autorun =
false
;
prg_run =
false
;
if
(ready ==
true
) {
st_blink =
true
;
st_val = 7 ;
st_bl_intvl = 5 ;
}
else
{
st_on =
true
;
st_val = 0 ;
}
}
}
}
else
{
if
(rdy_change) {
if
(ready) {
st_blink =
true
;
st_val = 4 ;
st_bl_intvl = 5 ;
}
else
{
st_on =
true
;
st_val = 0 ;
}
rdy_change =
false
;
}
}
if
(duty > base_val)
running =
true
;
else
running =
false
;
if
(dir_change) {
ledcWrite(0, 0) ;
delay(10);
digitalWrite(LED_FWD,!dir_bkwd) ;
digitalWrite(LED_BWD,dir_bkwd) ;
digitalWrite(DIR_OUT,dir_bkwd) ;
delay(10);
ledcWrite(0, duty) ;
dir_change =
false
;
}
if
(st_on ==
true
) {
digitalWrite(LED_ST3, (st_val & 0x01) != 0) ;
digitalWrite(LED_ST2, (st_val & 0x02) != 0) ;
digitalWrite(LED_ST1, (st_val & 0x04) != 0) ;
st_on =
false
;
st_blink =
false
;
}
if
(st_blink ==
true
) {
if
(st_bl_off ==
true
) {
if
(st_bl_cnt == 0) {
st_bl_cnt = st_bl_intvl ;
st_bl_off =
false
;
digitalWrite(LED_ST3, (st_val & 0x01) != 0) ;
digitalWrite(LED_ST2, (st_val & 0x02) != 0) ;
digitalWrite(LED_ST1, (st_val & 0x04) != 0) ;
}
else
{
st_bl_cnt = st_bl_cnt -1 ;
}
}
else
{
if
(st_bl_cnt == 0) {
st_bl_cnt = st_bl_intvl ;
st_bl_off =
true
;
digitalWrite(LED_ST3, 0) ;
digitalWrite(LED_ST2, 0) ;
digitalWrite(LED_ST1, 0) ;
}
else
{
st_bl_cnt = st_bl_cnt -1 ;
}
}
}
ledcWrite(0, duty) ;
loopcnt++ ;
if
(loopcnt ==10) {
# ifdef DEBUG_Hard // デバッグ用出力
Serial.println(
""
) ;
Serial.print(
"PWR_VOL :"
) ; Serial.println(vol_value) ;
Serial.print(
"duty :"
) ; Serial.println(duty) ;
Serial.print(
"running :"
) ; Serial.println(running) ;
Serial.print(
"autorun :"
) ; Serial.println(autorun) ;
Serial.print(
"stop :"
) ; Serial.println(stop ) ;
Serial.print(
"ready :"
) ; Serial.println(ready) ;
Serial.print(
"start :"
) ; Serial.println(start) ;
Serial.print(
"prg_start:"
) ; Serial.println(prg_start) ;
Serial.print(
"prg_next :"
) ; Serial.println(prg_next ) ;
Serial.print(
"prg_run :"
) ; Serial.println(prg_run ) ;
Serial.print(
"prg_tim :"
) ; Serial.println(prg_tim ) ;
#endif //
loopcnt = 0;
}
ticker_val =
false
;
}