浏览代码

save status values in EEPROM

master
gituser 10 个月前
父节点
当前提交
2361b13e8b
共有 4 个文件被更改,包括 55 次插入11 次删除
  1. 3
    0
      .cproject
  2. 5
    0
      .project
  3. 45
    10
      FSRemotePowerSwitch.ino
  4. 2
    1
      sloeber.ino.cpp

+ 3
- 0
.cproject 查看文件

<listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/AccelStepper/src}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/AccelStepper/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/ArduinoJson/src}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/ArduinoJson/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/core/variant}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/core/variant}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/EEPROM/src}&quot;"/>
</option> </option>
<inputType id="io.sloeber.compiler.cpp.sketch.input.1496076099" name="CPP source files" superClass="io.sloeber.compiler.cpp.sketch.input"/> <inputType id="io.sloeber.compiler.cpp.sketch.input.1496076099" name="CPP source files" superClass="io.sloeber.compiler.cpp.sketch.input"/>
</tool> </tool>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/AccelStepper/src}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/AccelStepper/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/ArduinoJson/src}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/ArduinoJson/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/core/variant}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/core/variant}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/EEPROM/src}&quot;"/>
</option> </option>
<inputType id="io.sloeber.compiler.c.sketch.input.280688484" name="C Source Files" superClass="io.sloeber.compiler.c.sketch.input"/> <inputType id="io.sloeber.compiler.c.sketch.input.280688484" name="C Source Files" superClass="io.sloeber.compiler.c.sketch.input"/>
</tool> </tool>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/AccelStepper/src}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/AccelStepper/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/ArduinoJson/src}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/ArduinoJson/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/core/variant}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/core/variant}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/FSRemotePowerSwitch/libraries/EEPROM/src}&quot;"/>
</option> </option>
<inputType id="io.sloeber.compiler.S.sketch.input.288275921" name="Assembly source files" superClass="io.sloeber.compiler.S.sketch.input"/> <inputType id="io.sloeber.compiler.S.sketch.input.288275921" name="Assembly source files" superClass="io.sloeber.compiler.S.sketch.input"/>
</tool> </tool>

+ 5
- 0
.project 查看文件

<type>2</type> <type>2</type>
<locationURI>ECLIPSE_HOME/arduinoPlugin/libraries/ArduinoJson/7.0.2</locationURI> <locationURI>ECLIPSE_HOME/arduinoPlugin/libraries/ArduinoJson/7.0.2</locationURI>
</link> </link>
<link>
<name>libraries/EEPROM</name>
<type>2</type>
<locationURI>ECLIPSE_HOME/arduinoPlugin/packages/arduino/hardware/avr/1.8.4/libraries/EEPROM</locationURI>
</link>
</linkedResources> </linkedResources>
</projectDescription> </projectDescription>

+ 45
- 10
FSRemotePowerSwitch.ino 查看文件

#include <AccelStepper.h> #include <AccelStepper.h>
#include <HardwareSerial.h> #include <HardwareSerial.h>
#include <math.h> #include <math.h>
#include <EEPROM.h>


const char *Version = "V1.3.0"; const char *Version = "V1.3.0";


const int PWR_RELAY_PIN = 5; const int PWR_RELAY_PIN = 5;
const int PWR_CAM_PIN = 6; const int PWR_CAM_PIN = 6;


const int eepromAddrStatusRelay = 100;
const int eepromAddrStatusCam = 200;
const int eepromAddrStatusCamVel = 300;
const int eepromAddrActAzimut = 400;

JsonDocument msg; JsonDocument msg;
String stepperVelocity; String stepperVelocity;
int actAzimut;


// Define motor interface type // Define motor interface type
#define motorInterfaceType AccelStepper::MotorInterfaceType::HALF4WIRE #define motorInterfaceType AccelStepper::MotorInterfaceType::HALF4WIRE
pinMode(PWR_RELAY_PIN, OUTPUT); pinMode(PWR_RELAY_PIN, OUTPUT);
pinMode(PWR_CAM_PIN, OUTPUT); pinMode(PWR_CAM_PIN, OUTPUT);


