initial commit
This commit is contained in:
271
Arduino_PLC/VarClass.cpp
Normal file
271
Arduino_PLC/VarClass.cpp
Normal file
@@ -0,0 +1,271 @@
|
||||
#include "VarClass.h"
|
||||
#include "motor.h"
|
||||
#include "IO.h"
|
||||
#include "HmiClass.h"
|
||||
|
||||
|
||||
void VarClass::Setup()
|
||||
{
|
||||
hmi.SendMessage("##:VAR:SETUP", false);
|
||||
|
||||
for(int i = 0 ; i < 4;i++)
|
||||
{
|
||||
ANData[i] = 0;
|
||||
AOData[i] = 0;
|
||||
}
|
||||
}
|
||||
void VarClass::Update()
|
||||
{
|
||||
/*
|
||||
if (var.getFlag(FLAG_CHARGEONM) == true)
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><CCB6> <20>ڵ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>¸<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>
|
||||
if (var.getFlag(FLAG_AUTORUN) == true)
|
||||
var.setFlag(FLAG_AUTORUN, false, "Manual Charge Mode");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/* <20>ܺθ<DCBA><CEB8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>. HMI<4D><49> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>̳<EFBFBD> RS232<33><32> REMOTE <20><>ɿ<EFBFBD> <20><><EFBFBD><EFBFBD> */
|
||||
void VarClass::runCommand(eCommand cmd, uint8_t p1, uint8_t p2)
|
||||
{
|
||||
/*String msg = ("RunCommand ");
|
||||
msg += String(cmd);
|
||||
msg += (":");
|
||||
msg += String(p1);
|
||||
msg += (":");
|
||||
msg += String(p2);
|
||||
hmi.SendMessage(msg, false);*/
|
||||
|
||||
//display data
|
||||
var.pingtime = millis();
|
||||
bool newValue = false;
|
||||
|
||||
if (cmd == LOAD)
|
||||
{
|
||||
var.eeprom_load();
|
||||
}
|
||||
else if (cmd == SAVE)
|
||||
{
|
||||
var.eeprom_save();
|
||||
}
|
||||
else if (cmd == RESET)
|
||||
{
|
||||
var.runReset = true;
|
||||
}
|
||||
else if (cmd == SET_PINMODE)
|
||||
{
|
||||
pinMode(p1, p2); //<2F>ش<EFBFBD><D8B4><EFBFBD><EFBFBD><EFBFBD> IO<49><4F>带 <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>
|
||||
}
|
||||
else if (cmd == SET_DOUTPUT)
|
||||
{
|
||||
String msg = ("Remote:Output:");
|
||||
msg += String(p1);
|
||||
msg += ',';
|
||||
msg += String(p2);
|
||||
hmi.SendMessage(msg, false);
|
||||
digitalWrite(p1, p2);
|
||||
}
|
||||
else if (cmd == SET_AOUTPUT)
|
||||
{
|
||||
if (p1 == 11) var.AOData[0] = p2;
|
||||
else if (p1 == 12) var.AOData[1] = p2;
|
||||
|
||||
analogWrite(p1, p2);
|
||||
|
||||
String msg = ("Set PWM Out:");
|
||||
msg += String(p1);
|
||||
msg += ',';
|
||||
msg += String(p2);
|
||||
hmi.SendMessage(msg, false);
|
||||
}
|
||||
else if (cmd == SET_FLAG)
|
||||
{
|
||||
String msg = ("@FLAG|");
|
||||
msg += String(p1);
|
||||
msg += ',';
|
||||
msg += String(p2);
|
||||
hmi.SendMessage(msg, false);
|
||||
|
||||
if (p2 == 1) var.setFlag(p1, true, "Remote");
|
||||
else var.setFlag(p1, false, "Remote");
|
||||
|
||||
if (p2 == 1 && p1 == FLAG_SETUP)
|
||||
{
|
||||
hmi.SendMessage("Entering Setup Mode", false);
|
||||
}
|
||||
}
|
||||
else if (cmd == SET_EEPROM)
|
||||
{
|
||||
if (p1 == EEP_IOINTERVAL) {
|
||||
var._eep_iosendinterval = p2;
|
||||
hmi.SendMessage("(EEP) I/O Interval = " + String(p2), false);
|
||||
}
|
||||
else if (p1 == EEP_RESETCOUNT) {
|
||||
hmi.SendMessage("(EEP) EEP_RESETCOUNT = " + String(p2), false);
|
||||
}
|
||||
else hmi.SendMessage("Set_ErrpRom p1 error", false);
|
||||
//var.eeprom_save();
|
||||
}
|
||||
else if (cmd == GET_SETTING)
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>
|
||||
//<2F>̰DZ<CCB0><C7B1><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
|
||||
}
|
||||
|
||||
else if (cmd == GUIDE_MOT)
|
||||
{
|
||||
if (p1 == 'L') //left
|
||||
{
|
||||
if (p2 == 'P')
|
||||
{
|
||||
mot.SetZDir(ZDIR_CW);
|
||||
mot.SetZRunL(true);
|
||||
}
|
||||
else if (p2 == 'N')
|
||||
{
|
||||
mot.SetZDir(ZDIR_CCW);
|
||||
mot.SetZRunL(true);
|
||||
}
|
||||
else if (p2 == 'S')
|
||||
{
|
||||
mot.SetZRunL(false);
|
||||
}
|
||||
}
|
||||
else if (p1 == 'R') //right
|
||||
{
|
||||
if (p2 == 'P')
|
||||
{
|
||||
mot.SetZDir(ZDIR_CW);
|
||||
mot.SetZRunR(true);
|
||||
}
|
||||
else if (p2 == 'N')
|
||||
{
|
||||
mot.SetZDir(ZDIR_CCW);
|
||||
mot.SetZRunR(true);
|
||||
}
|
||||
else if (p2 == 'S')
|
||||
{
|
||||
mot.SetZRunR(false);
|
||||
}
|
||||
}
|
||||
else if (p1 == 'A') //all
|
||||
{
|
||||
if (p2 == 'P')
|
||||
{
|
||||
mot.SetZRun(ZRUN_UP);
|
||||
}
|
||||
else if (p2 == 'N')
|
||||
{
|
||||
mot.SetZRun(ZRUN_DN);
|
||||
}
|
||||
else if (p2 == 'S')
|
||||
{
|
||||
mot.SetZRun(ZRUN_STOP);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (cmd == PINGCHK)
|
||||
{
|
||||
//<2F>ƹ<EFBFBD><C6B9>͵<EFBFBD> ó<><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʴ´<CAB4>.
|
||||
}
|
||||
else {
|
||||
hmi.SendMessage(F("Unknown Command"), true);
|
||||
}
|
||||
}
|
||||
|
||||
void VarClass::eeprom_save()
|
||||
{
|
||||
//param
|
||||
EEPROM.write(EEP_IOINTERVAL, var._eep_iosendinterval);
|
||||
EEPROM.write(EEP_RESETCOUNT, var._eep_resetcount);
|
||||
EEPROM.write(EEP_DIREVH, var._eep_pindir_iH);
|
||||
EEPROM.write(EEP_DIREVL, var._eep_pindir_iL);
|
||||
|
||||
//<2F>ɼǰ<C9BC> <20><><EFBFBD><EFBFBD>
|
||||
bool opt1 = var.getFlag(FLAG_ENABLE_AD4INVERT);
|
||||
bool opt2 = var.getFlag(FLAG_ENABLE_LOG_SPEED);
|
||||
//bool opt3 = var.getFlag(FLAG_ENABLE_BALANCE);
|
||||
//bool opt4 = var.getFlag(FLAG_ENABLE_LIDARSTOP);
|
||||
//bool opt5 = var.getFlag(FLAG_ENABLE_GATEOUT);
|
||||
|
||||
bitWrite(var._eep_option, FLAG_ENABLE_AD4INVERT - 24, opt1);
|
||||
bitWrite(var._eep_option, FLAG_ENABLE_LOG_SPEED - 24, opt2);
|
||||
//bitWrite(var._eep_option, FLAG_ENABLE_BALANCE - 24, opt3);
|
||||
//bitWrite(var._eep_option, FLAG_ENABLE_LIDARSTOP - 24, opt4);
|
||||
//bitWrite(var._eep_option, FLAG_ENABLE_GATEOUT - 24, opt5);
|
||||
|
||||
//hmi.SendMessage("Option Store Value=" + String(var._eep_option), false);
|
||||
EEPROM.write(EEP_OPTION, var._eep_option); //<2F><><EFBFBD><EFBFBD> 200402
|
||||
hmi.SendMessage("@SET|SAVE:" + String(var._eep_option), false);
|
||||
}
|
||||
|
||||
void VarClass::eeprom_load()
|
||||
{
|
||||
//hmi.SendMessage("##:EEPROM:LOAD:BEGIN", false);
|
||||
var._eep_iosendinterval = EEPROM.read(EEP_IOINTERVAL);
|
||||
var._eep_resetcount = EEPROM.read(EEP_RESETCOUNT);
|
||||
var._eep_pindir_iH = EEPROM.read(EEP_DIREVH);
|
||||
var._eep_pindir_iL = EEPROM.read(EEP_DIREVL);
|
||||
var._eep_option = EEPROM.read(EEP_OPTION); //<2F>ɼǰ<C9BC><C7B0><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><D8B3><EFBFBD> <20><><EFBFBD><EFBFBD>Ѵ<EFBFBD>
|
||||
|
||||
//<2F>ɼǰ<C9BC> <20><><EFBFBD><EFBFBD>
|
||||
bool opt1 = bitRead(var._eep_option, FLAG_ENABLE_AD4INVERT - 24);
|
||||
bool opt2 = bitRead(var._eep_option, FLAG_ENABLE_LOG_SPEED - 24);
|
||||
|
||||
|
||||
if (var._eep_iosendinterval == 0 || var._eep_iosendinterval == 0xFF)
|
||||
var._eep_iosendinterval = 50;
|
||||
|
||||
|
||||
|
||||
hmi.SendMessage("@SET|LOAD:" + String(var._eep_option), false);
|
||||
}
|
||||
|
||||
void VarClass::eeprom_incResetCount()
|
||||
{
|
||||
EEPROM.write(EEP_RESETCOUNT, _eep_resetcount);
|
||||
hmi.SendMessage(F("Increase Reset Count"), false);
|
||||
}
|
||||
|
||||
/*
|
||||
system flag
|
||||
*/
|
||||
void VarClass::setFlag(uint8_t pos, bool value, String Readson)
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȯ<EFBFBD><C8AE>
|
||||
bool oldValue = bitRead(var.flag, pos);
|
||||
|
||||
//#####################################
|
||||
// 값이 변경된 경우에 처리
|
||||
//#####################################
|
||||
if (oldValue != value)
|
||||
{
|
||||
bitWrite(var.flag, pos, value);
|
||||
|
||||
if (pos == FLAG_AUTORUN)
|
||||
{
|
||||
if (value == true)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else if (pos == FLAG_STOPZ)
|
||||
{
|
||||
hmi.SendMessage("Z-Stop Condition => " + String(value) + ": " + Readson, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool VarClass::getFlag(uint8_t pos)
|
||||
{
|
||||
return bitRead(var.flag, pos);
|
||||
}
|
||||
uint32_t VarClass::getFlagValue()
|
||||
{
|
||||
return var.flag;
|
||||
}
|
||||
|
||||
VarClass var;
|
||||
Reference in New Issue
Block a user