Skip to content

Commit

Permalink
#25 attempt to add persistance of break settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pkerspe committed Mar 7, 2022
1 parent 3b0b12c commit ae128f6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/ESPStepperMotorServer_Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void ESPStepperMotorServer_Configuration::serializeServerConfiguration(JsonDocum
doc[JSON_SECTION_NAME_SERVER_CONFIGURATION][JSON_PROPERTY_NAME_WIFI_PASSWORD] = (includePasswords) ? this->wifiPassword : "*****";
doc[JSON_SECTION_NAME_SERVER_CONFIGURATION][JSON_PROPERTY_NAME_WIFI_AP_NAME] = this->apName;
doc[JSON_SECTION_NAME_SERVER_CONFIGURATION][JSON_PROPERTY_NAME_WIFI_AP_PASSWORD] = (includePasswords) ? this->apPassword : "*****";
doc[JSON_SECTION_NAME_SERVER_CONFIGURATION][JSON_PROPERTY_NAME_CPUCORE_FOR_MOTIONCONTROLLER_SERVICE] = this->motionControllerCpuCore;

ESPStepperMotorServer_Logger::logInfof("Serializing config \n");

Expand All @@ -120,7 +121,7 @@ void ESPStepperMotorServer_Configuration::serializeServerConfiguration(JsonDocum
}
if (this->dns2IP != 0)
{
ESPStepperMotorServer_Logger::logInfof("DSN2 ip = %s \n", this->dns2IP.toString().c_str());
ESPStepperMotorServer_Logger::logInfof("DNS2 ip = %s \n", this->dns2IP.toString().c_str());
doc[JSON_SECTION_NAME_SERVER_CONFIGURATION][JSON_PROPERTY_NAME_WIFI_STATIC_IP_DNS2] = this->dns2IP.toString();
}

Expand All @@ -140,6 +141,10 @@ void ESPStepperMotorServer_Configuration::serializeServerConfiguration(JsonDocum
nestedStepperConfig["stepsPerMM"] = stepperConfig->getStepsPerMM();
nestedStepperConfig["microsteppingDivisor"] = stepperConfig->getMicrostepsPerStep();
nestedStepperConfig["rpmLimit"] = stepperConfig->getRpmLimit();
nestedStepperConfig["breakPin"] = stepperConfig->getBrakeIoPin();
nestedStepperConfig["breakPinActiveState"] = stepperConfig->getBrakePinActiveState();
nestedStepperConfig["breakEngageDelay"] = stepperConfig->getBrakeEngageDelayMs();
nestedStepperConfig["breakReleaseDelay"] = stepperConfig->getBrakeReleaseDelayMs();
}
}

Expand Down Expand Up @@ -259,6 +264,9 @@ bool ESPStepperMotorServer_Configuration::loadConfiguationFromSpiffs(String file
value = doc[JSON_SECTION_NAME_SERVER_CONFIGURATION][JSON_PROPERTY_NAME_WIFI_AP_PASSWORD];
this->apPassword = (value) ? value.as<char *>() : "Aa123456";

value = doc[JSON_SECTION_NAME_SERVER_CONFIGURATION][JSON_PROPERTY_NAME_CPUCORE_FOR_MOTIONCONTROLLER_SERVICE];
this->motionControllerCpuCore = (value) ? value.as<int>() : 0;

this->wifiSsid = doc[JSON_SECTION_NAME_SERVER_CONFIGURATION][JSON_PROPERTY_NAME_WIFI_SSID].as<char *>();
this->wifiPassword = doc[JSON_SECTION_NAME_SERVER_CONFIGURATION][JSON_PROPERTY_NAME_WIFI_PASSWORD].as<char *>();

Expand Down Expand Up @@ -304,6 +312,13 @@ bool ESPStepperMotorServer_Configuration::loadConfiguationFromSpiffs(String file
(stepperConfigEntry["stepsPerMM"] | 100),
(stepperConfigEntry["microsteppingDivisor"] | ESPSMS_MICROSTEPS_OFF),
(stepperConfigEntry["rpmLimit"] | 1000));

//check if break pin is used at all
if(stepperConfig->getBrakeIoPin() != stepperConfig->ESPServerStepperUnsetIoPinNumber){
stepperConfig->setBrakeIoPin(stepperConfigEntry["breakPin"] | stepperConfig->ESPServerStepperUnsetIoPinNumber, stepperConfigEntry["breakPinActiveState"] | 1);
stepperConfig->setBrakeEngageDelayMs(stepperConfigEntry["breakEngageDelay"] | 0);
stepperConfig->setBrakeReleaseDelayMs(stepperConfigEntry["breakReleaseDelay"] | -1);
}
if (stepperConfigEntry["id"])
{
this->setStepperConfiguration(stepperConfig, stepperConfigEntry["id"]);
Expand Down
2 changes: 2 additions & 0 deletions src/ESPStepperMotorServer_Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class ESPStepperMotorServer_Configuration
const char *apPassword = "Aa123456";
const char *wifiSsid = "undefined";
const char *wifiPassword = "undefined";
int motionControllerCpuCore = 0;

IPAddress staticIP;
IPAddress gatewayIP;
Expand Down Expand Up @@ -141,6 +142,7 @@ class ESPStepperMotorServer_Configuration
const char *JSON_PROPERTY_NAME_WIFI_PASSWORD = "wifiPassword";
const char *JSON_PROPERTY_NAME_WIFI_AP_NAME = "apName";
const char *JSON_PROPERTY_NAME_WIFI_AP_PASSWORD = "apPassword";
const char *JSON_PROPERTY_NAME_CPUCORE_FOR_MOTIONCONTROLLER_SERVICE = "motionControllerCpuCore";

//for static IP settings
const char *JSON_PROPERTY_NAME_WIFI_STATIC_IP_ADDRESS = "staticIP";
Expand Down
8 changes: 7 additions & 1 deletion src/ESPStepperMotorServer_StepperConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ void ESPStepperMotorServer_StepperConfiguration::setBrakeReleaseDelayMs(long del
this->_flexyStepper->setBrakeReleaseDelayMs(delay);
}

void ESPStepperMotorServer_StepperConfiguration::setBrakePinActiveState(byte activeState)
{
this->_brakePinActiveState = activeState;
this->_flexyStepper->setBrakePin(this->_brakeIoPin, this->_brakePinActiveState);
}

// motion configurateion settings
void ESPStepperMotorServer_StepperConfiguration::setStepsPerRev(unsigned int stepsPerRev)
{
Expand Down Expand Up @@ -233,4 +239,4 @@ void ESPStepperMotorServer_StepperConfiguration::setRpmLimit(unsigned int rpmLim
unsigned int ESPStepperMotorServer_StepperConfiguration::getRpmLimit()
{
return this->_rpmLimit;
}
}
3 changes: 2 additions & 1 deletion src/ESPStepperMotorServer_StepperConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class ESPStepperMotorServer_StepperConfiguration
long getBrakeReleaseDelayMs();

void setBrakeIoPin(byte, byte);
void setBrakePinActiveState(byte);
void setBrakeEngageDelayMs(long);
void setBrakeReleaseDelayMs(long);

Expand Down Expand Up @@ -196,4 +197,4 @@ class ESPStepperMotorServer_StepperConfiguration
unsigned int _rpmLimit = 1200;
};
// ------------------------------------ End ---------------------------------
#endif
#endif

0 comments on commit ae128f6

Please sign in to comment.