setSlowStepperVelocity(); // Slow: Acc: 500 / Fast: MaxSpeed: 1000
// Slow: Acc: 200 / Fast: MaxSpeed: 500
int velocity = EEPROM.read(eepromAddrStatusCamVel);
if (velocity == 0) {
setSlowStepperVelocity(); // Slow: Acc: 200 / Slow: MaxSpeed: 500
} else {
setFastStepperVelocity(); // Fast: Acc: 500 / Fast: MaxSpeed: 1000
}

int powerRel = EEPROM.read(eepromAddrStatusRelay);
if (powerRel == 0) {
digitalWrite(PWR_RELAY_PIN, LOW);
} else {
digitalWrite(PWR_RELAY_PIN, HIGH);
}

int camRel = EEPROM.read(eepromAddrStatusCam);
if (powerRel == 0) {
digitalWrite(PWR_CAM_PIN, LOW);
} else {
digitalWrite(PWR_CAM_PIN, HIGH);
}


digitalWrite(PWR_RELAY_PIN, HIGH);
digitalWrite(PWR_CAM_PIN, HIGH);
actAzimut = EEPROM.read(eepromAddrActAzimut);
if (actAzimut > 180) {
actAzimut = 0;
}
stepper.setCurrentPosition(round((4076.0 / 360.0) * ((double) actAzimut) * -1));
} }


