Remove unused ExtInterface and ExtMgr
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
target_sources(app PRIVATE
|
||||
ext.cpp
|
||||
oled.cpp
|
||||
serial.cpp
|
||||
can.cpp
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Martin Jäger / Libre Solar
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "ext.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
// necessary for PlatformIO debug session
|
||||
void std::__throw_bad_alloc()
|
||||
{
|
||||
while (true) {}
|
||||
}
|
||||
|
||||
// necessary to compile Zephyr v2.2
|
||||
void std::__throw_length_error(char const*)
|
||||
{
|
||||
while (true) {}
|
||||
}
|
||||
|
||||
// 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<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 ExtManager::process_asap()
|
||||
{
|
||||
for_each(std::begin(*interfaces),std::end(*interfaces), [](ExtInterface* tsif) {
|
||||
tsif->process_asap();
|
||||
});
|
||||
}
|
||||
|
||||
void ExtManager::enable_all()
|
||||
{
|
||||
for_each(std::begin(*interfaces),std::end(*interfaces), [](ExtInterface* tsif) {
|
||||
tsif->enable();
|
||||
});
|
||||
}
|
||||
|
||||
void ExtManager::process_1s()
|
||||
{
|
||||
for_each(std::begin(*interfaces),std::end(*interfaces), [](ExtInterface* tsif) {
|
||||
tsif->process_1s();
|
||||
});
|
||||
}
|
||||
|
||||
void ExtManager::check_list()
|
||||
{
|
||||
if (ExtManager::interfaces == NULL) {
|
||||
ExtManager::interfaces = new std::vector<ExtInterface*>;
|
||||
}
|
||||
}
|
||||
|
||||
void ExtManager::add_ext(ExtInterface* member)
|
||||
{
|
||||
check_list();
|
||||
interfaces->push_back(member);
|
||||
}
|
||||
|
||||
ExtManager::ExtManager()
|
||||
{
|
||||
check_list();
|
||||
}
|
||||
|
||||
ExtInterface::ExtInterface()
|
||||
{
|
||||
ext_mgr.add_ext(this);
|
||||
}
|
||||
|
||||
ExtManager ext_mgr;
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Martin Jäger / Libre Solar
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef EXT_H_
|
||||
#define EXT_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @brief Classes to handle EXTensions and EXTernal communication interfaces
|
||||
*/
|
||||
|
||||
class ExtInterface
|
||||
{
|
||||
public:
|
||||
ExtInterface();
|
||||
virtual void process_asap() {};
|
||||
virtual void process_1s() {};
|
||||
virtual void enable() {};
|
||||
};
|
||||
|
||||
class ExtManager
|
||||
{
|
||||
public:
|
||||
ExtManager();
|
||||
|
||||
/** UEXT interface process function
|
||||
*
|
||||
* This function is called in each main loop, as soon as all other tasks finished.
|
||||
*/
|
||||
virtual void process_asap();
|
||||
|
||||
/** UEXT interface process function
|
||||
*
|
||||
* This function is called every second, if no other task was blocking for a longer time.
|
||||
* It should be used for state machines, etc.
|
||||
*/
|
||||
virtual void process_1s();
|
||||
|
||||
/* UEXT interface initialization
|
||||
*
|
||||
* This function is called only once at startup.
|
||||
*/
|
||||
virtual void enable_all();
|
||||
|
||||
/**
|
||||
* Adds an ExtInterface object to the list of managed extensions,
|
||||
* automatically called by ExtInterface objects during construction
|
||||
*/
|
||||
static void add_ext(ExtInterface*);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Stores list of all ExtInterface objects
|
||||
*/
|
||||
static std::vector<ExtInterface*>* interfaces;
|
||||
|
||||
/**
|
||||
* Makes sure there is an internal interfacts vector created, does nothing if it exists
|
||||
*/
|
||||
static void check_list();
|
||||
};
|
||||
|
||||
extern ExtManager ext_mgr;
|
||||
|
||||
#endif /* EXT_H_ */
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Martin Jäger / Libre Solar
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/** EXT interface description template
|
||||
*
|
||||
* The UEXT port can be used to connect several different extension modules to the charge controller.
|
||||
*
|
||||
* 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 EXT interface is enabled in config.h
|
||||
#ifdef CONFIG_EXT_TEMPLATE_ENABLED
|
||||
|
||||
// implement specific extension inherited from ExtInterface
|
||||
class ExtTemplate: public ExtInterface
|
||||
{
|
||||
public:
|
||||
ExtTemplate();
|
||||
void enable();
|
||||
void process_asap();
|
||||
void process_1s();
|
||||
};
|
||||
|
||||
static ExtTemplate ext_template; // local instance, will self register itself
|
||||
|
||||
/**
|
||||
* Constructor, place basic initialization here, if necessary
|
||||
*/
|
||||
ExtTemplate::ExtTemplate() {}
|
||||
|
||||
/**
|
||||
* Enable operation, place start of use code here, if necessary
|
||||
*/
|
||||
void ExtTemplate::enable() {
|
||||
// add you init functions here
|
||||
}
|
||||
|
||||
void ExtTemplate::process_asap(void) {
|
||||
// add functions to be called as soon as possible during each loop in main function
|
||||
}
|
||||
|
||||
void ExtTemplate::process_1s(void) {
|
||||
// add functions to be called every second here
|
||||
}
|
||||
|
||||
#endif /* EXT_TEMPLATE_ENABLED */
|
||||
Reference in New Issue
Block a user