Restore Feature Parity

Everything seems to work this time.
This commit is contained in:
mrcory
2020-02-16 19:59:23 -05:00
parent 1503d9dac8
commit 21c4a62ea2
6 changed files with 182 additions and 69 deletions
+2 -6
View File
@@ -9,9 +9,7 @@
*
* .! This is used for both motor types !.
*/
#define stepperSpeed 1100.0 //Max Speed
#define stepperAccel 175.0 //Acceleration Rate
motorSpeedStruct mSpeed = {
1000, //Up Speed
1000, //Down Speed
@@ -42,8 +40,6 @@ int connectTimeout = 100; // How many attempts can we make before giving up
#include "blynk.h" //Contains Blynk login
//Comment the below line to disable Blynk Serail feedback
#define BLYNK_PRINT Serial
//------Timer
int stepperPos[] = {0,6000};
@@ -101,7 +97,7 @@ int pulseMax = 250; //Max brightness for pulse mode. Max 250 or it wil
//FastLED Settings
#define NUM_LEDS 9 //Number of attached LEDs
#define DATA_PIN D1 //Communication pin for the LEDs | Same pin will be used for either LED control
#define DATA_PIN D2 //Communication pin for the LEDs | Same pin will be used for either LED control
#define LED_TYPE WS2812 //LED controller
#define COLOR_ORDER GRB //Order to send colors
+28 -1
View File
@@ -3,6 +3,7 @@
void configSave() {
//Position 400 is reserved for the blynk token
EEPROM.write(0,1); //Flag for autoload
EEPROM.put(3,configVersion);
int i=5;
EEPROM.put(i,savedPosition);
i+=sizeof(savedPosition);
@@ -10,6 +11,16 @@ void configSave() {
i+=sizeof(lastPosition);
EEPROM.put(i,mInvert.is);
i+=sizeof(mInvert.is);
EEPROM.put(i,pwm.set);
i+=sizeof(pwm.set);
EEPROM.put(i,mInvert.set);
i+=sizeof(mInvert.set);
EEPROM.put(i,mSpeed.up);
i+=sizeof(mSpeed.up);
EEPROM.put(i,mSpeed.dn);
i+=sizeof(mSpeed.dn);
EEPROM.put(i,mSpeed.accel);
i+=sizeof(mSpeed.accel);
EEPROM.commit();
Serial.println("Config Saved");
}
@@ -22,6 +33,16 @@ void configLoad() {
i+=sizeof(lastPosition);
EEPROM.get(i,mInvert.is);
i+=sizeof(mInvert.is);
EEPROM.get(i,pwm.set);
i+=sizeof(pwm.set);
EEPROM.get(i,mInvert.set);
i+=sizeof(mInvert.set);
EEPROM.get(i,mSpeed.up);
i+=sizeof(mSpeed.up);
EEPROM.get(i,mSpeed.dn);
i+=sizeof(mSpeed.dn);
EEPROM.get(i,mSpeed.accel);
i+=sizeof(mSpeed.accel);
Serial.println("Config Loaded");
Serial.println(savedPosition);
}
@@ -102,7 +123,7 @@ void speedCheck() { //Set speed based on direction
stepper.setMaxSpeed(mSpeed.up); //Up Speed
Serial.print("Speed set to "); Serial.println(mSpeed.up);
}
stepper.setAcceleration(stepperAccel); //Update acceleration
stepper.setAcceleration(mSpeed.accel); //Update acceleration
}
void checkInvert() {
@@ -192,3 +213,9 @@ bool timerFunc(int _comp) {
return false;
}
}
byte returnConfigVersion() {
byte grabbedVersion;
EEPROM.get(3,grabbedVersion);
return grabbedVersion;
}
+56
View File
@@ -0,0 +1,56 @@
void lightControl() {
if (lightMode == 1) { //Use FastLED if selected
if (lightOn == true) {
fill_solid(leds,NUM_LEDS,CRGB(currentColor[0],currentColor[1],currentColor[2]));
}
if (lightOn == false && lightOld != lightOn) {
fill_solid(leds,NUM_LEDS,CRGB(0,0,0));
}
lightOld = lightOn;
static bool _direction = false; //Flag for fade direction
if (pulse == true) {
if (timerFunc(pulseSpeed)) {
if (_direction == true) {
if (ledBrightness < pulseMax) { ledBrightness+=2; } else {_direction = false;}
}
if (_direction == false) {
if (ledBrightness > 5) { ledBrightness-=2; } else {_direction = true;}
}
}
}
}
//PWM Code ---------------------------
if (lightMode == 0) {
if (pwm.on == false && pwm.set > 0) {
pwm.set = 0;
}
}
if (lightMode == 0) {
if (pwm.on == false || pwm.set == 0) {
pwm.out = 0;
analogWrite(PWM_PIN,pwm.out);
}
}
if (pwm.on == true && pwm.set != pwm.out) {
pwm.out = pwm.set;
analogWrite(PWM_PIN,pwm.out);
}
if (pwm.on == false && pwm.set != pwm.old) {
pwm.on = true;
}
if (pwm.on == true && pwm.set == 0) {
pwm.on = false;
}
}
+48 -60
View File
@@ -11,8 +11,10 @@
* rst | Reset home position to 0
*/
//version 2.0.0
const int configVersion = 1;
#define BLYNK_PRINT Serial
//version 2.5.1
const int configVersion = 3;
#include "structs.h"
@@ -24,7 +26,6 @@ long currentDistance = 0;
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Ethernet.h>
#include "config.h"
@@ -77,15 +78,21 @@ bool pulse = false; //Basic effect
bool lightOn = false;
bool lightOld = true;
int oldBrightness = ledBrightness;
//int oldBrightness = ledBrightness;
int currentColor[3] = {255,255,255};
int pulseSpeed = 2;
bool pwmOn = false;
bool pwmOld = false;
int pwmBrightness = 0;
//bool pwmOn = false;
//bool pwmOld = false;
//int pwmBrightness = 0;
pwmStruct pwm = {
ledBrightness, //old
0, //set
false, //on
false, //onOld
0 //out
};
#include "wifi.h"
@@ -144,8 +151,8 @@ int pwmBrightness = 0;
}
if (lightMode == 0) {
pwmOn = !pwmOn;
pwmBrightness = ledButtonBrightness;
pwm.on = !pwm.on;
pwm.set = ledButtonBrightness;
}
ledTurn(1);
@@ -154,6 +161,7 @@ int pwmBrightness = 0;
void resetHold() {
Serial.println("Rst Hold");
stepper.setCurrentPosition(0);
configSave();
ledTurn(1);
}
@@ -172,10 +180,12 @@ int pwmBrightness = 0;
BlynkTimer timer1;
#endif
#include "lightcontrol.h"
void setup() {
Serial.begin(74880);
Serial.println("dsadsadaas");
delay(50);
@@ -204,16 +214,19 @@ void setup() {
Serial.begin(115200);
Serial.println("");
delay(50);
blynkConfig();
setupOTA();
EEPROM.begin(eepromSize); //Initialize the EEPROM with our selected size
if (EEPROM.read(0) == 1) { //If flagged in EEPROM; we load our current position
if (EEPROM.read(0) == 1 && returnConfigVersion() == configVersion) { //If flagged in EEPROM; we load our current position
configLoad();
Serial.println("Pass Config Version Check");
} else {
Serial.println("Fail Config Version Check, Reseting To Default");
configSave();
}
@@ -243,7 +256,7 @@ void setup() {
void loop() {
oldBrightness = ledBrightness;
pwm.old = ledBrightness;
currentDistance = stepper.distanceToGo();
if (ledFeedback == true) {
@@ -271,7 +284,7 @@ void loop() {
lightControl();
if (lightMode == 1) { //Use FastLED if selected
if (ledBrightness != oldBrightness) {
if (ledBrightness != pwm.old) {
FastLED.setBrightness(ledBrightness);
}
@@ -279,9 +292,9 @@ void loop() {
}
if (lightMode == 0) {
if (pwmBrightness != pwmOld) {
analogWrite(PWM_PIN,pwmBrightness);
pwmOld = pwmBrightness;
if (pwm.set != pwm.onOld) {
analogWrite(PWM_PIN,pwm.set);
pwm.onOld = pwm.set;
}
}
}
@@ -294,43 +307,18 @@ void loop() {
motorControl();
ArduinoOTA.handle();
if (resetFlag == true) {
ESP.reset();
}
if (configLoadFlag == true) {
configLoad();
configLoadFlag = false;
}
if (configSaveFlag == true) {
configSave();
configSaveFlag = false;
}
} //END LOOP
void lightControl() {
if (lightMode == 1) { //Use FastLED if selected
if (lightOn == true) {
fill_solid(leds,NUM_LEDS,CRGB(currentColor[0],currentColor[1],currentColor[2]));
}
if (lightOn == false && lightOld != lightOn) {
fill_solid(leds,NUM_LEDS,CRGB(0,0,0));
}
lightOld = lightOn;
static bool _direction = false; //Flag for fade direction
if (pulse == true) {
if (timerFunc(pulseSpeed)) {
if (_direction == true) {
if (ledBrightness < pulseMax) { ledBrightness+=2; } else {_direction = false;}
}
if (_direction == false) {
if (ledBrightness > 5) { ledBrightness-=2; } else {_direction = true;}
}
}
}
}
if (lightMode == 0) {
if (pwmOn == false && pwmBrightness > 0) {
pwmBrightness = 0;
}
}
//------LED Strip
}
+9
View File
@@ -15,3 +15,12 @@ motorInvertStruct mInvert = {
false,
false
};
//PWM Struct
struct pwmStruct {
int old;
int set;
bool on;
bool onOld;
int out;
};
+39 -2
View File
@@ -1,11 +1,25 @@
bool firstRun = true;
bool resetFlag = false;
bool configLoadFlag = false;
bool configSaveFlag = false;
void sendBlynk() { //Blynk Feedback
Blynk.virtualWrite(V1,stepper.currentPosition());
if (pwm.old != pwm.set) {
Blynk.virtualWrite(V27,pwm.set);
Blynk.virtualWrite(V28,pwm.on);
}
if (firstRun == true) {
Blynk.virtualWrite(V11,shade[4]);
Blynk.virtualWrite(V27,pwm.set);
Blynk.virtualWrite(V30,mSpeed.up);
Blynk.virtualWrite(V31,mSpeed.accel);
Blynk.virtualWrite(V34,mSpeed.dn);
Blynk.virtualWrite(V32,mInvert.is);
firstRun = false;
}
@@ -55,14 +69,37 @@ BLYNK_WRITE(V26) {
}
BLYNK_WRITE(V27) {
pwmBrightness = param.asInt();
pwm.set = param.asInt();
}
BLYNK_WRITE(V28) {
pwmOn = param.asInt();
pwm.on = param.asInt();
}
BLYNK_WRITE(V30) {
mSpeed.up = param.asInt();
}
BLYNK_WRITE(V31) {
mSpeed.accel = param.asInt();
}
BLYNK_WRITE(V32) { //Invert direction
mInvert.set = param.asInt();
}
BLYNK_WRITE(V33) {
configSaveFlag = param.asInt();
}
BLYNK_WRITE(V34) {
mSpeed.dn = param.asInt();
}
BLYNK_WRITE(V35) {
resetFlag = param.asInt();
}
BLYNK_WRITE(V36) {
configLoadFlag = param.asInt();
}