Merge pull request #151 from MalteSchm/huawei_lint_pin_mgr_fixes
Huawei lint pin mgr fixes
This commit is contained in:
commit
ebaf5c4565
@ -75,14 +75,14 @@ public:
|
|||||||
void setPower(bool power);
|
void setPower(bool power);
|
||||||
|
|
||||||
RectifierParameters_t * get();
|
RectifierParameters_t * get();
|
||||||
unsigned long getLastUpdate();
|
uint32_t getLastUpdate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void sendRequest();
|
void sendRequest();
|
||||||
void onReceive(uint8_t* frame, uint8_t len);
|
void onReceive(uint8_t* frame, uint8_t len);
|
||||||
|
|
||||||
unsigned long previousMillis;
|
uint32_t previousMillis;
|
||||||
unsigned long lastUpdate;
|
uint32_t lastUpdate;
|
||||||
RectifierParameters_t _rp;
|
RectifierParameters_t _rp;
|
||||||
|
|
||||||
SPIClass *spi;
|
SPIClass *spi;
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "Huawei_can.h"
|
#include "Huawei_can.h"
|
||||||
#include "MessageOutput.h"
|
#include "MessageOutput.h"
|
||||||
|
#include "Configuration.h"
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <mcp_can.h>
|
#include <mcp_can.h>
|
||||||
|
|
||||||
@ -14,6 +15,12 @@ HuaweiCanClass HuaweiCan;
|
|||||||
void HuaweiCanClass::init(uint8_t huawei_miso, uint8_t huawei_mosi, uint8_t huawei_clk, uint8_t huawei_irq, uint8_t huawei_cs, uint8_t huawei_power)
|
void HuaweiCanClass::init(uint8_t huawei_miso, uint8_t huawei_mosi, uint8_t huawei_clk, uint8_t huawei_irq, uint8_t huawei_cs, uint8_t huawei_power)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
|
if (!config.Huawei_Enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
spi = new SPIClass(VSPI);
|
spi = new SPIClass(VSPI);
|
||||||
spi->begin(huawei_clk, huawei_miso, huawei_mosi, huawei_cs);
|
spi->begin(huawei_clk, huawei_miso, huawei_mosi, huawei_cs);
|
||||||
pinMode(huawei_cs, OUTPUT);
|
pinMode(huawei_cs, OUTPUT);
|
||||||
@ -43,7 +50,7 @@ RectifierParameters_t * HuaweiCanClass::get()
|
|||||||
return &_rp;
|
return &_rp;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long HuaweiCanClass::getLastUpdate()
|
uint32_t HuaweiCanClass::getLastUpdate()
|
||||||
{
|
{
|
||||||
return lastUpdate;
|
return lastUpdate;
|
||||||
}
|
}
|
||||||
@ -142,10 +149,16 @@ void HuaweiCanClass::onReceive(uint8_t* frame, uint8_t len)
|
|||||||
void HuaweiCanClass::loop()
|
void HuaweiCanClass::loop()
|
||||||
{
|
{
|
||||||
|
|
||||||
long unsigned int rxId;
|
INT32U rxId;
|
||||||
unsigned char len = 0;
|
unsigned char len = 0;
|
||||||
unsigned char rxBuf[8];
|
unsigned char rxBuf[8];
|
||||||
|
|
||||||
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
|
if (!config.Huawei_Enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(!digitalRead(_huawei_irq)) // If CAN_INT pin is low, read receive buffer
|
if(!digitalRead(_huawei_irq)) // If CAN_INT pin is low, read receive buffer
|
||||||
{
|
{
|
||||||
CAN->readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
|
CAN->readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
|
||||||
|
|||||||
@ -27,9 +27,19 @@ void PowerMeterClass::init()
|
|||||||
|
|
||||||
CONFIG_T& config = Configuration.get();
|
CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
|
if (config.PowerMeter_Enabled && config.PowerMeter_Source == 0) {
|
||||||
|
if (strlen(config.PowerMeter_MqttTopicPowerMeter1) > 0) {
|
||||||
MqttSettings.subscribe(config.PowerMeter_MqttTopicPowerMeter1, 0, std::bind(&PowerMeterClass::onMqttMessage, this, _1, _2, _3, _4, _5, _6));
|
MqttSettings.subscribe(config.PowerMeter_MqttTopicPowerMeter1, 0, std::bind(&PowerMeterClass::onMqttMessage, this, _1, _2, _3, _4, _5, _6));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(config.PowerMeter_MqttTopicPowerMeter2) > 0) {
|
||||||
MqttSettings.subscribe(config.PowerMeter_MqttTopicPowerMeter2, 0, std::bind(&PowerMeterClass::onMqttMessage, this, _1, _2, _3, _4, _5, _6));
|
MqttSettings.subscribe(config.PowerMeter_MqttTopicPowerMeter2, 0, std::bind(&PowerMeterClass::onMqttMessage, this, _1, _2, _3, _4, _5, _6));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(config.PowerMeter_MqttTopicPowerMeter3) > 0) {
|
||||||
MqttSettings.subscribe(config.PowerMeter_MqttTopicPowerMeter3, 0, std::bind(&PowerMeterClass::onMqttMessage, this, _1, _2, _3, _4, _5, _6));
|
MqttSettings.subscribe(config.PowerMeter_MqttTopicPowerMeter3, 0, std::bind(&PowerMeterClass::onMqttMessage, this, _1, _2, _3, _4, _5, _6));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mqttInitDone = true;
|
mqttInitDone = true;
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
#include "WebApi_Huawei.h"
|
#include "WebApi_Huawei.h"
|
||||||
#include "Huawei_can.h"
|
#include "Huawei_can.h"
|
||||||
#include "Configuration.h"
|
#include "Configuration.h"
|
||||||
|
#include "MessageOutput.h"
|
||||||
|
#include "PinMapping.h"
|
||||||
#include "WebApi.h"
|
#include "WebApi.h"
|
||||||
#include "WebApi_errors.h"
|
#include "WebApi_errors.h"
|
||||||
#include <AsyncJson.h>
|
#include <AsyncJson.h>
|
||||||
@ -251,5 +253,17 @@ void WebApiHuaweiClass::onAdminPost(AsyncWebServerRequest* request)
|
|||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|
||||||
|
const PinMapping_t& pin = PinMapping.get();
|
||||||
|
if (config.Huawei_Enabled) {
|
||||||
|
MessageOutput.println(F("Initialize Huawei AC charger interface... "));
|
||||||
|
if (PinMapping.isValidHuaweiConfig()) {
|
||||||
|
MessageOutput.printf("Huawei AC-charger miso = %d, mosi = %d, clk = %d, irq = %d, cs = %d, power_pin = %d\r\n", pin.huawei_miso, pin.huawei_mosi, pin.huawei_clk, pin.huawei_irq, pin.huawei_cs, pin.huawei_power);
|
||||||
|
HuaweiCan.init(pin.huawei_miso, pin.huawei_mosi, pin.huawei_clk, pin.huawei_irq, pin.huawei_cs, pin.huawei_power);
|
||||||
|
MessageOutput.println(F("done"));
|
||||||
|
} else {
|
||||||
|
MessageOutput.println(F("Invalid pin config"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HuaweiCan.setPower(config.Huawei_Enabled);
|
HuaweiCan.setPower(config.Huawei_Enabled);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,6 +77,14 @@ void WebApiDeviceClass::onDeviceAdminGet(AsyncWebServerRequest* request)
|
|||||||
batteryPinObj[F("rx")] = pin.battery_rx;
|
batteryPinObj[F("rx")] = pin.battery_rx;
|
||||||
batteryPinObj[F("tx")] = pin.battery_tx;
|
batteryPinObj[F("tx")] = pin.battery_tx;
|
||||||
|
|
||||||
|
JsonObject huaweiPinObj = curPin.createNestedObject("huawei");
|
||||||
|
huaweiPinObj[F("miso")] = pin.huawei_miso;
|
||||||
|
huaweiPinObj[F("mosi")] = pin.huawei_mosi;
|
||||||
|
huaweiPinObj[F("clk")] = pin.huawei_clk;
|
||||||
|
huaweiPinObj[F("irq")] = pin.huawei_irq;
|
||||||
|
huaweiPinObj[F("cs")] = pin.huawei_cs;
|
||||||
|
huaweiPinObj[F("power")] = pin.huawei_power;
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user