Removed example files (can be recovered later)
Now it compiles with test main code
This commit is contained in:
@@ -84,7 +84,7 @@ void EthernetTask(void *parameter) {
|
||||
while(1){
|
||||
if (eth_connected && !eth_connected_Old) {
|
||||
eth_connected_Old = eth_connected;
|
||||
RGB_Open_Time(0, 60, 0,1000, 0);
|
||||
//RGB_Open_Time(0, 60, 0,1000, 0);
|
||||
printf("Network port connected!\r\n");
|
||||
Acquisition_time();
|
||||
}
|
||||
@@ -108,13 +108,13 @@ void Acquisition_time(void) { // Get the netwo
|
||||
printf("ETH - Online clock error!!!\r\n");
|
||||
}
|
||||
struct tm *localTime = localtime(¤tTime);
|
||||
static datetime_t PCF85063_Time = {0};
|
||||
PCF85063_Time.year = localTime->tm_year + 1900;
|
||||
PCF85063_Time.month = localTime->tm_mon + 1;
|
||||
PCF85063_Time.day = localTime->tm_mday;
|
||||
PCF85063_Time.dotw = localTime->tm_wday;
|
||||
PCF85063_Time.hour = localTime->tm_hour;
|
||||
PCF85063_Time.minute = localTime->tm_min;
|
||||
PCF85063_Time.second = localTime->tm_sec;
|
||||
//static datetime_t PCF85063_Time = {0};
|
||||
//PCF85063_Time.year = localTime->tm_year + 1900;
|
||||
//PCF85063_Time.month = localTime->tm_mon + 1;
|
||||
//PCF85063_Time.day = localTime->tm_mday;
|
||||
//PCF85063_Time.dotw = localTime->tm_wday;
|
||||
//PCF85063_Time.hour = localTime->tm_hour;
|
||||
//PCF85063_Time.minute = localTime->tm_min;
|
||||
//PCF85063_Time.second = localTime->tm_sec;
|
||||
//PCF85063_Set_All(PCF85063_Time);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "WS_TCA9554PWR.h"
|
||||
#include "TCA9554PWR_Driver.h"
|
||||
|
||||
namespace drivers
|
||||
{
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
#include "WS_DIN.h"
|
||||
|
||||
bool DIN_Flag[8] = {0}; // DIN current status flag
|
||||
uint8_t DIN_Data = 0;
|
||||
bool Relay_Immediate_Enable = Relay_Immediate_Default;
|
||||
|
||||
bool DIN_Read_CH1(void){
|
||||
DIN_Flag[0] = digitalRead(DIN_PIN_CH1);
|
||||
if(DIN_Flag[0]){
|
||||
DIN_Data |= (1 << 0);
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
DIN_Data &= (~(1 << 0));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
bool DIN_Read_CH2(void){
|
||||
DIN_Flag[1] = digitalRead(DIN_PIN_CH2);
|
||||
if(DIN_Flag[1]){
|
||||
DIN_Data |= (1 << 1);
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
DIN_Data &= (~(1 << 1));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
bool DIN_Read_CH3(void){
|
||||
DIN_Flag[2] = digitalRead(DIN_PIN_CH3);
|
||||
if(DIN_Flag[2]){
|
||||
DIN_Data |= (1 << 2);
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
DIN_Data &= (~(1 << 2));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
bool DIN_Read_CH4(void){
|
||||
DIN_Flag[3] = digitalRead(DIN_PIN_CH4);
|
||||
if(DIN_Flag[3]){
|
||||
DIN_Data |= (1 << 3);
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
DIN_Data &= (~(1 << 3));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
bool DIN_Read_CH5(void){
|
||||
DIN_Flag[4] = digitalRead(DIN_PIN_CH5);
|
||||
if(DIN_Flag[4]){
|
||||
DIN_Data |= (1 << 4);
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
DIN_Data &= (~(1 << 4));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
bool DIN_Read_CH6(void){
|
||||
DIN_Flag[5] = digitalRead(DIN_PIN_CH6);
|
||||
if(DIN_Flag[5]){
|
||||
DIN_Data |= (1 << 5);
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
DIN_Data &= (~(1 << 5));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
bool DIN_Read_CH7(void){
|
||||
DIN_Flag[6] = digitalRead(DIN_PIN_CH7);
|
||||
if(DIN_Flag[6]){
|
||||
DIN_Data |= (1 << 6);
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
DIN_Data &= (~(1 << 6));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
bool DIN_Read_CH8(void){
|
||||
DIN_Flag[7] = digitalRead(DIN_PIN_CH8);
|
||||
if(DIN_Flag[7]){
|
||||
DIN_Data |= (1 << 7);
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
DIN_Data &= (~(1 << 7));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
uint8_t DIN_Read_CHxs(){
|
||||
DIN_Read_CH1();
|
||||
DIN_Read_CH2();
|
||||
DIN_Read_CH3();
|
||||
DIN_Read_CH4();
|
||||
DIN_Read_CH5();
|
||||
DIN_Read_CH6();
|
||||
DIN_Read_CH7();
|
||||
DIN_Read_CH8();
|
||||
return DIN_Data;
|
||||
}
|
||||
|
||||
static uint8_t DIN_Data_Old = 0;
|
||||
void DINTask(void *parameter) {
|
||||
while(1){
|
||||
if(Relay_Immediate_Enable){
|
||||
DIN_Read_CHxs();
|
||||
if(DIN_Data_Old != DIN_Data){
|
||||
if(DIN_Inverse_Enable)
|
||||
Relay_Immediate_CHxs(~DIN_Data , DIN_Mode);
|
||||
else
|
||||
Relay_Immediate_CHxs(DIN_Data , DIN_Mode);
|
||||
DIN_Data_Old = DIN_Data;
|
||||
}
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void DIN_Init(void)
|
||||
{
|
||||
pinMode(DIN_PIN_CH1, INPUT_PULLUP);
|
||||
pinMode(DIN_PIN_CH2, INPUT_PULLUP);
|
||||
pinMode(DIN_PIN_CH3, INPUT_PULLUP);
|
||||
pinMode(DIN_PIN_CH4, INPUT_PULLUP);
|
||||
pinMode(DIN_PIN_CH5, INPUT_PULLUP);
|
||||
pinMode(DIN_PIN_CH6, INPUT_PULLUP);
|
||||
pinMode(DIN_PIN_CH7, INPUT_PULLUP);
|
||||
pinMode(DIN_PIN_CH8, INPUT_PULLUP);
|
||||
|
||||
DIN_Read_CHxs();
|
||||
if(DIN_Inverse_Enable)
|
||||
DIN_Data_Old = 0xFF;
|
||||
else
|
||||
DIN_Data_Old = 0x00;
|
||||
|
||||
xTaskCreatePinnedToCore(
|
||||
DINTask,
|
||||
"DINTask",
|
||||
4096,
|
||||
NULL,
|
||||
4,
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "WS_GPIO.h"
|
||||
#include "WS_Relay.h"
|
||||
/************************************************************* I/O *************************************************************/
|
||||
#define DIN_PIN_CH1 4 // DIN CH1 GPIO
|
||||
#define DIN_PIN_CH2 5 // DIN CH2 GPIO
|
||||
#define DIN_PIN_CH3 6 // DIN CH3 GPIO
|
||||
#define DIN_PIN_CH4 7 // DIN CH4 GPIO
|
||||
#define DIN_PIN_CH5 8 // DIN CH5 GPIO
|
||||
#define DIN_PIN_CH6 9 // DIN CH6 GPIO
|
||||
#define DIN_PIN_CH7 10 // DIN CH7 GPIO
|
||||
#define DIN_PIN_CH8 11 // DIN CH8 GPIO
|
||||
|
||||
#define Relay_Immediate_Default 1 // Enable the input control relay
|
||||
#define DIN_Inverse_Enable 1 // Input is reversed from control
|
||||
|
||||
void DIN_Init(void);
|
||||
@@ -1,166 +0,0 @@
|
||||
#include "WS_GPIO.h"
|
||||
|
||||
/************************************************************* I/O Init *************************************************************/
|
||||
void GPIO_Init() {
|
||||
pinMode(GPIO_PIN_RGB, OUTPUT); // Initialize the control GPIO of RGB
|
||||
pinMode(GPIO_PIN_Buzzer, OUTPUT); // Initialize the control GPIO of Buzzer
|
||||
|
||||
// TODO: Re enable this
|
||||
//ledcAttach(GPIO_PIN_Buzzer, Frequency, Resolution);
|
||||
Set_Dutyfactor(0); //0~100
|
||||
|
||||
xTaskCreatePinnedToCore(
|
||||
RGBTask,
|
||||
"RelayFailTask",
|
||||
4096,
|
||||
NULL,
|
||||
2,
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
xTaskCreatePinnedToCore(
|
||||
BuzzerTask,
|
||||
"RelayFailTask",
|
||||
4096,
|
||||
NULL,
|
||||
2,
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
/************************************************************* RGB *************************************************************/
|
||||
void RGB_Light(uint8_t red_val, uint8_t green_val, uint8_t blue_val) {
|
||||
rgbLedWrite(GPIO_PIN_RGB, green_val, red_val, blue_val); // RGB color adjustment
|
||||
}
|
||||
RGB_Indicate RGB_indicate[RGB_Indicate_Number];
|
||||
static uint8_t RGB_indicate_Num = 0;
|
||||
void RGB_Open_Time(uint8_t red_val, uint8_t green_val, uint8_t blue_val, uint16_t Time, uint16_t flicker_time) {
|
||||
|
||||
if(RGB_indicate_Num + 1 >= RGB_Indicate_Number)
|
||||
{
|
||||
printf("Note : The RGB indicates that the cache is full and has been ignored\r\n");
|
||||
}
|
||||
else{
|
||||
RGB_indicate[RGB_indicate_Num].Red = red_val;
|
||||
RGB_indicate[RGB_indicate_Num].Green = green_val;
|
||||
RGB_indicate[RGB_indicate_Num].Blue = blue_val;
|
||||
RGB_indicate[RGB_indicate_Num].RGB_Time = Time;
|
||||
if(flicker_time<51)
|
||||
flicker_time = 0; // If the blinking interval is less than 50ms, the blinking is ignored
|
||||
RGB_indicate[RGB_indicate_Num].RGB_Flicker = flicker_time;
|
||||
RGB_indicate_Num ++;
|
||||
}
|
||||
}
|
||||
void RGBTask(void *parameter) {
|
||||
bool RGB_Flag = 0;
|
||||
while(1){
|
||||
if(RGB_indicate[0].RGB_Time)
|
||||
{
|
||||
RGB_Flag = 1;
|
||||
RGB_Light(RGB_indicate[0].Red, RGB_indicate[0].Green, RGB_indicate[0].Blue);
|
||||
if(RGB_indicate[0].RGB_Flicker){
|
||||
vTaskDelay(pdMS_TO_TICKS(RGB_indicate[0].RGB_Flicker));
|
||||
RGB_Light(0, 0, 0);
|
||||
vTaskDelay(pdMS_TO_TICKS(RGB_indicate[0].RGB_Flicker));
|
||||
}
|
||||
if(RGB_indicate[0].RGB_Time > (RGB_indicate[0].RGB_Flicker * 2 +50))
|
||||
RGB_indicate[0].RGB_Time = RGB_indicate[0].RGB_Time -(RGB_indicate[0].RGB_Flicker * 2 +50);
|
||||
else
|
||||
RGB_indicate[0].RGB_Time = 0;
|
||||
}
|
||||
else if(RGB_Flag && !RGB_indicate[0].RGB_Time){
|
||||
RGB_Light(0, 0, 0);
|
||||
RGB_Flag = 0;
|
||||
RGB_indicate[0].Red = 0;
|
||||
RGB_indicate[0].Green = 0;
|
||||
RGB_indicate[0].Blue = 0;
|
||||
RGB_indicate[0].RGB_Time = 0;
|
||||
RGB_indicate[0].RGB_Flicker = 0;
|
||||
if(RGB_indicate_Num > 0){
|
||||
for (int i = 1; i < RGB_Indicate_Number; i++) {
|
||||
RGB_indicate[i-1] = RGB_indicate[i];
|
||||
}
|
||||
RGB_indicate[RGB_Indicate_Number -1].Red = 0;
|
||||
RGB_indicate[RGB_Indicate_Number -1].Green = 0;
|
||||
RGB_indicate[RGB_Indicate_Number -1].Blue = 0;
|
||||
RGB_indicate[RGB_Indicate_Number -1].RGB_Time = 0;
|
||||
RGB_indicate[RGB_Indicate_Number -1].RGB_Flicker = 0;
|
||||
RGB_indicate_Num --;
|
||||
vTaskDelay(pdMS_TO_TICKS(RGB_Indicating_interval));
|
||||
}
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
|
||||
/************************************************************* Buzzer *************************************************************/
|
||||
void Set_Dutyfactor(uint16_t dutyfactor)
|
||||
{
|
||||
if(dutyfactor > Dutyfactor_MAX || dutyfactor < 0)
|
||||
printf("Set Backlight parameters in the range of 0 to %d \r\n",Dutyfactor_MAX);
|
||||
else{
|
||||
ledcWrite(GPIO_PIN_Buzzer, dutyfactor);
|
||||
}
|
||||
}
|
||||
void Buzzer_Open(void)
|
||||
{
|
||||
Set_Dutyfactor(Dutyfactor);
|
||||
}
|
||||
void Buzzer_Closs(void)
|
||||
{
|
||||
Set_Dutyfactor(0);
|
||||
}
|
||||
Buzzer_Indicate Buzzer_indicate[Buzzer_Indicate_Number];
|
||||
static uint8_t Buzzer_indicate_Num = 0;
|
||||
void Buzzer_Open_Time(uint16_t Time, uint16_t flicker_time)
|
||||
{
|
||||
if(Buzzer_indicate_Num + 1 >= Buzzer_Indicate_Number)
|
||||
{
|
||||
printf("Note : The buzzer indicates that the cache is full and has been ignored\r\n");
|
||||
}
|
||||
else{
|
||||
Buzzer_indicate[Buzzer_indicate_Num].Buzzer_Time = Time;
|
||||
if(flicker_time<51)
|
||||
flicker_time = 0; // If the blinking interval is less than 50ms, the blinking is ignored
|
||||
Buzzer_indicate[Buzzer_indicate_Num].Buzzer_Flicker = flicker_time;
|
||||
Buzzer_indicate_Num ++;
|
||||
}
|
||||
}
|
||||
void BuzzerTask(void *parameter) {
|
||||
bool Buzzer_Flag = 0;
|
||||
while(1){
|
||||
if(Buzzer_indicate[0].Buzzer_Time)
|
||||
{
|
||||
Buzzer_Flag = 1;
|
||||
Buzzer_Open();
|
||||
if(Buzzer_indicate[0].Buzzer_Flicker){
|
||||
vTaskDelay(pdMS_TO_TICKS(Buzzer_indicate[0].Buzzer_Flicker));
|
||||
Buzzer_Closs();
|
||||
vTaskDelay(pdMS_TO_TICKS(Buzzer_indicate[0].Buzzer_Flicker));
|
||||
}
|
||||
if(Buzzer_indicate[0].Buzzer_Time > (Buzzer_indicate[0].Buzzer_Flicker * 2 +50))
|
||||
Buzzer_indicate[0].Buzzer_Time = Buzzer_indicate[0].Buzzer_Time -(Buzzer_indicate[0].Buzzer_Flicker * 2 +50);
|
||||
else
|
||||
Buzzer_indicate[0].Buzzer_Time = 0;
|
||||
}
|
||||
else if(Buzzer_Flag && !Buzzer_indicate[0].Buzzer_Time){
|
||||
Buzzer_Closs();
|
||||
Buzzer_Flag = 0;
|
||||
Buzzer_indicate[0].Buzzer_Time = 0;
|
||||
Buzzer_indicate[0].Buzzer_Flicker = 0;
|
||||
if(Buzzer_indicate_Num > 0){
|
||||
for (int i = 1; i < Buzzer_indicate_Num; i++) {
|
||||
Buzzer_indicate[i-1] = Buzzer_indicate[i];
|
||||
}
|
||||
Buzzer_indicate[Buzzer_indicate_Num - 1].Buzzer_Time = 0;
|
||||
Buzzer_indicate[Buzzer_indicate_Num - 1].Buzzer_Flicker = 0;
|
||||
Buzzer_indicate_Num --;
|
||||
}
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <HardwareSerial.h> // Reference the ESP32 built-in serial port library
|
||||
|
||||
/************************************************************* I/O *************************************************************/
|
||||
#define TXD1 17 //The TXD of UART1 corresponds to GPIO RS485/CAN
|
||||
#define RXD1 18 //The RXD of UART1 corresponds to GPIO RS485/CAN
|
||||
#define GPIO_PIN_RGB 38 // RGB Control GPIO
|
||||
|
||||
/*********************************************************** Buzzer ***********************************************************/
|
||||
#define GPIO_PIN_Buzzer 46 // Buzzer Control GPIO
|
||||
#define PWM_Channel 1 // PWM Channel
|
||||
#define Frequency 1000 // PWM frequencyconst
|
||||
#define Resolution 8 // PWM resolution ratio
|
||||
#define Dutyfactor 200 // PWM Dutyfactor
|
||||
#define Dutyfactor_MAX 255
|
||||
|
||||
|
||||
#define RGB_Indicate_Number 10 // Number of saved RGB indicator signals
|
||||
#define RGB_Indicating_interval 500 // Time interval of each indication signal(unit: ms)
|
||||
typedef struct {
|
||||
uint8_t Red = 0;
|
||||
uint8_t Green = 0;
|
||||
uint8_t Blue = 0;
|
||||
uint16_t RGB_Time = 0; // RGB lighting duration
|
||||
uint16_t RGB_Flicker = 0; // RGB flicker interval
|
||||
} RGB_Indicate;
|
||||
|
||||
#define Buzzer_Indicate_Number 10 // Number of saved RGB indicator signals
|
||||
typedef struct {
|
||||
uint16_t Buzzer_Time = 0; // Buzzer duration
|
||||
uint16_t Buzzer_Flicker = 0; // Buzzer interval duration
|
||||
} Buzzer_Indicate;
|
||||
/************************************************************* I/O *************************************************************/
|
||||
void GPIO_Init();
|
||||
void RGB_Light(uint8_t red_val, uint8_t green_val, uint8_t blue_val);
|
||||
void RGB_Open_Time(uint8_t red_val, uint8_t green_val, uint8_t blue_val, uint16_t Time, uint16_t flicker_time);
|
||||
void RGBTask(void *parameter);
|
||||
|
||||
void Set_Dutyfactor(uint16_t dutyfactor);
|
||||
void Buzzer_Open(void);
|
||||
void Buzzer_Closs(void);
|
||||
void Buzzer_Open_Time(uint16_t Time, uint16_t flicker_time);
|
||||
void BuzzerTask(void *parameter);
|
||||
@@ -1,273 +0,0 @@
|
||||
#include "WS_Relay.h"
|
||||
|
||||
bool Failure_Flag = 0;
|
||||
/************************************************************* Relay I/O *************************************************************/
|
||||
bool Relay_Open(uint8_t CHx)
|
||||
{
|
||||
if(!Set_EXIO(CHx, true)){
|
||||
printf("Failed to Open CH%d!!!\r\n", CHx);
|
||||
Failure_Flag = 1;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
bool Relay_Close(uint8_t CHx)
|
||||
{
|
||||
if(!Set_EXIO(CHx, false)){
|
||||
printf("Failed to Closs CH%d!!!\r\n", CHx);
|
||||
Failure_Flag = 1;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
bool Relay_CHx_Toggle(uint8_t CHx)
|
||||
{
|
||||
if(!Set_Toggle(CHx)){
|
||||
printf("Failed to Toggle CH%d!!!\r\n", CHx);
|
||||
Failure_Flag = 1;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
bool Relay_CHx(uint8_t CHx, bool State)
|
||||
{
|
||||
bool result = 0;
|
||||
if(State)
|
||||
result = Relay_Open(CHx);
|
||||
else
|
||||
result = Relay_Close(CHx);
|
||||
if(!result)
|
||||
Failure_Flag = 1;
|
||||
return result;
|
||||
}
|
||||
bool Relay_CHxs_PinState(uint8_t PinState)
|
||||
{
|
||||
if(!Set_EXIOS(PinState)){
|
||||
printf("Failed to set the relay status!!!\r\n");
|
||||
Failure_Flag = 1;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RelayFailTask(void *parameter) {
|
||||
while(1){
|
||||
if(Failure_Flag)
|
||||
{
|
||||
Failure_Flag = 0;
|
||||
printf("Error: Relay control failed!!!\r\n");
|
||||
RGB_Open_Time(60,0,0,5000,500);
|
||||
Buzzer_Open_Time(5000, 500);
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
void Relay_Init(void)
|
||||
{
|
||||
TCA9554PWR_Init(0x00);
|
||||
xTaskCreatePinnedToCore(
|
||||
RelayFailTask,
|
||||
"RelayFailTask",
|
||||
4096,
|
||||
NULL,
|
||||
3,
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
/******************************************************** Data Analysis ********************************************************/
|
||||
bool Relay_Flag[8] = {0}; // Relay current status flag
|
||||
void Relay_Analysis(uint8_t *buf,uint8_t Mode_Flag)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
if(Mode_Flag == Bluetooth_Mode)
|
||||
printf("Bluetooth Data :\r\n");
|
||||
else if(Mode_Flag == WIFI_Mode)
|
||||
printf("WIFI Data :\r\n");
|
||||
else if(Mode_Flag == MQTT_Mode)
|
||||
printf("MQTT Data :\r\n");
|
||||
else if(Mode_Flag == RS485_Mode)
|
||||
printf("RS485 Data :\r\n");
|
||||
switch(buf[0])
|
||||
{
|
||||
case CH1:
|
||||
ret = Relay_CHx_Toggle(GPIO_PIN_CH1); //Toggle the level status of the GPIO_PIN_CH1 pin
|
||||
if(ret){
|
||||
Relay_Flag[0] =! Relay_Flag[0];
|
||||
Buzzer_Open_Time(200, 0);
|
||||
if(Relay_Flag[0])
|
||||
printf("|*** Relay CH1 on ***|\r\n");
|
||||
else
|
||||
printf("|*** Relay CH1 off ***|\r\n");
|
||||
}
|
||||
break;
|
||||
case CH2:
|
||||
ret = Relay_CHx_Toggle(GPIO_PIN_CH2); //Toggle the level status of the GPIO_PIN_CH2 pin
|
||||
if(ret){
|
||||
Relay_Flag[1] =! Relay_Flag[1];
|
||||
Buzzer_Open_Time(200, 0);
|
||||
if(Relay_Flag[1])
|
||||
printf("|*** Relay CH2 on ***|\r\n");
|
||||
else
|
||||
printf("|*** Relay CH2 off ***|\r\n");
|
||||
}
|
||||
break;
|
||||
case CH3:
|
||||
ret = Relay_CHx_Toggle(GPIO_PIN_CH3); //Toggle the level status of the GPIO_PIN_CH3 pin
|
||||
if(ret){
|
||||
Relay_Flag[2] =! Relay_Flag[2];
|
||||
Buzzer_Open_Time(200, 0);
|
||||
if(Relay_Flag[2])
|
||||
printf("|*** Relay CH3 on ***|\r\n");
|
||||
else
|
||||
printf("|*** Relay CH3 off ***|\r\n");
|
||||
}
|
||||
break;
|
||||
case CH4:
|
||||
ret = Relay_CHx_Toggle(GPIO_PIN_CH4); //Toggle the level status of the GPIO_PIN_CH4 pin
|
||||
if(ret){
|
||||
Relay_Flag[3] =! Relay_Flag[3];
|
||||
Buzzer_Open_Time(200, 0);
|
||||
if(Relay_Flag[3])
|
||||
printf("|*** Relay CH4 on ***|\r\n");
|
||||
else
|
||||
printf("|*** Relay CH4 off ***|\r\n");
|
||||
}
|
||||
break;
|
||||
case CH5:
|
||||
ret = Relay_CHx_Toggle(GPIO_PIN_CH5); //Toggle the level status of the GPIO_PIN_CH5 pin
|
||||
if(ret){
|
||||
Relay_Flag[4] =! Relay_Flag[4];
|
||||
Buzzer_Open_Time(200, 0);
|
||||
if(Relay_Flag[4])
|
||||
printf("|*** Relay CH5 on ***|\r\n");
|
||||
else
|
||||
printf("|*** Relay CH5 off ***|\r\n");
|
||||
}
|
||||
break;
|
||||
case CH6:
|
||||
ret = Relay_CHx_Toggle(GPIO_PIN_CH6); //Toggle the level status of the GPIO_PIN_CH6 pin
|
||||
if(ret){
|
||||
Relay_Flag[5] =! Relay_Flag[5];
|
||||
Buzzer_Open_Time(200, 0);
|
||||
if(Relay_Flag[5])
|
||||
printf("|*** Relay CH6 on ***|\r\n");
|
||||
else
|
||||
printf("|*** Relay CH6 off ***|\r\n");
|
||||
}
|
||||
break;
|
||||
case CH7:
|
||||
ret = Relay_CHx_Toggle(GPIO_PIN_CH7); //Toggle the level status of the GPIO_PIN_CH6 pin
|
||||
if(ret){
|
||||
Relay_Flag[6] =! Relay_Flag[6];
|
||||
Buzzer_Open_Time(200, 0);
|
||||
if(Relay_Flag[6])
|
||||
printf("|*** Relay CH7 on ***|\r\n");
|
||||
else
|
||||
printf("|*** Relay CH7 off ***|\r\n");
|
||||
}
|
||||
break;
|
||||
case CH8:
|
||||
ret = Relay_CHx_Toggle(GPIO_PIN_CH8); //Toggle the level status of the GPIO_PIN_CH6 pin
|
||||
if(ret){
|
||||
Relay_Flag[7] =! Relay_Flag[7];
|
||||
Buzzer_Open_Time(200, 0);
|
||||
if(Relay_Flag[7])
|
||||
printf("|*** Relay CH8 on ***|\r\n");
|
||||
else
|
||||
printf("|*** Relay CH8 off ***|\r\n");
|
||||
}
|
||||
break;
|
||||
case ALL_ON:
|
||||
ret = Relay_CHxs_PinState(0xFF); // Turn on all relay
|
||||
if(ret){
|
||||
memset(Relay_Flag,1, sizeof(Relay_Flag));
|
||||
printf("|*** Relay ALL on ***|\r\n");
|
||||
Buzzer_Open_Time(500, 0);
|
||||
}
|
||||
|
||||
break;
|
||||
case ALL_OFF:
|
||||
ret = Relay_CHxs_PinState(0x00); // Turn off all relay
|
||||
if(ret){
|
||||
memset(Relay_Flag,0, sizeof(Relay_Flag));
|
||||
printf("|*** Relay ALL off ***|\r\n");
|
||||
Buzzer_Open_Time(500, 150);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("Note : Non-instruction data was received ! - %c\r\n", buf[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void Relay_Immediate(uint8_t CHx, bool State, uint8_t Mode_Flag)
|
||||
{
|
||||
if(!CHx || CHx > 8){
|
||||
printf("Relay_Immediate(function): Incoming parameter error!!!!\r\n");
|
||||
Failure_Flag = 1;
|
||||
}
|
||||
else{
|
||||
uint8_t ret = 0;
|
||||
if(Mode_Flag == DIN_Mode)
|
||||
printf("DIN Data :\r\n");
|
||||
else if(Mode_Flag == RTC_Mode)
|
||||
printf("RTC Data :\r\n");
|
||||
ret = Relay_CHx(CHx,State);
|
||||
if(ret){
|
||||
Relay_Flag[CHx-1] = State;
|
||||
Buzzer_Open_Time(200, 0);
|
||||
if(Relay_Flag[0])
|
||||
printf("|*** Relay CH%d on ***|\r\n",CHx);
|
||||
else
|
||||
printf("|*** Relay CH%d off ***|\r\n",CHx);
|
||||
}
|
||||
}
|
||||
}
|
||||
void Relay_Immediate_CHxn(Status_adjustment * Relay_n, uint8_t Mode_Flag)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
if(Mode_Flag == DIN_Mode)
|
||||
printf("DIN Data :\r\n");
|
||||
else if(Mode_Flag == RTC_Mode)
|
||||
printf("RTC Data :\r\n");
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if(Relay_n[i] == STATE_Open || Relay_n[i] == STATE_Close){
|
||||
Relay_Flag[i] = (bool)Relay_n[i];
|
||||
ret = Relay_CHx(i+1,Relay_n[i]);
|
||||
if(Relay_n[i] == STATE_Open)
|
||||
printf("|*** Relay CH%d on ***|\r\n",i+1);
|
||||
else if(Relay_n[i] == STATE_Close)
|
||||
printf("|*** Relay CH%d off ***|\r\n",i+1);
|
||||
}
|
||||
}
|
||||
Buzzer_Open_Time(200, 0);
|
||||
}
|
||||
|
||||
void Relay_Immediate_CHxs(uint8_t PinState, uint8_t Mode_Flag)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
if(Mode_Flag == DIN_Mode)
|
||||
printf("DIN Data :\r\n");
|
||||
else if(Mode_Flag == RTC_Mode)
|
||||
printf("RTC Data :\r\n");
|
||||
for (int i = 0; i < 8; i++) {
|
||||
Relay_Flag[i] = (PinState >> i) & 0x01; // 提取每一位并赋值
|
||||
}
|
||||
ret = Relay_CHxs_PinState(PinState);
|
||||
if(ret){
|
||||
for (int j = 0; j < 8; j++) {
|
||||
if(Relay_Flag[j])
|
||||
printf("|*** Relay CH%d on ***|\r\n",j+1);
|
||||
else
|
||||
printf("|*** Relay CH%d off ***|\r\n",j+1);
|
||||
}
|
||||
Buzzer_Open_Time(200, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Relay_Immediate_CHxs(function): Relay control failure!!!!\r\n");
|
||||
Failure_Flag = 1;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "WS_TCA9554PWR.h"
|
||||
#include <HardwareSerial.h> // Reference the ESP32 built-in serial port library
|
||||
#include "WS_GPIO.h"
|
||||
|
||||
|
||||
/************************************************************* I/O *************************************************************/
|
||||
#define Relay_Number_MAX 8
|
||||
#define GPIO_PIN_CH1 EXIO_PIN1 // CH1 Control GPIO
|
||||
#define GPIO_PIN_CH2 EXIO_PIN2 // CH2 Control GPIO
|
||||
#define GPIO_PIN_CH3 EXIO_PIN3 // CH3 Control GPIO
|
||||
#define GPIO_PIN_CH4 EXIO_PIN4 // CH4 Control GPIO
|
||||
#define GPIO_PIN_CH5 EXIO_PIN5 // CH5 Control GPIO
|
||||
#define GPIO_PIN_CH6 EXIO_PIN6 // CH6 Control GPIO
|
||||
#define GPIO_PIN_CH7 EXIO_PIN7 // CH7 Control GPIO
|
||||
#define GPIO_PIN_CH8 EXIO_PIN8 // CH8 Control GPIO
|
||||
|
||||
|
||||
#define CH1 '1' // CH1 Enabled Instruction Hex : 0x31
|
||||
#define CH2 '2' // CH2 Enabled Instruction Hex : 0x32
|
||||
#define CH3 '3' // CH3 Enabled Instruction Hex : 0x33
|
||||
#define CH4 '4' // CH4 Enabled Instruction Hex : 0x34
|
||||
#define CH5 '5' // CH5 Enabled Instruction Hex : 0x35
|
||||
#define CH6 '6' // CH6 Enabled Instruction Hex : 0x36
|
||||
#define CH7 '7' // CH5 Enabled Instruction Hex : 0x37
|
||||
#define CH8 '8' // CH6 Enabled Instruction Hex : 0x38
|
||||
#define ALL_ON '9' // Start all channel instructions Hex : 0x39
|
||||
#define ALL_OFF '0' // Disable all channel instructions Hex : 0x30
|
||||
|
||||
#define DIN_Mode 1
|
||||
#define RS485_Mode 2 // Used to distinguish data sources
|
||||
#define Bluetooth_Mode 3
|
||||
#define WIFI_Mode 4
|
||||
#define MQTT_Mode 5
|
||||
#define RTC_Mode 6
|
||||
|
||||
typedef enum {
|
||||
STATE_Close = 0, // Closs Relay
|
||||
STATE_Open = 1, // Open Relay
|
||||
STATE_Retain = 2, // Stay in place
|
||||
} Status_adjustment;
|
||||
|
||||
extern bool Relay_Flag[8]; // Relay current status flag
|
||||
|
||||
void Relay_Init(void);
|
||||
bool Relay_Close(uint8_t CHx);
|
||||
bool Relay_Open(uint8_t CHx);
|
||||
bool Relay_CHx_Toggle(uint8_t CHx);
|
||||
bool Relay_CHx(uint8_t CHx, bool State);
|
||||
bool Relay_CHxs_PinState(uint8_t PinState);
|
||||
|
||||
void Relay_Analysis(uint8_t *buf,uint8_t Mode_Flag);
|
||||
void Relay_Immediate(uint8_t CHx, bool State, uint8_t Mode_Flag);
|
||||
void Relay_Immediate_CHxs(uint8_t PinState, uint8_t Mode_Flag);
|
||||
void Relay_Immediate_CHxn(Status_adjustment * Relay_n, uint8_t Mode_Flag);
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "WS_RS485.h"
|
||||
#include "RS485_driver.h"
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <endian.h>
|
||||
@@ -69,6 +69,7 @@ namespace drivers
|
||||
data.resize(avail);
|
||||
m_serial->readBytesUntil(ch, data.data(), avail);
|
||||
data.shrink_to_fit();
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@@ -85,7 +86,7 @@ namespace drivers
|
||||
{
|
||||
constexpr uint8_t func = 0x01;
|
||||
log_d("Read coils: dev[%02x], reg[%04x], num[%d]", device, reg, num);
|
||||
readBinary(func, device, reg, num, coils);
|
||||
return readBinary(func, device, reg, num, coils);
|
||||
}
|
||||
|
||||
// Func 0x02
|
||||
@@ -93,7 +94,7 @@ namespace drivers
|
||||
{
|
||||
constexpr uint8_t func = 0x01;
|
||||
log_d("Read multi inputs: dev[%02x], reg[%04x], num[%d]", device, reg, num);
|
||||
readBinary(func, device, reg, num, inputs);
|
||||
return readBinary(func, device, reg, num, inputs);
|
||||
}
|
||||
|
||||
// Func 0x03
|
||||
@@ -101,7 +102,7 @@ namespace drivers
|
||||
{
|
||||
constexpr uint8_t func = 0x03;
|
||||
log_d("Read multi holding registers: dev[%02x], reg[%04x], num[%d]", device, reg, num);
|
||||
readInteger(func, device, reg, num, values);
|
||||
return readInteger(func, device, reg, num, values);
|
||||
}
|
||||
|
||||
// Func 0x04
|
||||
@@ -109,7 +110,7 @@ namespace drivers
|
||||
{
|
||||
constexpr uint8_t func = 0x04;
|
||||
log_d("Read multi input registers: dev[%02x], reg[%04x], num[%d]", device, reg, num);
|
||||
readInteger(func, device, reg, num, values);
|
||||
return readInteger(func, device, reg, num, values);
|
||||
}
|
||||
|
||||
// Func 0x05
|
||||
@@ -192,6 +193,7 @@ namespace drivers
|
||||
bitNum++;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const bool MODBUS::readInteger(const uint8_t func, const uint8_t device, const uint16_t reg, const uint16_t num, std::vector<uint16_t> &out)
|
||||
@@ -233,6 +235,7 @@ namespace drivers
|
||||
const uint16_t val(0xFFFF & ((hi << 8) | lo));
|
||||
out.push_back(be16toh(val));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const bool MODBUS::writeBinary(const uint8_t func, const uint8_t device, const uint16_t reg, const uint16_t bits, const std::vector<bool> &in)
|
||||
@@ -313,7 +316,7 @@ namespace drivers
|
||||
// compute crc for header + data
|
||||
m_crc.reset();
|
||||
m_crc.add((uint8_t *)&header, headerBytes); // exclude last two bytes of crc
|
||||
const uint16_t crc(htole16(m_crc.getCRC()));
|
||||
const uint16_t crc(htole16(m_crc.calc()));
|
||||
|
||||
std::vector<uint8_t> dataOut(headerBytes + crcBytes, 0);
|
||||
std::memcpy(dataOut.data(), &header, headerBytes);
|
||||
@@ -344,7 +347,7 @@ namespace drivers
|
||||
m_crc.reset();
|
||||
m_crc.add((uint8_t *)&header, headerBytes); // add the request excluding the CRC code
|
||||
m_crc.add((uint8_t *)dataBe.data(), dataBytes);
|
||||
const uint16_t crc(htole16(m_crc.getCRC()));
|
||||
const uint16_t crc(htole16(m_crc.calc()));
|
||||
|
||||
std::vector<uint8_t> dataOut;
|
||||
dataOut.resize(headerBytes + dataBytes + crcBytes); // header message + data values + crc code
|
||||
@@ -359,7 +362,7 @@ namespace drivers
|
||||
// compute crc of current message
|
||||
m_crc.reset();
|
||||
m_crc.add(data.data(), data.size());
|
||||
const uint16_t computedCrc(m_crc.getCRC());
|
||||
const uint16_t computedCrc(m_crc.calc());
|
||||
// extract crc from response
|
||||
const uint16_t size(data.size());
|
||||
const uint8_t crcLo(data.at(size - 2));
|
||||
@@ -16,14 +16,6 @@
|
||||
#define Extension_ALL_ON 9 // Expansion ALL ON
|
||||
#define Extension_ALL_OFF 10 // Expansion ALL OFF
|
||||
|
||||
void SetData(uint8_t *data, size_t length); // Send data from the RS485
|
||||
void ReadData(uint8_t *buf, uint8_t length); // Data is received over RS485
|
||||
|
||||
void RS485_Analysis(uint8_t *buf); // External relay control
|
||||
void RS485_Init(); // Example Initialize the system serial port and RS485
|
||||
void RS485_Loop(); // Read RS485 data, parse and control relays
|
||||
void RS485Task(void *parameter);
|
||||
|
||||
namespace drivers
|
||||
{
|
||||
class RS485
|
||||
Reference in New Issue
Block a user