UExt interfaces simplified and renamed to Ext
This commit is contained in:
@@ -14,54 +14,54 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "uext.h"
|
||||
#include "ext.h"
|
||||
#include <algorithm>
|
||||
|
||||
// we use code to self register objects at construction time.
|
||||
// It relies on the fact that initially this pointer will be initialized
|
||||
// with NULL ! This is only true for global variables or static members of classes
|
||||
// so this must remain a static class member
|
||||
std::vector<UExtInterface*>* UExtInterfaceManager::interfaces;
|
||||
std::vector<ExtInterface*>* ExtManager::interfaces;
|
||||
|
||||
// run the respective function on all objects in the "devices" list
|
||||
// use the c++11 lambda expressions here for the for_each loop, keeps things compact
|
||||
|
||||
void UExtInterfaceManager::process_asap() {
|
||||
for_each(std::begin(*interfaces),std::end(*interfaces), [](UExtInterface* tsif) {
|
||||
void ExtManager::process_asap() {
|
||||
for_each(std::begin(*interfaces),std::end(*interfaces), [](ExtInterface* tsif) {
|
||||
tsif->process_asap();
|
||||
});
|
||||
}
|
||||
|
||||
void UExtInterfaceManager::enable() {
|
||||
for_each(std::begin(*interfaces),std::end(*interfaces), [](UExtInterface* tsif) {
|
||||
void ExtManager::enable_all() {
|
||||
for_each(std::begin(*interfaces),std::end(*interfaces), [](ExtInterface* tsif) {
|
||||
tsif->enable();
|
||||
});
|
||||
}
|
||||
|
||||
void UExtInterfaceManager::process_1s() {
|
||||
for_each(std::begin(*interfaces),std::end(*interfaces), [](UExtInterface* tsif) {
|
||||
void ExtManager::process_1s() {
|
||||
for_each(std::begin(*interfaces),std::end(*interfaces), [](ExtInterface* tsif) {
|
||||
tsif->process_1s();
|
||||
});
|
||||
}
|
||||
|
||||
void UExtInterfaceManager::check_list() {
|
||||
if (UExtInterfaceManager::interfaces == NULL)
|
||||
void ExtManager::check_list() {
|
||||
if (ExtManager::interfaces == NULL)
|
||||
{
|
||||
UExtInterfaceManager::interfaces = new std::vector<UExtInterface*>;
|
||||
ExtManager::interfaces = new std::vector<ExtInterface*>;
|
||||
}
|
||||
}
|
||||
|
||||
void UExtInterfaceManager::add_ext(UExtInterface* member) {
|
||||
void ExtManager::add_ext(ExtInterface* member) {
|
||||
check_list();
|
||||
interfaces->push_back(member);
|
||||
}
|
||||
|
||||
UExtInterfaceManager::UExtInterfaceManager() {
|
||||
ExtManager::ExtManager() {
|
||||
check_list();
|
||||
}
|
||||
|
||||
UExtInterface::UExtInterface() {
|
||||
uext.add_ext(this);
|
||||
ExtInterface::ExtInterface() {
|
||||
ext_mgr.add_ext(this);
|
||||
}
|
||||
|
||||
UExtInterfaceManager uext;
|
||||
ExtManager ext_mgr;
|
||||
@@ -14,31 +14,30 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef UEXT_H
|
||||
#define UEXT_H
|
||||
#ifndef EXT_H_
|
||||
#define EXT_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @brief
|
||||
* Communication interfaces connected to UEXT port
|
||||
* @brief Classes to handle EXTensions and EXTernal communication interfaces
|
||||
*/
|
||||
|
||||
class UExtInterface
|
||||
class ExtInterface
|
||||
{
|
||||
public:
|
||||
virtual void process_asap() {};
|
||||
ExtInterface();
|
||||
virtual void process_asap() {};
|
||||
virtual void process_1s() {};
|
||||
virtual void enable() {};
|
||||
|
||||
UExtInterface();
|
||||
private:
|
||||
};
|
||||
|
||||
class UExtInterfaceManager
|
||||
class ExtManager
|
||||
{
|
||||
public:
|
||||
ExtManager();
|
||||
|
||||
/** UEXT interface process function
|
||||
*
|
||||
* This function is called in each main loop, as soon as all other tasks finished.
|
||||
@@ -56,21 +55,19 @@ class UExtInterfaceManager
|
||||
*
|
||||
* This function is called only once at startup.
|
||||
*/
|
||||
virtual void enable();
|
||||
virtual void enable_all();
|
||||
|
||||
/**
|
||||
* Adds an UExtInterface object to the list of managed extensions,
|
||||
* automatically called by UExtInterface objects during construction
|
||||
* Adds an ExtInterface object to the list of managed extensions,
|
||||
* automatically called by ExtInterface objects during construction
|
||||
*/
|
||||
static void add_ext(UExtInterface*);
|
||||
|
||||
UExtInterfaceManager();
|
||||
static void add_ext(ExtInterface*);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Stores list of all UExtInterface objects
|
||||
* Stores list of all ExtInterface objects
|
||||
*/
|
||||
static std::vector<UExtInterface*>* interfaces;
|
||||
static std::vector<ExtInterface*>* interfaces;
|
||||
|
||||
/**
|
||||
* Makes sure there is an internal interfacts vector created, does nothing if it exists
|
||||
@@ -78,6 +75,6 @@ class UExtInterfaceManager
|
||||
static void check_list();
|
||||
};
|
||||
|
||||
extern UExtInterfaceManager uext;
|
||||
extern ExtManager ext_mgr;
|
||||
|
||||
#endif /* UEXT_H */
|
||||
#endif /* EXT_H_ */
|
||||
@@ -16,16 +16,26 @@
|
||||
|
||||
#ifdef __MBED__
|
||||
|
||||
#include "main.h"
|
||||
#include "config.h"
|
||||
|
||||
#ifdef OLED_ENABLED // otherwise don't compile code to reduce firmware size
|
||||
|
||||
#include "uext_oled.h"
|
||||
#include "pcb.h"
|
||||
#include "ext/ext.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "pcb.h"
|
||||
#include "Adafruit_SSD1306.h"
|
||||
|
||||
static UExtOled uext_oled; // local instance, will self register itself
|
||||
// implement specific extension inherited from ExtInterface
|
||||
class ExtOled: public ExtInterface
|
||||
{
|
||||
public:
|
||||
ExtOled() {};
|
||||
void enable();
|
||||
void process_1s();
|
||||
};
|
||||
|
||||
static ExtOled ext_oled; // local instance, will self register itself
|
||||
|
||||
const unsigned char bmp_load [] = {
|
||||
0x20, 0x22, 0x04, 0x70, 0x88, 0x8B, 0x88, 0x70, 0x04, 0x22, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
@@ -49,9 +59,8 @@ const unsigned char bmp_disconnected [] = {
|
||||
I2C i2c(PIN_UEXT_SDA, PIN_UEXT_SCL);
|
||||
Adafruit_SSD1306_I2c oled(i2c, PIN_UEXT_SSEL, 0x78, 64, 128);
|
||||
|
||||
UExtOled::UExtOled() {}
|
||||
|
||||
void UExtOled::enable() {
|
||||
void ExtOled::enable()
|
||||
{
|
||||
#ifdef PIN_UEXT_DIS
|
||||
DigitalOut uext_dis(PIN_UEXT_DIS);
|
||||
uext_dis = 0;
|
||||
@@ -84,9 +93,8 @@ void UExtOled::enable() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void UExtOled::process_asap() {}
|
||||
|
||||
void UExtOled::process_1s() {
|
||||
void ExtOled::process_1s()
|
||||
{
|
||||
oled.clearDisplay();
|
||||
|
||||
oled.drawBitmap(6, 0, bmp_pv_panel, 16, 16, 1);
|
||||
@@ -16,48 +16,47 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/** UEXT interface description template
|
||||
/** EXT interface description template
|
||||
*
|
||||
* The UEXT port can be used to connect several different extension modules to the charge controller.
|
||||
*
|
||||
* Only one interface can be used at a time. The interfaces are selected via #define in config.h
|
||||
*
|
||||
* Use this file as a template for custom interfaces. If the UEXT port is not used, UEXT_DUMMY_ENABLED
|
||||
* has to be defined in config.h to implement the functions.
|
||||
*/
|
||||
|
||||
// Only compile if this UEXT interface is enabled in config.h
|
||||
#ifdef UEXT_DUMMY_ENABLED
|
||||
// Only compile if this EXT interface is enabled in config.h
|
||||
#ifdef EXT_TEMPLATE_ENABLED
|
||||
|
||||
// implement specific extension inherited from ExtInterface
|
||||
class ExtTemplate: public ExtInterface
|
||||
{
|
||||
public:
|
||||
ExtTemplate();
|
||||
void enable();
|
||||
void process_asap();
|
||||
void process_1s();
|
||||
};
|
||||
|
||||
|
||||
#include "uext_template.h"
|
||||
|
||||
static UExtDummy uext_dummy; // local instance, will self register itself
|
||||
static ExtTemplate ext_template; // local instance, will self register itself
|
||||
|
||||
/**
|
||||
* Constructor, place basic initialization here, if necessary
|
||||
*/
|
||||
UExtDummy::UExtDummy() {}
|
||||
|
||||
ExtTemplate::ExtTemplate() {}
|
||||
|
||||
/**
|
||||
* Enable operation, place start of use code here, if necessary
|
||||
*/
|
||||
void UExtDummy::enable() {
|
||||
#ifdef PIN_UEXT_DIS
|
||||
DigitalOut uext_dis(PIN_UEXT_DIS);
|
||||
uext_dis = 0;
|
||||
#endif
|
||||
void ExtTemplate::enable() {
|
||||
// add you init functions here
|
||||
}
|
||||
|
||||
void UExtDummy::process_asap(void) {
|
||||
void ExtTemplate::process_asap(void) {
|
||||
// add functions to be called as soon as possible during each loop in main function
|
||||
}
|
||||
|
||||
void UExtDummy::process_1s(void) {
|
||||
void ExtTemplate::process_1s(void) {
|
||||
// add functions to be called every second here
|
||||
}
|
||||
|
||||
#endif /* UEXT_DUMMY_ENABLED */
|
||||
#endif /* EXT_TEMPLATE_ENABLED */
|
||||
@@ -1,39 +0,0 @@
|
||||
/* LibreSolar charge controller firmware
|
||||
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef UEXT_OLED_H
|
||||
#define UEXT_OLED_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef OLED_ENABLED
|
||||
#include "uext.h"
|
||||
|
||||
class UExtOled: public UExtInterface
|
||||
{
|
||||
public:
|
||||
UExtOled();
|
||||
|
||||
void process_asap();
|
||||
void process_1s();
|
||||
|
||||
void enable();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* OLED_ENABLED */
|
||||
#endif
|
||||
@@ -1,39 +0,0 @@
|
||||
/* LibreSolar charge controller firmware
|
||||
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef UEX_TEMPLATE_H
|
||||
#define UEXT_TEMPLATE_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef UEXT_DUMMY_ENABLED
|
||||
#include "uext.h"
|
||||
|
||||
class UExtDummy: public UExtInterface
|
||||
{
|
||||
public:
|
||||
UExtDummy();
|
||||
|
||||
void process_asap();
|
||||
void process_1s();
|
||||
|
||||
void enable();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* UEXT_DUMMY_ENABLED */
|
||||
#endif
|
||||
@@ -1,39 +0,0 @@
|
||||
/* LibreSolar charge controller firmware
|
||||
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef UEXT_WIFI_H
|
||||
#define UEXT_WIFI_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef WIFI_ENABLED
|
||||
#include "uext.h"
|
||||
|
||||
class UExtWifi: public UExtInterface
|
||||
{
|
||||
public:
|
||||
UExtWifi();
|
||||
|
||||
void process_asap();
|
||||
void process_1s();
|
||||
|
||||
void enable();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* WIFI_ENABLED */
|
||||
#endif
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
#ifdef WIFI_ENABLED
|
||||
|
||||
#include "uext/uext_wifi.h"
|
||||
|
||||
#include "load.h"
|
||||
#include "thingset.h"
|
||||
#include <inttypes.h>
|
||||
@@ -160,20 +158,27 @@ int wifi_reset(void)
|
||||
return res;
|
||||
}
|
||||
|
||||
static UExtWifi uext_wifi; // local instance, will self register itself
|
||||
// implement specific extension inherited from ExtInterface
|
||||
class ExtWifi: public ExtInterface
|
||||
{
|
||||
public:
|
||||
ExtWifi() {};
|
||||
void enable();
|
||||
void process_1s();
|
||||
};
|
||||
|
||||
UExtWifi::UExtWifi() {}
|
||||
static ExtWifi ext_wifi; // local instance, will self register itself
|
||||
|
||||
void UExtWifi::enable() {
|
||||
void ExtWifi::enable()
|
||||
{
|
||||
#ifdef PIN_UEXT_DIS
|
||||
DigitalOut uext_dis(PIN_UEXT_DIS);
|
||||
uext_dis = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void UExtWifi::process_asap(void) {}
|
||||
|
||||
void UExtWifi::process_1s() {
|
||||
void ExtWifi::process_1s()
|
||||
{
|
||||
static WifiState state = STATE_WIFI_RESET;
|
||||
static int error_counter = 0;
|
||||
|
||||
+4
-4
@@ -33,7 +33,7 @@
|
||||
#include "pwm_switch.h" // PWM charge controller
|
||||
#include "bat_charger.h" // battery settings and charger state machine
|
||||
#include "adc_dma.h" // ADC using DMA and conversion to measurement values
|
||||
#include "ext/uext.h" // communication interfaces, displays, etc. in UEXT connector
|
||||
#include "ext/ext.h" // communication interfaces, displays, etc. in UEXT connector
|
||||
#include "eeprom.h" // external I2C EEPROM
|
||||
#include "load.h" // load and USB output management
|
||||
#include "leds.h" // LED switching using charlieplexing
|
||||
@@ -116,7 +116,7 @@ int main()
|
||||
// Communication interfaces
|
||||
ts_interfaces.enable();
|
||||
|
||||
uext.enable();
|
||||
ext_mgr.enable_all();
|
||||
init_watchdog(10); // 10s should be enough for communication ports
|
||||
|
||||
solar_terminal.init_solar();
|
||||
@@ -142,7 +142,7 @@ int main()
|
||||
while (1) {
|
||||
|
||||
ts_interfaces.process_asap();
|
||||
uext.process_asap();
|
||||
ext_mgr.process_asap();
|
||||
|
||||
time_t now = timestamp;
|
||||
if (now >= last_call + 1 || now < last_call) {
|
||||
@@ -163,7 +163,7 @@ int main()
|
||||
leds_update_1s();
|
||||
leds_update_soc(charger.soc, dev_stat.has_error(ERR_LOAD_LOW_SOC));
|
||||
|
||||
uext.process_1s();
|
||||
ext_mgr.process_1s();
|
||||
ts_interfaces.process_1s();
|
||||
|
||||
last_call = now;
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@
|
||||
#include "pwm_switch.h" // PWM charge controller
|
||||
#include "bat_charger.h" // battery settings and charger state machine
|
||||
#include "adc_dma.h" // ADC using DMA and conversion to measurement values
|
||||
#include "ext/uext.h" // communication interfaces, displays, etc. in UEXT connector
|
||||
#include "ext/ext.h" // communication interfaces, displays, etc. in UEXT connector
|
||||
#include "eeprom.h" // external I2C EEPROM
|
||||
#include "load.h" // load and USB output management
|
||||
#include "leds.h" // LED switching using charlieplexing
|
||||
|
||||
Reference in New Issue
Block a user