mirror of https://github.com/arendst/Tasmota.git
Merge branch 'development' of https://github.com/arendst/Sonoff-Tasmota into serial_115200_2
This commit is contained in:
commit
41d6dd2683
|
@ -0,0 +1,19 @@
|
|||
Stepper Library for Tasmota
|
||||
|
||||
This Class allows you to control bipolar stepper motors. To use it you will need an A4988-StepperDriverCircuit, connected at least with 2 GPIO's (direction and step) and of cause a stepper motor.
|
||||
|
||||
== License ==
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
@ -0,0 +1,24 @@
|
|||
#######################################
|
||||
# Syntax Coloring Map For Test
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
A4988_Stepper KEYWORD1 A4988_Stepper
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
doMove KEYWORD2
|
||||
doRotate KEYWORD2
|
||||
setRPM KEYWORD2
|
||||
setSPR KEYWORD2
|
||||
setMIS KEYWORD2
|
||||
version KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
|
@ -0,0 +1,9 @@
|
|||
name=A4988_Stepper
|
||||
version=0.0.1
|
||||
author=Tim Leuschner
|
||||
maintainer=Tim Leuschner <tim@feuer.land>
|
||||
sentence=Allows Tasmota to control stepper motors, connected to A4988-StepperDriverCircuit.
|
||||
paragraph=This library allows you to control bipolar stepper motors, controlled by A4988-stepperDriverCircuit.
|
||||
category=Device Control
|
||||
url=
|
||||
architectures=*
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
This library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Drives a bipolar motor, controlled by A4988 stepper driver circuit
|
||||
*/
|
||||
//
|
||||
#include "Arduino.h"
|
||||
#include "A4988_Stepper.h"
|
||||
A4988_Stepper::A4988_Stepper( int m_spr
|
||||
, int m_rpm
|
||||
, short m_mis
|
||||
, short m_dir_pin
|
||||
, short m_stp_pin
|
||||
, short m_ena_pin
|
||||
, short m_ms1_pin
|
||||
, short m_ms2_pin
|
||||
, short m_ms3_pin ) {
|
||||
last_time = 0; // time stamp in us of the last step taken
|
||||
motor_SPR = m_spr; // StepsPerRevolution
|
||||
motor_RPM = m_rpm; // RoundsPerMinute
|
||||
motor_MIS = m_mis; // Microsteps w/o effect if MS1-MS3 not connected - then full steps anyway
|
||||
motor_dir_pin = m_dir_pin;
|
||||
motor_stp_pin = m_stp_pin;
|
||||
motor_ena_pin = m_ena_pin;
|
||||
motor_ms1_pin = m_ms1_pin;
|
||||
motor_ms2_pin = m_ms2_pin;
|
||||
motor_ms3_pin = m_ms3_pin;
|
||||
|
||||
adjustDelay();
|
||||
adjustPins();
|
||||
adjustMicrosteps();
|
||||
}
|
||||
|
||||
void A4988_Stepper::adjustPins(void) {
|
||||
// setup the pins on the microcontroller:
|
||||
pinMode(motor_dir_pin, OUTPUT);
|
||||
pinMode(motor_stp_pin, OUTPUT);
|
||||
if (motor_ena_pin <99) {
|
||||
pinMode(motor_ena_pin, OUTPUT);
|
||||
digitalWrite(motor_ena_pin, HIGH);
|
||||
}
|
||||
|
||||
if ((motor_ms1_pin<99)&&(motor_ms2_pin<99)&&(motor_ms3_pin<99)) {
|
||||
pinMode(motor_ms1_pin, OUTPUT);
|
||||
pinMode(motor_ms2_pin, OUTPUT);
|
||||
pinMode(motor_ms3_pin, OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void A4988_Stepper::adjustMicrosteps() {
|
||||
if ((motor_ms1_pin<99)&&(motor_ms2_pin<99)&&(motor_ms3_pin<99)) {
|
||||
unsigned short i = 0;
|
||||
while (i < 5){
|
||||
if (motor_MIS & (1<<i)){
|
||||
unsigned short mask = MIS_TABLE[i];
|
||||
digitalWrite(motor_ms1_pin, 1&mask?HIGH:LOW);
|
||||
digitalWrite(motor_ms2_pin, 2&mask?HIGH:LOW);
|
||||
digitalWrite(motor_ms3_pin, 4&mask?HIGH:LOW);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
motor_MIS = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void A4988_Stepper::adjustDelay(void) {
|
||||
motor_delay = 60L * 1000L * 1000L / motor_SPR / motor_RPM / motor_MIS/2;
|
||||
}
|
||||
|
||||
void A4988_Stepper::setMIS(short oneToSixteen) {
|
||||
motor_MIS = oneToSixteen;
|
||||
adjustMicrosteps();
|
||||
adjustDelay();
|
||||
}
|
||||
|
||||
short A4988_Stepper::getMIS(void) {
|
||||
return motor_MIS;
|
||||
}
|
||||
|
||||
void A4988_Stepper::setRPM(int howManyRounds) {
|
||||
motor_RPM = howManyRounds;
|
||||
adjustDelay();
|
||||
}
|
||||
|
||||
int A4988_Stepper::getRPM(void) {
|
||||
return motor_RPM;
|
||||
}
|
||||
|
||||
void A4988_Stepper::setSPR(int howManySteps){
|
||||
motor_SPR = howManySteps;
|
||||
adjustDelay();
|
||||
}
|
||||
|
||||
int A4988_Stepper::getSPR(void) {
|
||||
return motor_SPR;
|
||||
}
|
||||
|
||||
void A4988_Stepper::enable(){
|
||||
if (motor_ena_pin < 99) {digitalWrite(motor_ena_pin, LOW);}
|
||||
}
|
||||
|
||||
void A4988_Stepper::disable(){
|
||||
if (motor_ena_pin < 99) {digitalWrite(motor_ena_pin, HIGH);}
|
||||
}
|
||||
|
||||
void A4988_Stepper::doMove(long howManySteps)
|
||||
{
|
||||
long steps_togo = abs(howManySteps); // how many steps to take
|
||||
bool lastStepWasHigh = false;
|
||||
digitalWrite(motor_dir_pin, howManySteps>0?LOW:HIGH);
|
||||
enable();
|
||||
while (steps_togo > 0) {
|
||||
delay(0); // don't get watchdoged in loop
|
||||
unsigned long now = micros();
|
||||
// move if delay has passed:
|
||||
if (now - last_time >= motor_delay) {
|
||||
digitalWrite(motor_stp_pin, lastStepWasHigh?LOW:HIGH);
|
||||
lastStepWasHigh = !lastStepWasHigh;
|
||||
// remeber step-time
|
||||
last_time = now;
|
||||
if (!lastStepWasHigh) steps_togo--; // same here - only HIGH moves, if pulled LOW step is completed...
|
||||
}
|
||||
}
|
||||
disable();
|
||||
}
|
||||
|
||||
void A4988_Stepper::doRotate(long howManyDegrees)
|
||||
{ long lSteps = 0;
|
||||
lSteps = motor_SPR*motor_MIS*howManyDegrees/360;
|
||||
doMove(lSteps);
|
||||
}
|
||||
|
||||
void A4988_Stepper::doTurn(float howManyTimes)
|
||||
{ long lSteps = 0;
|
||||
lSteps = howManyTimes*motor_SPR;
|
||||
doMove(lSteps);
|
||||
}
|
||||
|
||||
int A4988_Stepper::version(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
This library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef A4988_Stepper_h
|
||||
#define A4988_Stepper_h
|
||||
|
||||
class A4988_Stepper {
|
||||
public:
|
||||
// constructor:
|
||||
A4988_Stepper( int motor_spr
|
||||
, int motor_rpm
|
||||
, short motor_mis
|
||||
, short motor_dir_pin
|
||||
, short motor_stp_pin
|
||||
, short motor_ena_pin
|
||||
, short motor_ms1_pin
|
||||
, short motor_ms2_pin
|
||||
, short motor_ms3_pin
|
||||
);
|
||||
|
||||
void setRPM (int whatRPM );
|
||||
int getRPM (void );
|
||||
|
||||
void setMIS (short OneToSixteen);
|
||||
short getMIS (void );
|
||||
|
||||
void setSPR (int howMany );
|
||||
int getSPR (void );
|
||||
|
||||
void doMove (long steps_to_move);
|
||||
void doRotate(long degrs_to_turn);
|
||||
void doTurn (float howManyTimes);
|
||||
|
||||
void enable (void );
|
||||
void disable (void );
|
||||
|
||||
int version (void );
|
||||
const unsigned short MIS_TABLE[5] = {0b000,0b001,0b010,0b011,0b111};
|
||||
|
||||
private:
|
||||
void adjustDelay(void);
|
||||
void adjustPins(void);
|
||||
void adjustMicrosteps(void);
|
||||
unsigned long motor_delay; // delay between steps, in ms
|
||||
int motor_SPR; // Steps Per Revolution
|
||||
int motor_RPM; // Rounds Per Minute
|
||||
short motor_MIS; // Micro Steps
|
||||
|
||||
// motor pins:
|
||||
short motor_dir_pin;
|
||||
short motor_stp_pin;
|
||||
short motor_ena_pin;
|
||||
short motor_ms1_pin;
|
||||
short motor_ms2_pin;
|
||||
short motor_ms3_pin;
|
||||
|
||||
unsigned long last_time; // timestamp of last pincycle of last step
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "TasmotaSerial",
|
||||
"version": "2.3.3",
|
||||
"version": "2.3.4",
|
||||
"keywords": [
|
||||
"serial", "io", "TasmotaSerial"
|
||||
],
|
|
@ -1,5 +1,5 @@
|
|||
name=TasmotaSerial
|
||||
version=2.3.3
|
||||
version=2.3.4
|
||||
author=Theo Arends
|
||||
maintainer=Theo Arends <theo@arends.com>
|
||||
sentence=Implementation of software serial with hardware serial fallback for ESP8266.
|
|
@ -456,6 +456,18 @@
|
|||
#define D_JSON_ZIGBEEZNPSENT "ZigbeeZNPSent"
|
||||
#define D_JSON_ZIGBEEZCLRECEIVED "ZigbeeZCLReceived"
|
||||
#define D_JSON_ZIGBEEZCLSENT "ZigbeeZCLSent"
|
||||
|
||||
// Commands xdrv_25_A4988_Stepper.ino
|
||||
#ifdef USE_A4988_Stepper
|
||||
#define D_CMND_MOTOR "MOTOR"
|
||||
#define D_JSON_MOTOR_MOVE "doMove"
|
||||
#define D_JSON_MOTOR_ROTATE "doRotate"
|
||||
#define D_JSON_MOTOR_TURN "doTurn"
|
||||
#define D_JSON_MOTOR_SPR "setSPR"
|
||||
#define D_JSON_MOTOR_RPM "setRPM"
|
||||
#define D_JSON_MOTOR_MIS "setMIS"
|
||||
#endif
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
#define D_ASTERISK_PWD "****"
|
||||
|
|
|
@ -597,6 +597,13 @@
|
|||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
#define D_UNIT_CENTIMETER "cm"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "А"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "А"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "安"
|
||||
|
|
|
@ -596,6 +596,12 @@
|
|||
#define D_SENSOR_IBEACON_RX "iBeacon RX"
|
||||
#define D_SENSOR_RDM6300_RX "RDM6300 RX"
|
||||
#define D_SENSOR_CC1101_CS "CC1101 CS"
|
||||
#define D_SENSOR_A4988_DIR "A4988 DIR"
|
||||
#define D_SENSOR_A4988_STP "A4988 STP"
|
||||
#define D_SENSOR_A4988_ENA "A4988 ENA"
|
||||
#define D_SENSOR_A4988_MS1 "A4988 MS1"
|
||||
#define D_SENSOR_A4988_MS2 "A4988 MS2"
|
||||
#define D_SENSOR_A4988_MS3 "A4988 MS3"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "安"
|
||||
|
|
|
@ -528,6 +528,7 @@
|
|||
#define USE_SM16716 // Add support for SM16716 RGB LED controller (+0k7 code)
|
||||
|
||||
//#define USE_HRE // Add support for Badger HR-E Water Meter (+1k4 code)
|
||||
//#define USE_A4988_Stepper // Add support for A4988 stepper-motor-driver-circuit (+10k5 code)
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Debug features
|
||||
|
|
|
@ -258,6 +258,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
|
|||
#undef USE_RF_SENSOR // Disable support for RF sensor receiver (434MHz or 868MHz) (+0k8 code)
|
||||
#undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code)
|
||||
#undef USE_HRE // Disable support for Badger HR-E Water Meter (+1k4 code)
|
||||
#undef USE_A4988_Stepper // Disable support for A4988_Stepper
|
||||
#undef DEBUG_THEO // Disable debug code
|
||||
#undef USE_DEBUG_DRIVER // Disable debug code
|
||||
#endif // FIRMWARE_CLASSIC
|
||||
|
@ -387,6 +388,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
|
|||
#undef USE_RF_SENSOR // Disable support for RF sensor receiver (434MHz or 868MHz) (+0k8 code)
|
||||
#undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code)
|
||||
#undef USE_HRE // Disable support for Badger HR-E Water Meter (+1k4 code)
|
||||
#undef USE_A4988_Stepper // Disable support for A4988_Stepper
|
||||
#undef DEBUG_THEO // Disable debug code
|
||||
#undef USE_DEBUG_DRIVER // Disable debug code
|
||||
|
||||
|
@ -481,6 +483,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
|
|||
#undef USE_RF_SENSOR // Disable support for RF sensor receiver (434MHz or 868MHz) (+0k8 code)
|
||||
#undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code)
|
||||
#undef USE_HRE // Disable support for Badger HR-E Water Meter (+1k4 code)
|
||||
#undef USE_A4988_Stepper // Disable support for A4988_Stepper
|
||||
#undef DEBUG_THEO // Disable debug code
|
||||
#undef USE_DEBUG_DRIVER // Disable debug code
|
||||
#endif // FIRMWARE_BASIC
|
||||
|
@ -562,6 +565,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
|
|||
#undef USE_RF_SENSOR // Disable support for RF sensor receiver (434MHz or 868MHz) (+0k8 code)
|
||||
#undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code)
|
||||
#undef USE_HRE // Disable support for Badger HR-E Water Meter (+1k4 code)
|
||||
#undef USE_A4988_Stepper // Disable support for A4988_Stepper
|
||||
#undef DEBUG_THEO // Disable debug code
|
||||
#undef USE_DEBUG_DRIVER // Disable debug code
|
||||
#endif // FIRMWARE_MINIMAL
|
||||
|
|
|
@ -194,6 +194,12 @@ enum UserSelectablePins {
|
|||
GPIO_RDM6300_RX, // RDM6300 RX
|
||||
GPIO_IBEACON_TX, // HM17 IBEACON TX
|
||||
GPIO_IBEACON_RX, // HM17 IBEACON RX
|
||||
GPIO_A4988_DIR, // A4988 direction pin
|
||||
GPIO_A4988_STP, // A4988 step pin
|
||||
GPIO_A4988_ENA, // A4988 enabled pin
|
||||
GPIO_A4988_MS1, // A4988 microstep pin1
|
||||
GPIO_A4988_MS2, // A4988 microstep pin2
|
||||
GPIO_A4988_MS3, // A4988 microstep pin3
|
||||
GPIO_SENSOR_END };
|
||||
|
||||
// Programmer selectable GPIO functionality
|
||||
|
@ -267,6 +273,7 @@ const char kSensorNames[] PROGMEM =
|
|||
D_SENSOR_ZIGBEE_TXD "|" D_SENSOR_ZIGBEE_RXD "|"
|
||||
D_SENSOR_RDM6300_RX "|"
|
||||
D_SENSOR_IBEACON_TX "|" D_SENSOR_IBEACON_RX "|"
|
||||
D_SENSOR_A4988_DIR "|" D_SENSOR_A4988_STP "|" D_SENSOR_A4988_ENA "|" D_SENSOR_A4988_MS1 "|" D_SENSOR_A4988_MS2 "|" D_SENSOR_A4988_MS3 "|"
|
||||
;
|
||||
|
||||
// User selectable ADC0 functionality
|
||||
|
@ -689,6 +696,15 @@ const uint8_t kGpioNiceList[] PROGMEM = {
|
|||
GPIO_HRE_CLOCK,
|
||||
GPIO_HRE_DATA,
|
||||
#endif
|
||||
#ifdef USE_A4988_Stepper
|
||||
GPIO_A4988_DIR, // A4988 direction pin
|
||||
GPIO_A4988_STP, // A4988 step pin
|
||||
// folowing are not mandatory
|
||||
GPIO_A4988_ENA, // A4988 enabled pin
|
||||
GPIO_A4988_MS1, // A4988 microstep pin1
|
||||
GPIO_A4988_MS2, // A4988 microstep pin2
|
||||
GPIO_A4988_MS3, // A4988 microstep pin3
|
||||
#endif
|
||||
};
|
||||
|
||||
const uint8_t kModuleNiceList[] PROGMEM = {
|
||||
|
|
|
@ -441,11 +441,12 @@ void GetFeatures(void)
|
|||
#ifdef USE_SML_M
|
||||
feature5 |= 0x00000008; // xsns_53_sml.ino
|
||||
#endif
|
||||
|
||||
#ifdef USE_INA226
|
||||
feature5 |= 0x00000010; // xsns_54_ina226.ino
|
||||
#endif
|
||||
// feature5 |= 0x00000020;
|
||||
#ifdef USE_A4988_Stepper
|
||||
feature5 |= 0x00000020; // xdrv_25_A4988.ino
|
||||
#endif
|
||||
// feature5 |= 0x00000040;
|
||||
// feature5 |= 0x00000080;
|
||||
|
||||
|
|
|
@ -696,7 +696,7 @@ void CmndMaxEnergyStart(void)
|
|||
void EnergyDrvInit(void)
|
||||
{
|
||||
energy_flg = ENERGY_NONE;
|
||||
XnrgCall(FUNC_PRE_INIT);
|
||||
XnrgCall(FUNC_PRE_INIT); // Find first energy driver
|
||||
}
|
||||
|
||||
void EnergySnsInit(void)
|
||||
|
@ -901,14 +901,14 @@ bool Xdrv03(uint8_t function)
|
|||
case FUNC_EVERY_250_MSECOND:
|
||||
XnrgCall(FUNC_EVERY_250_MSECOND);
|
||||
break;
|
||||
case FUNC_SERIAL:
|
||||
result = XnrgCall(FUNC_SERIAL);
|
||||
break;
|
||||
#ifdef USE_ENERGY_MARGIN_DETECTION
|
||||
case FUNC_SET_POWER:
|
||||
Energy.power_steady_counter = 2;
|
||||
break;
|
||||
#endif // USE_ENERGY_MARGIN_DETECTION
|
||||
case FUNC_SERIAL:
|
||||
result = XnrgCall(FUNC_SERIAL);
|
||||
break;
|
||||
case FUNC_COMMAND:
|
||||
result = DecodeCommand(kEnergyCommands, EnergyCommand);
|
||||
break;
|
||||
|
@ -923,9 +923,6 @@ bool Xsns03(uint8_t function)
|
|||
|
||||
if (energy_flg) {
|
||||
switch (function) {
|
||||
case FUNC_INIT:
|
||||
EnergySnsInit();
|
||||
break;
|
||||
case FUNC_EVERY_SECOND:
|
||||
#ifdef USE_ENERGY_MARGIN_DETECTION
|
||||
EnergyMarginCheck();
|
||||
|
@ -943,6 +940,9 @@ bool Xsns03(uint8_t function)
|
|||
case FUNC_SAVE_BEFORE_RESTART:
|
||||
EnergySaveState();
|
||||
break;
|
||||
case FUNC_INIT:
|
||||
EnergySnsInit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#ifdef USE_TUYA_MCU
|
||||
|
||||
#define XDRV_16 16
|
||||
#define XNRG_08 8
|
||||
#define XNRG_16 16 // Needs to be the last XNRG_xx
|
||||
|
||||
#ifndef TUYA_DIMMER_ID
|
||||
#define TUYA_DIMMER_ID 0
|
||||
|
@ -372,6 +372,7 @@ void TuyaPacketProcess(void)
|
|||
|
||||
}
|
||||
else if (Tuya.buffer[5] == 8) { // Long value packet
|
||||
bool tuya_energy_enabled = (XNRG_16 == energy_flg);
|
||||
if (fnId == TUYA_MCU_FUNC_DIMMER) {
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), Tuya.buffer[13]);
|
||||
Tuya.new_dim = changeUIntScale((uint8_t) Tuya.buffer[13], 0, Settings.param[P_TUYA_DIMMER_MAX], 0, 100);
|
||||
|
@ -384,13 +385,13 @@ void TuyaPacketProcess(void)
|
|||
}
|
||||
|
||||
#ifdef USE_ENERGY_SENSOR
|
||||
else if (fnId == TUYA_MCU_FUNC_VOLTAGE) {
|
||||
else if (tuya_energy_enabled && fnId == TUYA_MCU_FUNC_VOLTAGE) {
|
||||
Energy.voltage = (float)(Tuya.buffer[12] << 8 | Tuya.buffer[13]) / 10;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Rx ID=%d Voltage=%d"), Tuya.buffer[6], (Tuya.buffer[12] << 8 | Tuya.buffer[13]));
|
||||
} else if (fnId == TUYA_MCU_FUNC_CURRENT) {
|
||||
} else if (tuya_energy_enabled && fnId == TUYA_MCU_FUNC_CURRENT) {
|
||||
Energy.current = (float)(Tuya.buffer[12] << 8 | Tuya.buffer[13]) / 1000;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Rx ID=%d Current=%d"), Tuya.buffer[6], (Tuya.buffer[12] << 8 | Tuya.buffer[13]));
|
||||
} else if (fnId == TUYA_MCU_FUNC_POWER) {
|
||||
} else if (tuya_energy_enabled && fnId == TUYA_MCU_FUNC_POWER) {
|
||||
Energy.active_power = (float)(Tuya.buffer[12] << 8 | Tuya.buffer[13]) / 10;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Rx ID=%d Active_Power=%d"), Tuya.buffer[6], (Tuya.buffer[12] << 8 | Tuya.buffer[13]));
|
||||
|
||||
|
@ -601,22 +602,20 @@ void TuyaSetWifiLed(void)
|
|||
* Energy Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
int Xnrg08(uint8_t function)
|
||||
bool Xnrg16(uint8_t function)
|
||||
{
|
||||
int result = 0;
|
||||
bool result = false;
|
||||
|
||||
if (TUYA_DIMMER == my_module_type) {
|
||||
if (FUNC_PRE_INIT == function) {
|
||||
if (!energy_flg) {
|
||||
if (TuyaGetDpId(TUYA_MCU_FUNC_POWER) != 0) {
|
||||
if (TuyaGetDpId(TUYA_MCU_FUNC_CURRENT) == 0) {
|
||||
Energy.current_available = false;
|
||||
}
|
||||
if (TuyaGetDpId(TUYA_MCU_FUNC_VOLTAGE) == 0) {
|
||||
Energy.voltage_available = false;
|
||||
}
|
||||
energy_flg = XNRG_08;
|
||||
if (TuyaGetDpId(TUYA_MCU_FUNC_POWER) != 0) {
|
||||
if (TuyaGetDpId(TUYA_MCU_FUNC_CURRENT) == 0) {
|
||||
Energy.current_available = false;
|
||||
}
|
||||
if (TuyaGetDpId(TUYA_MCU_FUNC_VOLTAGE) == 0) {
|
||||
Energy.voltage_available = false;
|
||||
}
|
||||
energy_flg = XNRG_16;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,172 @@
|
|||
|
||||
/*
|
||||
xdrv_25_A4988_Stepper.ino - A4988-StepMotorDriverCircuit- support for Sonoff-Tasmota
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_A4988_Stepper
|
||||
#include <A4988_Stepper.h>
|
||||
#define XDRV_25 25
|
||||
|
||||
enum A4988Errors { A4988_NO_ERROR, A4988_NO_JSON_COMMAND, A4988_INVALID_JSON, A4988_MOVE, A4988_ROTATE, A4988_TURN};
|
||||
|
||||
short A4988_dir_pin = pin[GPIO_MAX];
|
||||
short A4988_stp_pin = pin[GPIO_MAX];
|
||||
short A4988_ms1_pin = pin[GPIO_MAX];
|
||||
short A4988_ms2_pin = pin[GPIO_MAX];
|
||||
short A4988_ms3_pin = pin[GPIO_MAX];
|
||||
short A4988_ena_pin = pin[GPIO_MAX];
|
||||
int A4988_spr = 0;
|
||||
float A4988_rpm = 0;
|
||||
short A4988_mis = 0;
|
||||
|
||||
A4988_Stepper* myA4988 = nullptr;
|
||||
|
||||
void A4988Init(void)
|
||||
{
|
||||
A4988_dir_pin = pin[GPIO_A4988_DIR];
|
||||
A4988_stp_pin = pin[GPIO_A4988_STP];
|
||||
A4988_ena_pin = pin[GPIO_A4988_ENA];
|
||||
A4988_ms1_pin = pin[GPIO_A4988_MS1];
|
||||
A4988_ms2_pin = pin[GPIO_A4988_MS2];
|
||||
A4988_ms3_pin = pin[GPIO_A4988_MS3];
|
||||
A4988_spr = 200;
|
||||
A4988_rpm = 30;
|
||||
A4988_mis = 1;
|
||||
|
||||
myA4988 = new A4988_Stepper( A4988_spr
|
||||
, A4988_rpm
|
||||
, A4988_mis
|
||||
, A4988_dir_pin
|
||||
, A4988_stp_pin
|
||||
, A4988_ena_pin
|
||||
, A4988_ms1_pin
|
||||
, A4988_ms2_pin
|
||||
, A4988_ms3_pin );
|
||||
}
|
||||
|
||||
const char kA4988Commands[] PROGMEM = "|"
|
||||
"MOTOR";
|
||||
|
||||
void (* const A4988Command[])(void) PROGMEM = { &CmndMOTOR};
|
||||
|
||||
uint32_t MOTORCmndJson(void)
|
||||
{
|
||||
// MOTOR {"doMove":200}
|
||||
// MOTOR {"doRotate":360}
|
||||
// MOTOR {"doTurn":1.0}
|
||||
uint32_t returnValue =A4988_NO_JSON_COMMAND;
|
||||
|
||||
char parm_uc[12];
|
||||
char dataBufUc[XdrvMailbox.data_len];
|
||||
UpperCase(dataBufUc, XdrvMailbox.data);
|
||||
RemoveSpace(dataBufUc);
|
||||
if (strlen(dataBufUc) < 8) { returnValue =A4988_INVALID_JSON; }
|
||||
|
||||
DynamicJsonBuffer jsonBuf;
|
||||
JsonObject &json = jsonBuf.parseObject(dataBufUc);
|
||||
if (json.success()) {
|
||||
UpperCase_P(parm_uc, PSTR(D_JSON_MOTOR_SPR));
|
||||
if (json.containsKey(parm_uc)){
|
||||
int howManySteps =strtoul(json[parm_uc],nullptr,10);
|
||||
myA4988->setSPR(howManySteps);
|
||||
returnValue = A4988_NO_ERROR;
|
||||
}
|
||||
UpperCase_P(parm_uc, PSTR(D_JSON_MOTOR_RPM));
|
||||
if (json.containsKey(parm_uc)){
|
||||
int howManyRounds =strtoul(json[parm_uc],nullptr,10);
|
||||
myA4988->setRPM(howManyRounds);
|
||||
returnValue = A4988_NO_ERROR;
|
||||
}
|
||||
UpperCase_P(parm_uc, PSTR(D_JSON_MOTOR_MIS));
|
||||
if (json.containsKey(parm_uc)){
|
||||
short oneToSixteen =strtoul(json[parm_uc],nullptr,10);
|
||||
myA4988->setMIS(oneToSixteen);
|
||||
returnValue = A4988_NO_ERROR;
|
||||
}
|
||||
UpperCase_P(parm_uc, PSTR(D_JSON_MOTOR_MOVE));
|
||||
if (json.containsKey(parm_uc)){
|
||||
long stepsPlease = strtoul(json[parm_uc],nullptr,10);
|
||||
myA4988->doMove(stepsPlease);
|
||||
returnValue = A4988_MOVE;
|
||||
}
|
||||
UpperCase_P(parm_uc, PSTR(D_JSON_MOTOR_ROTATE));
|
||||
if (json.containsKey(parm_uc)){
|
||||
long degrsPlease = strtoul(json[parm_uc],nullptr,10);
|
||||
myA4988->doRotate(degrsPlease);
|
||||
returnValue = A4988_ROTATE;
|
||||
}
|
||||
UpperCase_P(parm_uc, PSTR(D_JSON_MOTOR_TURN));
|
||||
if (json.containsKey(parm_uc)){
|
||||
float turnsPlease = strtod(json[parm_uc],nullptr);
|
||||
myA4988->doTurn(turnsPlease);
|
||||
returnValue = A4988_TURN;
|
||||
}
|
||||
} else returnValue =A4988_INVALID_JSON;
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
void CmndMOTOR(void){
|
||||
uint32_t error;
|
||||
if (XdrvMailbox.data_len) {
|
||||
if (strstr(XdrvMailbox.data, "}") == nullptr) {
|
||||
error = A4988_NO_JSON_COMMAND;
|
||||
} else {
|
||||
error = MOTORCmndJson();
|
||||
}
|
||||
}
|
||||
A4988CmndResponse(error);
|
||||
}
|
||||
|
||||
void A4988CmndResponse(uint32_t error){
|
||||
switch (error) {
|
||||
case A4988_NO_JSON_COMMAND:
|
||||
ResponseCmndChar(PSTR("No command!"));
|
||||
break;
|
||||
case A4988_MOVE:
|
||||
ResponseCmndChar(PSTR("Stepping!"));
|
||||
break;
|
||||
case A4988_ROTATE:
|
||||
ResponseCmndChar(PSTR("Rotating!"));
|
||||
break;
|
||||
case A4988_TURN:
|
||||
ResponseCmndChar(PSTR("Turning!"));
|
||||
break;
|
||||
default: // A4988_NO_ERROR
|
||||
ResponseCmndDone();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Interface
|
||||
\*********************************************************************************************/
|
||||
bool Xdrv25(uint8_t function)
|
||||
{
|
||||
bool result = false;
|
||||
if ((pin[GPIO_A4988_DIR] < 99) && (pin[GPIO_A4988_STP] < 99)) {
|
||||
switch (function) {
|
||||
case FUNC_INIT:
|
||||
A4988Init();
|
||||
break;
|
||||
case FUNC_COMMAND:
|
||||
result = DecodeCommand(kA4988Commands, A4988Command);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -249,34 +249,32 @@ void HlwSnsInit(void)
|
|||
|
||||
void HlwDrvInit(void)
|
||||
{
|
||||
if (!energy_flg) {
|
||||
Hlw.model_type = 0; // HLW8012
|
||||
if (pin[GPIO_HJL_CF] < 99) {
|
||||
pin[GPIO_HLW_CF] = pin[GPIO_HJL_CF];
|
||||
pin[GPIO_HJL_CF] = 99;
|
||||
Hlw.model_type = 1; // HJL-01/BL0937
|
||||
Hlw.model_type = 0; // HLW8012
|
||||
if (pin[GPIO_HJL_CF] < 99) {
|
||||
pin[GPIO_HLW_CF] = pin[GPIO_HJL_CF];
|
||||
pin[GPIO_HJL_CF] = 99;
|
||||
Hlw.model_type = 1; // HJL-01/BL0937
|
||||
}
|
||||
|
||||
if (pin[GPIO_HLW_CF] < 99) { // HLW8012 or HJL-01 based device Power monitor
|
||||
|
||||
Hlw.ui_flag = true; // Voltage on high
|
||||
if (pin[GPIO_NRG_SEL_INV] < 99) {
|
||||
pin[GPIO_NRG_SEL] = pin[GPIO_NRG_SEL_INV];
|
||||
pin[GPIO_NRG_SEL_INV] = 99;
|
||||
Hlw.ui_flag = false; // Voltage on low
|
||||
}
|
||||
|
||||
if (pin[GPIO_HLW_CF] < 99) { // HLW8012 or HJL-01 based device Power monitor
|
||||
|
||||
Hlw.ui_flag = true; // Voltage on high
|
||||
if (pin[GPIO_NRG_SEL_INV] < 99) {
|
||||
pin[GPIO_NRG_SEL] = pin[GPIO_NRG_SEL_INV];
|
||||
pin[GPIO_NRG_SEL_INV] = 99;
|
||||
Hlw.ui_flag = false; // Voltage on low
|
||||
if (pin[GPIO_NRG_CF1] < 99) { // Voltage and/or Current monitor
|
||||
if (99 == pin[GPIO_NRG_SEL]) { // Voltage and/or Current selector
|
||||
Energy.current_available = false; // Assume Voltage
|
||||
}
|
||||
|
||||
if (pin[GPIO_NRG_CF1] < 99) { // Voltage and/or Current monitor
|
||||
if (99 == pin[GPIO_NRG_SEL]) { // Voltage and/or Current selector
|
||||
Energy.current_available = false; // Assume Voltage
|
||||
}
|
||||
} else {
|
||||
Energy.current_available = false;
|
||||
Energy.voltage_available = false;
|
||||
}
|
||||
|
||||
energy_flg = XNRG_01;
|
||||
} else {
|
||||
Energy.current_available = false;
|
||||
Energy.voltage_available = false;
|
||||
}
|
||||
|
||||
energy_flg = XNRG_01;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -311,28 +309,26 @@ bool HlwCommand(void)
|
|||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
int Xnrg01(uint8_t function)
|
||||
bool Xnrg01(uint8_t function)
|
||||
{
|
||||
int result = 0;
|
||||
bool result = false;
|
||||
|
||||
if (FUNC_PRE_INIT == function) {
|
||||
HlwDrvInit();
|
||||
}
|
||||
else if (XNRG_01 == energy_flg) {
|
||||
switch (function) {
|
||||
case FUNC_INIT:
|
||||
HlwSnsInit();
|
||||
break;
|
||||
case FUNC_ENERGY_EVERY_SECOND:
|
||||
HlwEverySecond();
|
||||
break;
|
||||
case FUNC_EVERY_200_MSECOND:
|
||||
HlwEvery200ms();
|
||||
break;
|
||||
case FUNC_COMMAND:
|
||||
result = HlwCommand();
|
||||
break;
|
||||
}
|
||||
switch (function) {
|
||||
case FUNC_EVERY_200_MSECOND:
|
||||
HlwEvery200ms();
|
||||
break;
|
||||
case FUNC_ENERGY_EVERY_SECOND:
|
||||
HlwEverySecond();
|
||||
break;
|
||||
case FUNC_COMMAND:
|
||||
result = HlwCommand();
|
||||
break;
|
||||
case FUNC_INIT:
|
||||
HlwSnsInit();
|
||||
break;
|
||||
case FUNC_PRE_INIT:
|
||||
HlwDrvInit();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ bool CseSerialInput(void)
|
|||
Energy.data_valid = 0;
|
||||
CseReceived();
|
||||
Cse.received = false;
|
||||
return 1;
|
||||
return true;
|
||||
} else {
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("CSE: " D_CHECKSUM_FAILURE));
|
||||
do { // Sync buffer with data (issue #1907 and #3425)
|
||||
|
@ -167,7 +167,7 @@ bool CseSerialInput(void)
|
|||
serial_in_buffer[serial_in_byte_counter++] = serial_in_byte;
|
||||
}
|
||||
serial_in_byte = 0; // Discard
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
@ -208,16 +208,14 @@ void CseEverySecond(void)
|
|||
|
||||
void CseDrvInit(void)
|
||||
{
|
||||
if (!energy_flg) {
|
||||
if ((3 == pin[GPIO_CSE7766_RX]) && (1 == pin[GPIO_CSE7766_TX])) { // As it uses 8E1 currently only hardware serial is supported
|
||||
baudrate = 4800;
|
||||
serial_config = SERIAL_8E1;
|
||||
if (0 == Settings.param[P_CSE7766_INVALID_POWER]) {
|
||||
Settings.param[P_CSE7766_INVALID_POWER] = CSE_MAX_INVALID_POWER; // SetOption39 1..255
|
||||
}
|
||||
Cse.power_invalid = Settings.param[P_CSE7766_INVALID_POWER];
|
||||
energy_flg = XNRG_02;
|
||||
if ((3 == pin[GPIO_CSE7766_RX]) && (1 == pin[GPIO_CSE7766_TX])) { // As it uses 8E1 currently only hardware serial is supported
|
||||
baudrate = 4800;
|
||||
serial_config = SERIAL_8E1;
|
||||
if (0 == Settings.param[P_CSE7766_INVALID_POWER]) {
|
||||
Settings.param[P_CSE7766_INVALID_POWER] = CSE_MAX_INVALID_POWER; // SetOption39 1..255
|
||||
}
|
||||
Cse.power_invalid = Settings.param[P_CSE7766_INVALID_POWER];
|
||||
energy_flg = XNRG_02;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,25 +247,23 @@ bool CseCommand(void)
|
|||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
int Xnrg02(uint8_t function)
|
||||
bool Xnrg02(uint8_t function)
|
||||
{
|
||||
int result = 0;
|
||||
bool result = false;
|
||||
|
||||
if (FUNC_PRE_INIT == function) {
|
||||
CseDrvInit();
|
||||
}
|
||||
else if (XNRG_02 == energy_flg) {
|
||||
switch (function) {
|
||||
case FUNC_ENERGY_EVERY_SECOND:
|
||||
CseEverySecond();
|
||||
break;
|
||||
case FUNC_COMMAND:
|
||||
result = CseCommand();
|
||||
break;
|
||||
case FUNC_SERIAL:
|
||||
result = CseSerialInput();
|
||||
break;
|
||||
}
|
||||
switch (function) {
|
||||
case FUNC_SERIAL:
|
||||
result = CseSerialInput();
|
||||
break;
|
||||
case FUNC_ENERGY_EVERY_SECOND:
|
||||
CseEverySecond();
|
||||
break;
|
||||
case FUNC_COMMAND:
|
||||
result = CseCommand();
|
||||
break;
|
||||
case FUNC_PRE_INIT:
|
||||
CseDrvInit();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -211,10 +211,8 @@ void PzemSnsInit(void)
|
|||
|
||||
void PzemDrvInit(void)
|
||||
{
|
||||
if (!energy_flg) {
|
||||
if ((pin[GPIO_PZEM004_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) { // Any device with a Pzem004T
|
||||
energy_flg = XNRG_03;
|
||||
}
|
||||
if ((pin[GPIO_PZEM004_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) { // Any device with a Pzem004T
|
||||
energy_flg = XNRG_03;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,22 +220,20 @@ void PzemDrvInit(void)
|
|||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
int Xnrg03(uint8_t function)
|
||||
bool Xnrg03(uint8_t function)
|
||||
{
|
||||
int result = 0;
|
||||
bool result = false;
|
||||
|
||||
if (FUNC_PRE_INIT == function) {
|
||||
PzemDrvInit();
|
||||
}
|
||||
else if (XNRG_03 == energy_flg) {
|
||||
switch (function) {
|
||||
case FUNC_INIT:
|
||||
PzemSnsInit();
|
||||
break;
|
||||
case FUNC_EVERY_200_MSECOND:
|
||||
if (PzemSerial) { PzemEvery200ms(); }
|
||||
break;
|
||||
}
|
||||
switch (function) {
|
||||
case FUNC_EVERY_200_MSECOND:
|
||||
if (PzemSerial) { PzemEvery200ms(); }
|
||||
break;
|
||||
case FUNC_INIT:
|
||||
PzemSnsInit();
|
||||
break;
|
||||
case FUNC_PRE_INIT:
|
||||
PzemDrvInit();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -583,17 +583,15 @@ void McpSnsInit(void)
|
|||
|
||||
void McpDrvInit(void)
|
||||
{
|
||||
if (!energy_flg) {
|
||||
if ((pin[GPIO_MCP39F5_RX] < 99) && (pin[GPIO_MCP39F5_TX] < 99)) {
|
||||
if (pin[GPIO_MCP39F5_RST] < 99) {
|
||||
pinMode(pin[GPIO_MCP39F5_RST], OUTPUT);
|
||||
digitalWrite(pin[GPIO_MCP39F5_RST], 0); // MCP disable - Reset Delta Sigma ADC's
|
||||
}
|
||||
mcp_calibrate = 0;
|
||||
mcp_timeout = 2; // Initial wait
|
||||
mcp_init = 2; // Initial setup steps
|
||||
energy_flg = XNRG_04;
|
||||
if ((pin[GPIO_MCP39F5_RX] < 99) && (pin[GPIO_MCP39F5_TX] < 99)) {
|
||||
if (pin[GPIO_MCP39F5_RST] < 99) {
|
||||
pinMode(pin[GPIO_MCP39F5_RST], OUTPUT);
|
||||
digitalWrite(pin[GPIO_MCP39F5_RST], 0); // MCP disable - Reset Delta Sigma ADC's
|
||||
}
|
||||
mcp_calibrate = 0;
|
||||
mcp_timeout = 2; // Initial wait
|
||||
mcp_init = 2; // Initial setup steps
|
||||
energy_flg = XNRG_04;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -651,28 +649,26 @@ bool McpCommand(void)
|
|||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
int Xnrg04(uint8_t function)
|
||||
bool Xnrg04(uint8_t function)
|
||||
{
|
||||
int result = 0;
|
||||
bool result = false;
|
||||
|
||||
if (FUNC_PRE_INIT == function) {
|
||||
McpDrvInit();
|
||||
}
|
||||
else if (XNRG_04 == energy_flg) {
|
||||
switch (function) {
|
||||
case FUNC_LOOP:
|
||||
if (McpSerial) { McpSerialInput(); }
|
||||
break;
|
||||
case FUNC_INIT:
|
||||
McpSnsInit();
|
||||
break;
|
||||
case FUNC_ENERGY_EVERY_SECOND:
|
||||
if (McpSerial) { McpEverySecond(); }
|
||||
break;
|
||||
case FUNC_COMMAND:
|
||||
result = McpCommand();
|
||||
break;
|
||||
}
|
||||
switch (function) {
|
||||
case FUNC_LOOP:
|
||||
if (McpSerial) { McpSerialInput(); }
|
||||
break;
|
||||
case FUNC_ENERGY_EVERY_SECOND:
|
||||
if (McpSerial) { McpEverySecond(); }
|
||||
break;
|
||||
case FUNC_COMMAND:
|
||||
result = McpCommand();
|
||||
break;
|
||||
case FUNC_INIT:
|
||||
McpSnsInit();
|
||||
break;
|
||||
case FUNC_PRE_INIT:
|
||||
McpDrvInit();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -109,10 +109,8 @@ void PzemAcSnsInit(void)
|
|||
|
||||
void PzemAcDrvInit(void)
|
||||
{
|
||||
if (!energy_flg) {
|
||||
if ((pin[GPIO_PZEM016_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) {
|
||||
energy_flg = XNRG_05;
|
||||
}
|
||||
if ((pin[GPIO_PZEM016_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) {
|
||||
energy_flg = XNRG_05;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,22 +118,20 @@ void PzemAcDrvInit(void)
|
|||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
int Xnrg05(uint8_t function)
|
||||
bool Xnrg05(uint8_t function)
|
||||
{
|
||||
int result = 0;
|
||||
bool result = false;
|
||||
|
||||
if (FUNC_PRE_INIT == function) {
|
||||
PzemAcDrvInit();
|
||||
}
|
||||
else if (XNRG_05 == energy_flg) {
|
||||
switch (function) {
|
||||
case FUNC_INIT:
|
||||
PzemAcSnsInit();
|
||||
break;
|
||||
case FUNC_ENERGY_EVERY_SECOND:
|
||||
if (uptime > 4) { PzemAcEverySecond(); } // Fix start up issue #5875
|
||||
break;
|
||||
}
|
||||
switch (function) {
|
||||
case FUNC_ENERGY_EVERY_SECOND:
|
||||
if (uptime > 4) { PzemAcEverySecond(); } // Fix start up issue #5875
|
||||
break;
|
||||
case FUNC_INIT:
|
||||
PzemAcSnsInit();
|
||||
break;
|
||||
case FUNC_PRE_INIT:
|
||||
PzemAcDrvInit();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -88,10 +88,8 @@ void PzemDcSnsInit(void)
|
|||
|
||||
void PzemDcDrvInit(void)
|
||||
{
|
||||
if (!energy_flg) {
|
||||
if ((pin[GPIO_PZEM017_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) {
|
||||
energy_flg = XNRG_06;
|
||||
}
|
||||
if ((pin[GPIO_PZEM017_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) {
|
||||
energy_flg = XNRG_06;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,22 +97,20 @@ void PzemDcDrvInit(void)
|
|||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
int Xnrg06(uint8_t function)
|
||||
bool Xnrg06(uint8_t function)
|
||||
{
|
||||
int result = 0;
|
||||
bool result = false;
|
||||
|
||||
if (FUNC_PRE_INIT == function) {
|
||||
PzemDcDrvInit();
|
||||
}
|
||||
else if (XNRG_06 == energy_flg) {
|
||||
switch (function) {
|
||||
case FUNC_INIT:
|
||||
PzemDcSnsInit();
|
||||
break;
|
||||
case FUNC_ENERGY_EVERY_SECOND:
|
||||
if (uptime > 4) { PzemDcEverySecond(); } // Fix start up issue #5875
|
||||
break;
|
||||
}
|
||||
switch (function) {
|
||||
case FUNC_ENERGY_EVERY_SECOND:
|
||||
if (uptime > 4) { PzemDcEverySecond(); } // Fix start up issue #5875
|
||||
break;
|
||||
case FUNC_INIT:
|
||||
PzemDcSnsInit();
|
||||
break;
|
||||
case FUNC_PRE_INIT:
|
||||
PzemDcDrvInit();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -169,19 +169,17 @@ void Ade7953EnergyEverySecond()
|
|||
|
||||
void Ade7953DrvInit(void)
|
||||
{
|
||||
if (!energy_flg) {
|
||||
if (i2c_flg && (pin[GPIO_ADE7953_IRQ] < 99)) { // Irq on GPIO16 is not supported...
|
||||
delay(100); // Need 100mS to init ADE7953
|
||||
if (I2cDevice(ADE7953_ADDR)) {
|
||||
if (HLW_PREF_PULSE == Settings.energy_power_calibration) {
|
||||
Settings.energy_power_calibration = ADE7953_PREF;
|
||||
Settings.energy_voltage_calibration = ADE7953_UREF;
|
||||
Settings.energy_current_calibration = ADE7953_IREF;
|
||||
}
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "ADE7953", ADE7953_ADDR);
|
||||
Ade7953.init_step = 2;
|
||||
energy_flg = XNRG_07;
|
||||
}
|
||||
if (i2c_flg && (pin[GPIO_ADE7953_IRQ] < 99)) { // Irq on GPIO16 is not supported...
|
||||
delay(100); // Need 100mS to init ADE7953
|
||||
if (I2cDevice(ADE7953_ADDR)) {
|
||||
if (HLW_PREF_PULSE == Settings.energy_power_calibration) {
|
||||
Settings.energy_power_calibration = ADE7953_PREF;
|
||||
Settings.energy_voltage_calibration = ADE7953_UREF;
|
||||
Settings.energy_current_calibration = ADE7953_IREF;
|
||||
}
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "ADE7953", ADE7953_ADDR);
|
||||
Ade7953.init_step = 2;
|
||||
energy_flg = XNRG_07;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -234,22 +232,20 @@ bool Ade7953Command(void)
|
|||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
int Xnrg07(uint8_t function)
|
||||
bool Xnrg07(uint8_t function)
|
||||
{
|
||||
int result = 0;
|
||||
bool result = false;
|
||||
|
||||
if (FUNC_PRE_INIT == function) {
|
||||
Ade7953DrvInit();
|
||||
}
|
||||
else if (XNRG_07 == energy_flg) {
|
||||
switch (function) {
|
||||
case FUNC_ENERGY_EVERY_SECOND:
|
||||
Ade7953EnergyEverySecond();
|
||||
break;
|
||||
case FUNC_COMMAND:
|
||||
result = Ade7953Command();
|
||||
break;
|
||||
}
|
||||
switch (function) {
|
||||
case FUNC_ENERGY_EVERY_SECOND:
|
||||
Ade7953EnergyEverySecond();
|
||||
break;
|
||||
case FUNC_COMMAND:
|
||||
result = Ade7953Command();
|
||||
break;
|
||||
case FUNC_PRE_INIT:
|
||||
Ade7953DrvInit();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
xnrg_09_sdm120.ino - Eastron SDM120-Modbus energy meter support for Sonoff-Tasmota
|
||||
xnrg_08_sdm120.ino - Eastron SDM120-Modbus energy meter support for Sonoff-Tasmota
|
||||
|
||||
Copyright (C) 2019 Gennaro Tortone and Theo Arends
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
|||
* Based on: https://github.com/reaper7/SDM_Energy_Meter
|
||||
\*********************************************************************************************/
|
||||
|
||||
#define XNRG_09 9
|
||||
#define XNRG_08 8
|
||||
|
||||
// can be user defined in my_user_config.h
|
||||
#ifndef SDM120_SPEED
|
||||
|
@ -189,10 +189,8 @@ void Sdm120SnsInit(void)
|
|||
|
||||
void Sdm120DrvInit(void)
|
||||
{
|
||||
if (!energy_flg) {
|
||||
if ((pin[GPIO_SDM120_RX] < 99) && (pin[GPIO_SDM120_TX] < 99)) {
|
||||
energy_flg = XNRG_09;
|
||||
}
|
||||
if ((pin[GPIO_SDM120_RX] < 99) && (pin[GPIO_SDM120_TX] < 99)) {
|
||||
energy_flg = XNRG_08;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,33 +243,31 @@ void Sdm220Show(bool json)
|
|||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
int Xnrg09(uint8_t function)
|
||||
bool Xnrg08(uint8_t function)
|
||||
{
|
||||
int result = 0;
|
||||
bool result = false;
|
||||
|
||||
if (FUNC_PRE_INIT == function) {
|
||||
Sdm120DrvInit();
|
||||
}
|
||||
else if (XNRG_09 == energy_flg) {
|
||||
switch (function) {
|
||||
case FUNC_INIT:
|
||||
Sdm120SnsInit();
|
||||
break;
|
||||
case FUNC_EVERY_250_MSECOND:
|
||||
if (uptime > 4) { SDM120Every250ms(); }
|
||||
break;
|
||||
case FUNC_ENERGY_RESET:
|
||||
Sdm220Reset();
|
||||
break;
|
||||
case FUNC_JSON_APPEND:
|
||||
Sdm220Show(1);
|
||||
break;
|
||||
switch (function) {
|
||||
case FUNC_EVERY_250_MSECOND:
|
||||
if (uptime > 4) { SDM120Every250ms(); }
|
||||
break;
|
||||
case FUNC_JSON_APPEND:
|
||||
Sdm220Show(1);
|
||||
break;
|
||||
#ifdef USE_WEBSERVER
|
||||
case FUNC_WEB_SENSOR:
|
||||
Sdm220Show(0);
|
||||
break;
|
||||
case FUNC_WEB_SENSOR:
|
||||
Sdm220Show(0);
|
||||
break;
|
||||
#endif // USE_WEBSERVER
|
||||
}
|
||||
case FUNC_ENERGY_RESET:
|
||||
Sdm220Reset();
|
||||
break;
|
||||
case FUNC_INIT:
|
||||
Sdm120SnsInit();
|
||||
break;
|
||||
case FUNC_PRE_INIT:
|
||||
Sdm120DrvInit();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
|
@ -20,9 +20,9 @@
|
|||
#ifdef USE_ENERGY_SENSOR
|
||||
|
||||
#ifdef XFUNC_PTR_IN_ROM
|
||||
int (* const xnrg_func_ptr[])(uint8_t) PROGMEM = { // Energy driver Function Pointers
|
||||
bool (* const xnrg_func_ptr[])(uint8_t) PROGMEM = { // Energy driver Function Pointers
|
||||
#else
|
||||
int (* const xnrg_func_ptr[])(uint8_t) = { // Energy driver Function Pointers
|
||||
bool (* const xnrg_func_ptr[])(uint8_t) = { // Energy driver Function Pointers
|
||||
#endif
|
||||
|
||||
#ifdef XNRG_01
|
||||
|
@ -92,20 +92,23 @@ int (* const xnrg_func_ptr[])(uint8_t) = { // Energy driver Function Pointers
|
|||
|
||||
const uint8_t xnrg_present = sizeof(xnrg_func_ptr) / sizeof(xnrg_func_ptr[0]); // Number of drivers found
|
||||
|
||||
int XnrgCall(uint8_t Function)
|
||||
uint8_t xnrg_active = 0;
|
||||
|
||||
bool XnrgCall(uint8_t function)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
for (uint32_t x = 0; x < xnrg_present; x++) {
|
||||
result = xnrg_func_ptr[x](Function);
|
||||
|
||||
if (result && ((FUNC_SERIAL == Function) ||
|
||||
(FUNC_COMMAND == Function)
|
||||
)) {
|
||||
break;
|
||||
if (FUNC_PRE_INIT == function) {
|
||||
for (uint32_t x = 0; x < xnrg_present; x++) {
|
||||
xnrg_func_ptr[x](function);
|
||||
if (energy_flg) {
|
||||
xnrg_active = x;
|
||||
return true; // Stop further driver investigation
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
else if (energy_flg) {
|
||||
return xnrg_func_ptr[xnrg_active](function);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // USE_ENERGY_SENSOR
|
||||
|
|
|
@ -167,7 +167,7 @@ a_features = [[
|
|||
"USE_MAX31865","USE_CHIRP","USE_SOLAX_X1","USE_PAJ7620"
|
||||
],[
|
||||
"USE_BUZZER","USE_RDM6300","USE_IBEACON","USE_SML_M",
|
||||
"USE_INA226","","","",
|
||||
"USE_INA226","USE_A4988_Stepper","","",
|
||||
"","","","",
|
||||
"","","","",
|
||||
"","","","",
|
||||
|
|
Loading…
Reference in New Issue