/* The loop function runs over and and checks the serial port for receiving a Json of following format: /* The loop function runs over and and checks the serial port for receiving a Json of following format:
if (digitalRead(PWR_RELAY_PIN) == LOW) { if (digitalRead(PWR_RELAY_PIN) == LOW) {
moveStepper(); moveStepper();
sendRelayPowerStatus(CMD_VAL_ON); sendRelayPowerStatus(CMD_VAL_ON);
EEPROM.write(eepromAddrStatusRelay, 0);
} else { } else {
moveStepper(); moveStepper();
sendRelayPowerStatus(CMD_VAL_OFF); sendRelayPowerStatus(CMD_VAL_OFF);
EEPROM.write(eepromAddrStatusRelay, 1);
} }


} else if (sdr == CMD_SENDER_PC && cmd == CMD_STATUS_RELAY) { } else if (sdr == CMD_SENDER_PC && cmd == CMD_STATUS_RELAY) {
if (digitalRead(PWR_CAM_PIN) == LOW) { if (digitalRead(PWR_CAM_PIN) == LOW) {
moveStepper(); moveStepper();
sendCamPowerStatus(CMD_VAL_ON); sendCamPowerStatus(CMD_VAL_ON);
EEPROM.write(eepromAddrStatusCam, 0);
} else { } else {
moveStepper(); moveStepper();
sendCamPowerStatus(CMD_VAL_OFF); sendCamPowerStatus(CMD_VAL_OFF);
EEPROM.write(eepromAddrStatusCam, 1);
} }


} else if (sdr == CMD_SENDER_PC && cmd == CMD_STATUS_CAM) { } else if (sdr == CMD_SENDER_PC && cmd == CMD_STATUS_CAM) {
sendCamPowerStatus(CMD_VAL_OFF); sendCamPowerStatus(CMD_VAL_OFF);
} }


} else if (sdr == CMD_SENDER_PC && cmd == CMD_ZERO_CAM) {
stepper.setCurrentPosition(0);
sendZeroCamStatus(String(stepper.currentPosition()));

} else if (sdr == CMD_SENDER_PC && cmd == CMD_VELOCITY_CAM) { } else if (sdr == CMD_SENDER_PC && cmd == CMD_VELOCITY_CAM) {
if (val.equals(CMD_VELOCITY_FAST)) { if (val.equals(CMD_VELOCITY_FAST)) {
setFastStepperVelocity(); setFastStepperVelocity();
} else if (sdr == CMD_SENDER_PC && cmd == CMD_STATUS_VELOCITY_CAM) { } else if (sdr == CMD_SENDER_PC && cmd == CMD_STATUS_VELOCITY_CAM) {
sendCamVelocityStatus(); sendCamVelocityStatus();


} else if (sdr == CMD_SENDER_PC && cmd == CMD_ZERO_CAM) {
stepper.setCurrentPosition(0);
sendZeroCamStatus(String(stepper.currentPosition()));
EEPROM.write(eepromAddrActAzimut, 0);

} else if (sdr == CMD_SENDER_PC && cmd == CMD_ACT_AZIMUT_CAM) { } else if (sdr == CMD_SENDER_PC && cmd == CMD_ACT_AZIMUT_CAM) {
int actAzi = round(stepper.currentPosition() / (4076.0 / 360.0) * -1); int actAzi = round(stepper.currentPosition() / (4076.0 / 360.0) * -1);
sendCamActAzimut(String(actAzi)); sendCamActAzimut(String(actAzi));
long target = round((4076.0 / 360.0) * val.toDouble() * -1); long target = round((4076.0 / 360.0) * val.toDouble() * -1);
stepper.moveTo(target); stepper.moveTo(target);
stepper.run(); stepper.run();
EEPROM.write(eepromAddrActAzimut, val.toInt());
} }
} }


stepper.setMaxSpeed(1000); // Slow: 500 / Fast: 1000 stepper.setMaxSpeed(1000); // Slow: 500 / Fast: 1000
stepper.setAcceleration(500); // Slow: 200 / Fast: 500 stepper.setAcceleration(500); // Slow: 200 / Fast: 500
stepper.setSpeed(1000); stepper.setSpeed(1000);
EEPROM.write(eepromAddrStatusCamVel, 1);
} }


void setSlowStepperVelocity() { void setSlowStepperVelocity() {
stepper.setMaxSpeed(500); // Slow: 500 / Fast: 1000 stepper.setMaxSpeed(500); // Slow: 500 / Fast: 1000
stepper.setAcceleration(200); // Slow: 200 / Fast: 500 stepper.setAcceleration(200); // Slow: 200 / Fast: 500
stepper.setSpeed(500); stepper.setSpeed(500);
EEPROM.write(eepromAddrStatusCamVel, 0);
} }



void sendVersion() { void sendVersion() {
msg["Sender"] = CMD_SENDER_AN; msg["Sender"] = CMD_SENDER_AN;
msg["Cmd"] = CMD_VER; msg["Cmd"] = CMD_VER;


void sendCamVelocityStatus() { void sendCamVelocityStatus() {
msg["Sender"] = CMD_SENDER_AN; msg["Sender"] = CMD_SENDER_AN;
msg["Cmd"] = CMD_VELOCITY_CAM;
msg["Cmd"] = CMD_STATUS_VELOCITY_CAM;
msg["Val"] = stepperVelocity; msg["Val"] = stepperVelocity;


serializeJson(msg, Serial); serializeJson(msg, Serial);

+ 2
- 1
sloeber.ino.cpp 查看文件

//This is a automatic generated file //This is a automatic generated file
//Please do not modify this file //Please do not modify this file
//If you touch this file your change will be overwritten during the next build //If you touch this file your change will be overwritten during the next build
//This file has been generated on 2025-01-22 22:57:08
//This file has been generated on 2025-01-23 16:55:38


#include "Arduino.h" #include "Arduino.h"
#include "Arduino.h" #include "Arduino.h"
#include <AccelStepper.h> #include <AccelStepper.h>
#include <HardwareSerial.h> #include <HardwareSerial.h>
#include <math.h> #include <math.h>
#include <EEPROM.h>


void setup() ; void setup() ;
void loop() ; void loop() ;

正在加载...
取消
保存