mirror of
https://github.com/anklimov/lighthub
synced 2025-12-09 21:29:49 +03:00
MASSIVE refactoring. /set scale changed 100 -> 255
This commit is contained in:
@@ -213,6 +213,7 @@ inline unsigned char toHex( char ch ){
|
||||
|
||||
int out_AC::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
Serial.println("AC Init");
|
||||
AC_Serial.begin(9600);
|
||||
driverStatus = CST_INITIALIZED;
|
||||
@@ -280,7 +281,7 @@ int out_AC::Ctrl(itemCmd cmd, char* subItem , bool toExecute)
|
||||
switch(suffixCode)
|
||||
{
|
||||
case S_SET:
|
||||
case S_ESET:
|
||||
//case S_ESET:
|
||||
set_tmp = cmd.getInt();
|
||||
if (set_tmp >= 10 && set_tmp <= 30)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
#ifndef AC_DISABLE
|
||||
#include <abstractout.h>
|
||||
#include "itemCmd.h"
|
||||
|
||||
#define LEN_B 37
|
||||
#define B_CUR_TMP 13 //Текущая температура
|
||||
@@ -29,7 +30,7 @@ public:
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
int isActive() override;
|
||||
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||
int getDefaultStorageType(){return ST_FLOAT_CELSIUS;};
|
||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -13,6 +13,7 @@ static int driverStatus = CST_UNKNOWN;
|
||||
|
||||
int out_dmx::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
debugSerial<<F("DMX-Out Init")<<endl;
|
||||
driverStatus = CST_INITIALIZED;
|
||||
return 1;
|
||||
@@ -88,7 +89,7 @@ if (cType==CH_DIMMER) //Single channel
|
||||
storageType=ST_RGBW;
|
||||
break;
|
||||
default:
|
||||
storageType=ST_PERCENTS;
|
||||
storageType=ST_PERCENTS255;
|
||||
}
|
||||
|
||||
itemCmd st(storageType,CMD_VOID);
|
||||
|
||||
@@ -155,6 +155,7 @@ bool out_Modbus::getConfig()
|
||||
|
||||
int out_Modbus::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
if (!store) store= (mbPersistent *)item->setPersistent(new mbPersistent);
|
||||
if (!store)
|
||||
{ errorSerial<<F("MBUS: Out of memory")<<endl;
|
||||
@@ -194,10 +195,6 @@ if (store)
|
||||
return CST_UNKNOWN;
|
||||
}
|
||||
|
||||
int out_Modbus::isActive()
|
||||
{
|
||||
return item->getVal();
|
||||
}
|
||||
|
||||
|
||||
bool readModbus(uint16_t reg, int regType, int count)
|
||||
@@ -464,7 +461,7 @@ case S_NOTFOUND:
|
||||
toExecute = true;
|
||||
debugSerial<<F("Forced execution");
|
||||
case S_SET:
|
||||
case S_ESET:
|
||||
//case S_ESET:
|
||||
if (!cmd.isValue()) return 0;
|
||||
|
||||
//TODO
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#ifndef MBUS_DISABLE
|
||||
#include <abstractout.h>
|
||||
#include <item.h>
|
||||
#include "itemCmd.h"
|
||||
|
||||
#if defined(ESP32)
|
||||
#define serialParamType uint32_t
|
||||
@@ -34,9 +35,9 @@ public:
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
int isActive() override;
|
||||
int getChanType() override;
|
||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
|
||||
int getDefaultStorageType(){return ST_INT32;};
|
||||
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -48,6 +48,7 @@ void out_Motor::getConfig()
|
||||
|
||||
int out_Motor::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
getConfig();
|
||||
Serial.println("Motor Init");
|
||||
pinMode(pinUp,OUTPUT);
|
||||
@@ -82,7 +83,7 @@ int out_Motor::Status()
|
||||
{
|
||||
return driverStatus;
|
||||
}
|
||||
|
||||
/*
|
||||
int out_Motor::isActive()
|
||||
{
|
||||
itemCmd st;
|
||||
@@ -94,10 +95,10 @@ switch (item->getCmd())
|
||||
break;
|
||||
default:
|
||||
st.loadItem(item);
|
||||
return st.getPercents();
|
||||
return st.getPercents255();
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
int out_Motor::Poll(short cause)
|
||||
{
|
||||
int curPos = -1;
|
||||
@@ -118,7 +119,7 @@ if (!item->getFlag(ACTION_IN_PROCESS))
|
||||
uint32_t motorOfftime = item->getExt();
|
||||
itemCmd st;
|
||||
st.loadItem(item);
|
||||
targetPos = st.getPercents();// item->getVal();
|
||||
targetPos = st.getPercents255();// item->getVal();
|
||||
|
||||
switch (item->getCmd())
|
||||
{
|
||||
@@ -137,18 +138,17 @@ int fb=-1;
|
||||
if (pinFeedback && isAnalogPin(pinFeedback))
|
||||
{
|
||||
|
||||
curPos=map((fb=analogRead(pinFeedback)),feedbackClosed,feedbackOpen,0,100);
|
||||
curPos=map((fb=analogRead(pinFeedback)),feedbackClosed,feedbackOpen,0,255);
|
||||
if (curPos<0) curPos=0;
|
||||
if (curPos>100) curPos=100;
|
||||
if (curPos>255) curPos=255;
|
||||
}
|
||||
|
||||
//if (motorOfftime && motorOfftime<millis()) //Time over
|
||||
if (motorOfftime && isTimeOver(motorOfftime,millis(),maxOnTime))
|
||||
{dif = 0; debugSerial<<F("Motor timeout")<<endl;}
|
||||
else if (curPos>=0)
|
||||
dif=targetPos-curPos;
|
||||
else
|
||||
dif=targetPos-50; // Have No feedback
|
||||
dif=targetPos-255/2; // Have No feedback
|
||||
|
||||
debugSerial<<F("In:")<<pinFeedback<<F(" Val:")<<fb<<F("/")<<curPos<<F("->")<<targetPos<<F(" delta:")<<dif<<endl;
|
||||
|
||||
@@ -168,8 +168,8 @@ if (digitalPinHasPWM(pinUp))
|
||||
{
|
||||
//Serial.println("pinUP PWM");
|
||||
int velocity;
|
||||
if (inverted) velocity = map(-dif, 0, 10, 255, 0);
|
||||
else velocity = map(-dif, 0, 10, 0, 255);
|
||||
if (inverted) velocity = map(-dif, 0, 255/10, 255, 0);
|
||||
else velocity = map(-dif, 0, 255/10, 0, 255);
|
||||
|
||||
velocity = constrain (velocity, MIN_PWM, 255);
|
||||
|
||||
@@ -183,8 +183,8 @@ else if (digitalPinHasPWM(pinDown))
|
||||
|
||||
int velocity;
|
||||
if (inverted)
|
||||
velocity = map(-dif, 0, 10, 0, 255);
|
||||
else velocity = map(-dif, 0, 10, 255, 0);
|
||||
velocity = map(-dif, 0, 255/10, 0, 255);
|
||||
else velocity = map(-dif, 0, 255/10, 255, 0);
|
||||
|
||||
velocity = constrain (velocity, MIN_PWM, 255);
|
||||
analogWrite(pinDown,velocity);
|
||||
@@ -209,8 +209,8 @@ if (digitalPinHasPWM(pinDown))
|
||||
{
|
||||
//Serial.println("pinDown PWM");
|
||||
int velocity;
|
||||
if (inverted) velocity = map(dif, 0, 20, 255, 0);
|
||||
else velocity = map(dif, 0, 20, 0, 255);
|
||||
if (inverted) velocity = map(dif, 0, 255/5, 255, 0);
|
||||
else velocity = map(dif, 0, 255/5, 0, 255);
|
||||
|
||||
velocity = constrain (velocity, MIN_PWM, 255);
|
||||
|
||||
@@ -223,8 +223,8 @@ if (digitalPinHasPWM(pinUp))
|
||||
digitalWrite(pinDown,ACTIVE);
|
||||
|
||||
int velocity;
|
||||
if (inverted) velocity = map(dif, 0, 10, 0, 255);
|
||||
else velocity = map(dif, 0, 10, 255, 0);
|
||||
if (inverted) velocity = map(dif, 0, 255/10, 0, 255);
|
||||
else velocity = map(dif, 0, 255/10, 255, 0);
|
||||
|
||||
if (velocity>255) velocity=255;
|
||||
if (velocity<0) velocity=0;
|
||||
@@ -277,7 +277,7 @@ case S_NOTFOUND:
|
||||
toExecute = true;
|
||||
debugSerial<<F("Forced execution");
|
||||
case S_SET:
|
||||
case S_ESET:
|
||||
//case S_ESET:
|
||||
if (!cmd.isValue()) return 0;
|
||||
// item->setVal(cmd.getPercents());
|
||||
if (item->getExt()) item->setExt(millisNZ()); //Extend motor time
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
#ifndef MOTOR_DISABLE
|
||||
#include <abstractout.h>
|
||||
#include <item.h>
|
||||
#include "itemCmd.h"
|
||||
|
||||
#ifndef POS_ERR
|
||||
#define POS_ERR 5
|
||||
#define POS_ERR 10
|
||||
#endif
|
||||
|
||||
#define MIN_PWM 70
|
||||
@@ -24,8 +25,9 @@ public:
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
int isActive() override;
|
||||
//int isActive() override;
|
||||
int getChanType() override;
|
||||
int getDefaultStorageType(){return ST_PERCENTS255;};
|
||||
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ bool out_pid::getConfig()
|
||||
return false;
|
||||
}
|
||||
double outMin=0.;
|
||||
double outMax=100.;
|
||||
double outMax=255.;
|
||||
aJsonObject * param;
|
||||
switch (aJson.getArraySize(kPIDObj))
|
||||
{ case 5:
|
||||
@@ -89,6 +89,7 @@ bool out_pid::getConfig()
|
||||
|
||||
int out_pid::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
if (!store) store= (pidPersistent *)item->setPersistent(new pidPersistent);
|
||||
if (!store)
|
||||
{ errorSerial<<F("PID: Out of memory")<<endl;
|
||||
@@ -98,6 +99,7 @@ store->pid=NULL;
|
||||
if (getConfig())
|
||||
{
|
||||
infoSerial<<F("PID config loaded ")<< item->itemArr->name<<endl;
|
||||
item->On(); // Turn ON pid by default
|
||||
store->driverStatus = CST_INITIALIZED;
|
||||
return 1;
|
||||
}
|
||||
@@ -141,7 +143,7 @@ if (store && store->pid && (Status() == CST_INITIALIZED) && item && (item->getCm
|
||||
//if (abs(store->output-store-prevOut)>OUTPUT_TRESHOLD)
|
||||
{
|
||||
aJsonObject * oCmd = aJson.getArrayItem(item->itemArg, 1);
|
||||
itemCmd value((float) (store->output * (100./255.)));
|
||||
itemCmd value((float) (store->output));// * (100./255.)));
|
||||
executeCommand(oCmd,-1,value);
|
||||
}
|
||||
|
||||
@@ -183,7 +185,7 @@ return 1;
|
||||
|
||||
case S_NOTFOUND:
|
||||
case S_SET:
|
||||
case S_ESET:
|
||||
//case S_ESET:
|
||||
// Setpoint for PID
|
||||
if (!cmd.isValue()) return 0;
|
||||
store->setpoint=cmd.getFloat();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <abstractout.h>
|
||||
#include <item.h>
|
||||
#include <PID_v1.h>
|
||||
#include "itemCmd.h"
|
||||
|
||||
#define OUTPUT_TRESHOLD 1
|
||||
|
||||
@@ -29,6 +30,7 @@ public:
|
||||
int Status() override;
|
||||
int isActive() override;
|
||||
int getChanType() override;
|
||||
int getDefaultStorageType(){return ST_FLOAT;};
|
||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ void analogWrite(int pin, int val)
|
||||
|
||||
int out_pwm::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
debugSerial<<F("PWM-Out Init")<<endl;
|
||||
if (!item || iaddr) return 0;
|
||||
|
||||
@@ -142,7 +143,7 @@ switch (cmd.getCmd()){
|
||||
storageType=ST_RGBW;
|
||||
break;
|
||||
default:
|
||||
storageType=ST_PERCENTS;
|
||||
storageType=ST_PERCENTS255;
|
||||
}
|
||||
|
||||
itemCmd st(storageType,CMD_VOID);
|
||||
|
||||
@@ -43,6 +43,7 @@ void out_SPILed::getConfig()
|
||||
|
||||
int out_SPILed::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
getConfig();
|
||||
Serial.println("SPI-LED Init");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user