@@ -0,0 +1,59 @@
|
||||
#ifndef CURRENT_SENSOR_H
|
||||
#define CURRENT_SENSOR_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Streaming.h>
|
||||
#include "../Addon.h"
|
||||
#include "../config.h"
|
||||
|
||||
#include "../common/macros.h"
|
||||
#include "../common/ppmath.h"
|
||||
|
||||
class CurrentSensor : public Addon
|
||||
{
|
||||
public:
|
||||
CurrentSensor(short _pin) : pin(_pin),
|
||||
load(0),
|
||||
Addon(CURRENT_SENSOR_STR, CURRENT_SENSOR)
|
||||
{
|
||||
// this->setFlag(DEBUG);
|
||||
}
|
||||
|
||||
short setup()
|
||||
{
|
||||
pinMode(pin, INPUT);
|
||||
loop();
|
||||
}
|
||||
|
||||
short loop()
|
||||
{
|
||||
if (now - last > MOTOR_LOAD_READ_INTERVAL)
|
||||
{
|
||||
load = digitalRead(pin);
|
||||
last = now;
|
||||
}
|
||||
return load;
|
||||
}
|
||||
|
||||
short ok()
|
||||
{
|
||||
return !load;
|
||||
}
|
||||
|
||||
void debug(Stream *stream)
|
||||
{
|
||||
*stream << this->name << ":" << ok();
|
||||
}
|
||||
|
||||
void info(Stream *stream)
|
||||
{
|
||||
*stream << this->name << "\n\t : " SPACE("Pin:" << pin);
|
||||
}
|
||||
|
||||
millis_t lastOverload;
|
||||
|
||||
protected:
|
||||
short pin;
|
||||
short load;
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
#ifndef DIRECTION_SWITCH_H
|
||||
#define DIRECTION_SWITCH_H
|
||||
|
||||
#include "../config.h"
|
||||
#include "../components/3PosAnalog.h"
|
||||
#include "../Addon.h"
|
||||
#include <Streaming.h>
|
||||
#include "../common/macros.h"
|
||||
|
||||
class DirectionSwitch : public Addon
|
||||
{
|
||||
public:
|
||||
Pos3Analog dir_switch;
|
||||
DirectionSwitch() : dir_switch(DIR_SWITCH_UP_PIN, DIR_SWITCH_DOWN_PIN),
|
||||
Addon(DIRECTION_SWITCH_STR, DIRECTION_SWITCH)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void debug(Stream *stream)
|
||||
{
|
||||
*stream << this->name << ":" << SPACE(dir_switch.switch_pos) << SPACE(dir_switch.last_switch);
|
||||
}
|
||||
void info(Stream *stream)
|
||||
{
|
||||
*stream << this->name << "\n\t : " SPACE("Up Pin:" << DIR_SWITCH_UP_PIN) << SPACE("\t | Down Pin :" << DIR_SWITCH_DOWN_PIN);
|
||||
}
|
||||
short setup()
|
||||
{
|
||||
dir_switch.setup();
|
||||
return loop();
|
||||
}
|
||||
short loop()
|
||||
{
|
||||
if (now - dt > ANALOG_READ_INTERVAL)
|
||||
{
|
||||
_value = dir_switch.loop();
|
||||
dt = now;
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
short value()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
short last()
|
||||
{
|
||||
return dir_switch.last_switch;
|
||||
}
|
||||
|
||||
private:
|
||||
short _value;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef MOTOR_TEMPERATURE_H
|
||||
#define MOTOR_TEMPERATURE_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Addon.h"
|
||||
#include "config.h"
|
||||
#include <Streaming.h>
|
||||
#include "../common/macros.h"
|
||||
#include "TemperatureSensor.h"
|
||||
|
||||
class MotorTemperature : public Addon
|
||||
{
|
||||
private:
|
||||
TemperatureSensor sensor;
|
||||
|
||||
public:
|
||||
MotorTemperature() : sensor(MOTOR_TEMPERTURE_SCK_PIN, MOTOR_TEMPERTURE_CS_PIN, MOTOR_TEMPERTURE_SO_PIN, MOTOR_TEMPERTURE_MAX, MOTOR_TEMPERTURE_INTERVAL),
|
||||
Addon(MOTOR_TEMPERATURE_STR, MOTOR_TEMPERATURE) {}
|
||||
|
||||
virtual short ok()
|
||||
{
|
||||
return sensor.ok();
|
||||
}
|
||||
void debug(Stream *stream)
|
||||
{
|
||||
// *stream << this->name << ":" << this->ok();
|
||||
}
|
||||
void info(Stream *stream)
|
||||
{
|
||||
/*
|
||||
*stream << this->name << "\n\t : " <<
|
||||
SPACE("Pin SCK:" << MOTOR_TEMPERTURE_SCK_PIN ) <<
|
||||
SPACE("Pin CS :" << MOTOR_TEMPERTURE_CS_PIN ) <<
|
||||
SPACE("Pin SO:" << MOTOR_TEMPERTURE_SO_PIN ) <<
|
||||
SPACE("Max" << MOTOR_TEMPERTURE_MAX ) <<
|
||||
SPACE("Interval" << MOTOR_TEMPERTURE_INTERVAL );
|
||||
*/
|
||||
}
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,148 @@
|
||||
#ifndef OPERATION_MODE_SWITCH_H
|
||||
#define OPERATION_MODE_SWITCH_H
|
||||
|
||||
#ifdef HAS_STATES
|
||||
#include <ArduinoJson.h>
|
||||
#endif
|
||||
|
||||
#ifndef OP_MODE_ANALOG
|
||||
#include <Bounce2.h>
|
||||
#endif
|
||||
|
||||
#include "../config.h"
|
||||
#include "../Addon.h"
|
||||
#include <Streaming.h>
|
||||
#include "../common/macros.h"
|
||||
#include "../common/ppmath.h"
|
||||
|
||||
class OperationModeSwitch : public Addon
|
||||
{
|
||||
|
||||
public:
|
||||
short pin1;
|
||||
#ifdef OP_MODE_ANALOG
|
||||
ushort level1;
|
||||
ushort level2;
|
||||
ushort level3;
|
||||
OperationModeSwitch(short _pin1, ushort _level1, ushort _level2, ushort _level3) : pin1(_pin1),
|
||||
level1(_level1),
|
||||
level2(_level2),
|
||||
level3(_level3),
|
||||
Addon(OPERATION_MODE_SWITCH_STR, OPERATION_MODE_SWITCH)
|
||||
{
|
||||
//setFlag(DEBUG);
|
||||
}
|
||||
#ifdef HAS_STATES
|
||||
String state()
|
||||
{
|
||||
const int capacity = JSON_OBJECT_SIZE(2);
|
||||
StaticJsonDocument<capacity> doc;
|
||||
doc['0'] = id;
|
||||
doc['1'] = value();
|
||||
return doc.as<String>();
|
||||
}
|
||||
#endif
|
||||
void debug(Stream *stream)
|
||||
{
|
||||
//*stream << this->name << SPACE(value());
|
||||
}
|
||||
void info(Stream *stream)
|
||||
{
|
||||
//*stream << this->name << "\n\t ";
|
||||
}
|
||||
|
||||
short value()
|
||||
{
|
||||
ushort value = analogRead(pin1);
|
||||
if (RANGE(value, level1 - 10, level1 + 10))
|
||||
{
|
||||
return OP_DEBUG;
|
||||
}
|
||||
if (RANGE(value, level2 - 10, level2 + 10))
|
||||
{
|
||||
return OP_NORMAL;
|
||||
}
|
||||
if (RANGE(value, level3 - 10, level3 + 10))
|
||||
{
|
||||
return OP_SERVICE;
|
||||
}
|
||||
return OP_NONE;
|
||||
}
|
||||
short setup()
|
||||
{
|
||||
}
|
||||
|
||||
short loop()
|
||||
{
|
||||
// Serial.println(analogRead(pin1));
|
||||
}
|
||||
|
||||
#else
|
||||
Bounce debouncer1;
|
||||
Bounce debouncer2;
|
||||
Bounce debouncer3;
|
||||
short pin1;
|
||||
short pin2;
|
||||
short pin3;
|
||||
|
||||
OperationModeSwitch(short _pin1, short _pin2, short _pin3) : pin1(_pin1), // 1-2
|
||||
pin2(_pin2), // 5-6
|
||||
pin3(_pin3), // 9-10
|
||||
Addon(OPERATION_MODE_SWITCH_STR, OPERATION_MODE_SWITCH)
|
||||
{
|
||||
}
|
||||
|
||||
void debug(Stream *stream)
|
||||
{
|
||||
*stream << this->name << ": PIN1 " << SPACE(!debouncer1.read()) << ": PIN2 " << SPACE(!debouncer2.read()) << ": PIN3 " << SPACE(!debouncer3.read());
|
||||
}
|
||||
void info(Stream *stream)
|
||||
{
|
||||
*stream << this->name << "\n\t : ";
|
||||
}
|
||||
|
||||
short value()
|
||||
{
|
||||
if (!debouncer1.read())
|
||||
{
|
||||
return OP_DEBUG;
|
||||
}
|
||||
|
||||
if (!debouncer2.read())
|
||||
{
|
||||
return OP_NORMAL;
|
||||
}
|
||||
|
||||
if (!debouncer3.read())
|
||||
{
|
||||
return OP_SERVICE;
|
||||
}
|
||||
|
||||
return OP_NONE;
|
||||
}
|
||||
short setup()
|
||||
{
|
||||
this->debouncer1 = Bounce();
|
||||
this->debouncer1.attach(this->pin1, INPUT_PULLUP);
|
||||
this->debouncer1.interval(25);
|
||||
|
||||
this->debouncer2 = Bounce();
|
||||
this->debouncer2.attach(this->pin2, INPUT_PULLUP);
|
||||
this->debouncer2.interval(25);
|
||||
|
||||
this->debouncer3 = Bounce();
|
||||
this->debouncer3.attach(this->pin3, INPUT_PULLUP);
|
||||
this->debouncer3.interval(25);
|
||||
}
|
||||
|
||||
short loop()
|
||||
{
|
||||
this->debouncer1.update();
|
||||
this->debouncer2.update();
|
||||
this->debouncer3.update();
|
||||
}
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef RESET_H
|
||||
#define RESET_H
|
||||
|
||||
// This module uses currently a normally closed momentary button.
|
||||
|
||||
static millis_t sw_reset_TS = 0;
|
||||
|
||||
static void reset_setup()
|
||||
{
|
||||
pinMode(RESET_PIN, INPUT_PULLUP);
|
||||
sw_reset_TS = millis();
|
||||
}
|
||||
|
||||
static void reset_loop()
|
||||
{
|
||||
if (millis() - sw_reset_TS > RESET_INTERVAL) {
|
||||
#if RESET_NC == true
|
||||
// globals.isReset = digitalRead(RESET_PIN);
|
||||
#else
|
||||
// globals.isReset = !digitalRead(RESET_PIN);
|
||||
#endif
|
||||
|
||||
sw_reset_TS = millis();
|
||||
// if(globals.isReset && DEBUG){
|
||||
// Serial.println("reset");
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,110 @@
|
||||
#ifndef STATUS_H
|
||||
#define STATUS_H
|
||||
|
||||
#include "../addon.h"
|
||||
#include "../types.h"
|
||||
#include "../common/macros.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class Status : public Addon
|
||||
{
|
||||
public:
|
||||
Status(short _errorPin, short _okPin) : errorPin(_errorPin),
|
||||
okPin(_okPin),
|
||||
status_blink_TS(0),
|
||||
doBlink(false),
|
||||
last_blink(true),
|
||||
blink_start_ts(0),
|
||||
max_blink_time(HOUR_MS),
|
||||
Addon(STATUS_STR, STATUS)
|
||||
{
|
||||
}
|
||||
|
||||
short setup()
|
||||
{
|
||||
pinMode(okPin, OUTPUT);
|
||||
pinMode(errorPin, OUTPUT);
|
||||
}
|
||||
|
||||
short loop()
|
||||
{
|
||||
if (now - status_blink_TS > 1000)
|
||||
{
|
||||
status_blink_TS = millis();
|
||||
last_blink = !last_blink;
|
||||
if (doBlink)
|
||||
{
|
||||
digitalWrite(errorPin, last_blink);
|
||||
}
|
||||
|
||||
if (now - blink_start_ts > max_blink_time)
|
||||
{
|
||||
doBlink = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
void status_blink(bool blink)
|
||||
{
|
||||
if (!doBlink && blink)
|
||||
{
|
||||
blink_start_ts = millis();
|
||||
}
|
||||
doBlink = blink;
|
||||
}
|
||||
|
||||
void setStatusAllOn()
|
||||
{
|
||||
if (doBlink)
|
||||
{
|
||||
return;
|
||||
}
|
||||
digitalWrite(errorPin, HIGH);
|
||||
digitalWrite(okPin, HIGH);
|
||||
}
|
||||
|
||||
void setStatusAllOff()
|
||||
{
|
||||
if (doBlink)
|
||||
{
|
||||
return;
|
||||
}
|
||||
digitalWrite(errorPin, LOW);
|
||||
digitalWrite(okPin, LOW);
|
||||
}
|
||||
|
||||
void setStatus(bool error)
|
||||
{
|
||||
if (doBlink)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (error)
|
||||
{
|
||||
digitalWrite(errorPin, HIGH);
|
||||
digitalWrite(okPin, LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(okPin, HIGH);
|
||||
digitalWrite(errorPin, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void info(Stream *stream)
|
||||
{
|
||||
*stream << this->name << "\n\t : " SPACE("Error Pin:" << errorPin) << SPACE("\t | Ok Pin :" << okPin);
|
||||
}
|
||||
|
||||
private:
|
||||
millis_t status_blink_TS;
|
||||
bool doBlink;
|
||||
bool last_blink;
|
||||
millis_t blink_start_ts;
|
||||
millis_t max_blink_time;
|
||||
|
||||
short okPin;
|
||||
short errorPin;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef TEMPERATURE_SENSOR_H
|
||||
#define TEMPERATURE_SENSOR_H
|
||||
|
||||
#include <max6675.h>
|
||||
#include "../config.h"
|
||||
#include "../macros.h"
|
||||
#include "../time.h"
|
||||
|
||||
class TemperatureSensor
|
||||
{
|
||||
|
||||
public:
|
||||
TemperatureSensor(short sck, short cs, short so, short _max, short _interval) : ktc(MAX6675(sck, cs, so)),
|
||||
temperature(),
|
||||
temperature_TS(millis()),
|
||||
maxTemp(_max),
|
||||
interval(_interval) {}
|
||||
|
||||
bool ok()
|
||||
{
|
||||
return temperature < maxTemp;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
if (millis() - temperature_TS > interval)
|
||||
{
|
||||
temperature_TS = millis();
|
||||
temperature = ktc.readCelsius();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
MAX6675 ktc;
|
||||
short temperature;
|
||||
short maxTemp;
|
||||
short interval;
|
||||
millis_t temperature_TS;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user