changed name setup for modules

feature/yukon
ZodiusInfuser 2023-08-03 17:21:01 +01:00
rodzic 2fd696790b
commit 34f95e4ed7
22 zmienionych plików z 118 dodań i 144 usunięć

Wyświetl plik

@ -13,15 +13,15 @@
namespace pimoroni {
const ModuleInfo KNOWN_MODULES[] = {
LEDStripModule::info(),
QuadServoDirectModule::info(),
QuadServoRegModule::info(),
BigMotorModule::info(),
DualMotorModule::info(),
DualSwitchedModule::info(),
BenchPowerModule::info(),
//AudioAmpModule::info(),
ProtoPotModule::info(),
const ModuleType KNOWN_MODULES[] = {
LEDStripModule::type(),
QuadServoDirectModule::type(),
QuadServoRegModule::type(),
BigMotorModule::type(),
DualMotorModule::type(),
DualSwitchedModule::type(),
BenchPowerModule::type(),
//AudioAmpModule::type(),
ProtoPotModule::type(),
};
}

Wyświetl plik

@ -2,6 +2,8 @@
namespace pimoroni {
static const std::string NAME = "Audio Amp";
// | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) |
// |-------|-------|-------|-------|----------------------|-----------------------------|
// | FLOAT | 0 | 1 | 1 | [Proposed] Audio Amp | |

Wyświetl plik

@ -5,20 +5,16 @@
namespace pimoroni {
class AudioAmpModule : public YukonModule {
public:
//static const std::string NAME = "Unnamed";
public:
static const std::string NAME;
static bool is_module(uint adc_level, bool slow1, bool slow2, bool slow3);
static std::string name() {
return "Audio Amp";
virtual std::string name() {
return AudioAmpModule::NAME;
}
virtual std::string instance_name() {
return AudioAmpModule::name();
}
INFO_FUNC(AudioAmpModule)
TYPE_FUNCTION(AudioAmpModule)
};
}

Wyświetl plik

@ -2,6 +2,8 @@
namespace pimoroni {
const std::string BenchPowerModule::NAME = "Bench Power";
// | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) |
// |-------|-------|-------|-------|----------------------|-----------------------------|
// | LOW | 1 | 0 | 0 | Bench Power | |

Wyświetl plik

@ -5,20 +5,16 @@
namespace pimoroni {
class BenchPowerModule : public YukonModule {
public:
//static const std::string NAME = "Unnamed";
public:
static const std::string NAME;
static bool is_module(uint adc_level, bool slow1, bool slow2, bool slow3);
static std::string name() {
return "Bench Power";
virtual std::string name() {
return BenchPowerModule::NAME;
}
virtual std::string instance_name() {
return BenchPowerModule::name();
}
INFO_FUNC(BenchPowerModule)
TYPE_FUNCTION(BenchPowerModule)
};
}

Wyświetl plik

@ -2,6 +2,8 @@
namespace pimoroni {
const std::string BigMotorModule::NAME = "Big Motor";
// | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) |
// |-------|-------|-------|-------|----------------------|-----------------------------|
// | LOW | 0 | 0 | 1 | Big Motor | Not in fault |

Wyświetl plik

@ -5,20 +5,16 @@
namespace pimoroni {
class BigMotorModule : public YukonModule {
public:
//static const std::string NAME = "Unnamed";
public:
static const std::string NAME;
static bool is_module(uint adc_level, bool slow1, bool slow2, bool slow3);
static std::string name() {
return "Big Motor";
virtual std::string name() {
return BigMotorModule::NAME;
}
virtual std::string instance_name() {
return BigMotorModule::name();
}
INFO_FUNC(BigMotorModule)
TYPE_FUNCTION(BigMotorModule)
};
}

Wyświetl plik

@ -19,31 +19,25 @@ namespace pimoroni {
};
class YukonModule {
public:
//static const std::string NAME = "Unnamed";
public:
static constexpr float ROOM_TEMP = 273.15f + 25.0f;
static constexpr float RESISTOR_AT_ROOM_TEMP = 10000.0f;
static constexpr float BETA = 3435;
static constexpr float ROOM_TEMP = 273.15f + 25.0f;
static constexpr float RESISTOR_AT_ROOM_TEMP = 10000.0f;
static constexpr float BETA = 3435;
static bool is_module(uint adc_level, bool slow1, bool slow2, bool slow3) {
return false;
}
virtual std::string instance_name() = 0;
virtual std::string name() = 0;
};
typedef bool (*module_callback)(uint, bool, bool, bool) ;
typedef bool (&func_is_module)(uint, bool, bool, bool);
struct ModuleInfo {
std::type_index type;
std::string name;
module_callback is_module;
struct ModuleType {
const std::type_index TYPE;
const std::string &NAME;
func_is_module is_module;
};
#define INFO_FUNC(module_name) \
static ModuleInfo info() { \
return { typeid(module_name), module_name::name(), &module_name::is_module }; \
}
#define TYPE_FUNCTION(module_class) \
static ModuleType type() { \
return { typeid(module_class), module_class::NAME, module_class::is_module }; \
}
}

Wyświetl plik

@ -2,6 +2,8 @@
namespace pimoroni {
const std::string DualMotorModule::NAME = "Dual Motor";
// | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) |
// |-------|-------|-------|-------|----------------------|-----------------------------|
// | HIGH | 1 | 1 | 1 | Dual Motor | |

Wyświetl plik

@ -5,20 +5,16 @@
namespace pimoroni {
class DualMotorModule : public YukonModule {
public:
//static const std::string NAME = "Unnamed";
public:
static const std::string NAME;
static bool is_module(uint adc_level, bool slow1, bool slow2, bool slow3);
static std::string name() {
return "Dual Motor";
virtual std::string name() {
return DualMotorModule::NAME;
}
virtual std::string instance_name() {
return DualMotorModule::name();
}
INFO_FUNC(DualMotorModule)
TYPE_FUNCTION(DualMotorModule)
};
}

Wyświetl plik

@ -2,6 +2,8 @@
namespace pimoroni {
const std::string DualSwitchedModule::NAME = "Dual Switched Output";
// | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) |
// |-------|-------|-------|-------|----------------------|-----------------------------|
// | FLOAT | 1 | 0 | 1 | Dual Switched Output | |

Wyświetl plik

@ -5,20 +5,16 @@
namespace pimoroni {
class DualSwitchedModule : public YukonModule {
public:
//static const std::string NAME = "Unnamed";
public:
static const std::string NAME;
static bool is_module(uint adc_level, bool slow1, bool slow2, bool slow3);
static std::string name() {
return "Dual Switched Output";
virtual std::string name() {
return DualSwitchedModule::NAME;
}
virtual std::string instance_name() {
return DualSwitchedModule::name();
}
INFO_FUNC(DualSwitchedModule)
TYPE_FUNCTION(DualSwitchedModule)
};
}

Wyświetl plik

@ -2,6 +2,8 @@
namespace pimoroni {
const std::string LEDStripModule::NAME = "LED Strip";
// | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) |
// |-------|-------|-------|-------|----------------------|-----------------------------|
// | LOW | 1 | 1 | 1 | LED Strip | |

Wyświetl plik

@ -5,20 +5,16 @@
namespace pimoroni {
class LEDStripModule : public YukonModule {
public:
//static const std::string NAME = "Unnamed";
public:
static const std::string NAME;
static bool is_module(uint adc_level, bool slow1, bool slow2, bool slow3);
static std::string name() {
return "LED Strip";
virtual std::string name() {
return LEDStripModule::NAME + " (NeoPixel)";
}
virtual std::string instance_name() {
return LEDStripModule::name() + " (NeoPixel)";
}
INFO_FUNC(LEDStripModule)
TYPE_FUNCTION(LEDStripModule)
};
}

Wyświetl plik

@ -2,6 +2,8 @@
namespace pimoroni {
const std::string ProtoPotModule::NAME = "Proto Potentiometer";
// | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) |
// |-------|-------|-------|-------|----------------------|-----------------------------|
// | LOW | 1 | 1 | 0 | Proto Potentiometer | Pot in low position |
@ -11,6 +13,8 @@ namespace pimoroni {
return slow1 == HIGH && slow2 == HIGH && slow3 == LOW;
}
const std::string ProtoPotModule2::NAME = "Proto Potentiometer 2";
bool ProtoPotModule2::is_module(uint adc_level, bool slow1, bool slow2, bool slow3) {
return slow1 == HIGH && slow2 == HIGH && slow3 == LOW;
}

Wyświetl plik

@ -5,37 +5,29 @@
namespace pimoroni {
class ProtoPotModule : public YukonModule {
public:
//static const std::string NAME = "Unnamed";
public:
static const std::string NAME;
static bool is_module(uint adc_level, bool slow1, bool slow2, bool slow3);
static std::string name() {
return "Proto Potentiometer";
virtual std::string name() {
return ProtoPotModule::NAME;
}
virtual std::string instance_name() {
return ProtoPotModule::name();
}
INFO_FUNC(ProtoPotModule)
TYPE_FUNCTION(ProtoPotModule)
};
class ProtoPotModule2 : public YukonModule {
public:
//static const std::string NAME = "Unnamed";
public:
static const std::string NAME;
static bool is_module(uint adc_level, bool slow1, bool slow2, bool slow3);
static std::string name() {
return "Proto Potentiometer 2";
virtual std::string name() {
return ProtoPotModule2::NAME;
}
virtual std::string instance_name() {
return ProtoPotModule2::name();
}
INFO_FUNC(ProtoPotModule2)
TYPE_FUNCTION(ProtoPotModule2)
};
}

Wyświetl plik

@ -2,6 +2,8 @@
namespace pimoroni {
const std::string QuadServoDirectModule::NAME = "Quad Servo Direct";
// | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) |
// |-------|-------|-------|-------|----------------------|-----------------------------|
// | LOW | 0 | 0 | 0 | Quad Servo Direct | A1 input near 0V |

Wyświetl plik

@ -5,20 +5,16 @@
namespace pimoroni {
class QuadServoDirectModule : public YukonModule {
public:
//static const std::string NAME = "Unnamed";
public:
static const std::string NAME;
static bool is_module(uint adc_level, bool slow1, bool slow2, bool slow3);
static std::string name() {
return "Quad Servo Direct";
virtual std::string name() {
return QuadServoDirectModule::NAME;
}
virtual std::string instance_name() {
return QuadServoDirectModule::name();
}
INFO_FUNC(QuadServoDirectModule)
TYPE_FUNCTION(QuadServoDirectModule)
};
}

Wyświetl plik

@ -2,6 +2,8 @@
namespace pimoroni {
const std::string QuadServoRegModule::NAME = "Quad Servo Regulated";
// | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) |
// |-------|-------|-------|-------|----------------------|-----------------------------|
// | FLOAT | 0 | 1 | 0 | Quad Servo Regulated | |

Wyświetl plik

@ -5,20 +5,16 @@
namespace pimoroni {
class QuadServoRegModule : public YukonModule {
public:
//static const std::string NAME = "Unnamed";
public:
static const std::string NAME;
static bool is_module(uint adc_level, bool slow1, bool slow2, bool slow3);
static std::string name() {
return "Quad Servo Regulated";
virtual std::string name() {
return QuadServoRegModule::NAME;
}
virtual std::string instance_name() {
return QuadServoRegModule::name();
}
INFO_FUNC(QuadServoRegModule)
TYPE_FUNCTION(QuadServoRegModule)
};
}

Wyświetl plik

@ -252,25 +252,25 @@ namespace pimoroni {
return slot;
}
std::vector<uint> Yukon::find_slots_with_module(ModuleInfo module_type) {
std::vector<uint> Yukon::find_slots_with_module(const ModuleType& module_type) {
if(is_main_output()) {
throw std::runtime_error("Cannot find slots with modules whilst the main output is active\n");
}
logging.info("> Finding slots with '" + module_type.name + "' module\n");
logging.info("> Finding slots with '" + module_type.NAME + "' module\n");
std::vector<uint> slot_ids;
for(auto it = slot_assignments.begin(); it != slot_assignments.end(); it++) {
SLOT slot = it->first;
logging.info("[Slot" + std::to_string(slot.ID) + "] ");
const ModuleInfo* detected = __detect_module(slot); // Need to have a return type that can be null
const ModuleType* detected = __detect_module(slot);
if(detected != nullptr && detected->type == module_type.type) {
logging.info("Found '" + detected->name + "' module\n");
if(detected != nullptr && detected->TYPE == module_type.TYPE) {
logging.info("Found '" + detected->NAME + "' module\n");
slot_ids.push_back(slot.ID);
}
else {
logging.info("No '" + module_type.name + "' module\n");
logging.info("No '" + module_type.NAME + "' module\n");
}
}
@ -314,9 +314,9 @@ namespace pimoroni {
}
}
const ModuleInfo* Yukon::__match_module(uint adc_level, bool slow1, bool slow2, bool slow3) {
const ModuleType* Yukon::__match_module(uint adc_level, bool slow1, bool slow2, bool slow3) {
for(uint i = 0; i < count_of(KNOWN_MODULES); i++) {
const ModuleInfo& m = KNOWN_MODULES[i];
const ModuleType& m = KNOWN_MODULES[i];
//printf("%s\n", std::get<0>(KNOWN_MODULES[i]).name());
//printf("%s\n", std::get<1>(KNOWN_MODULES[i]).c_str());
//printf("%d\n", std::get<2>(KNOWN_MODULES[i])(adc_level, slow1, slow2, slow3));
@ -328,7 +328,7 @@ namespace pimoroni {
return nullptr;
}
const ModuleInfo* Yukon::__detect_module(SLOT slot) {
const ModuleType* Yukon::__detect_module(SLOT slot) {
set_slow_config(slot.SLOW1, false);
set_slow_config(slot.SLOW2, false);
set_slow_config(slot.SLOW3, false);
@ -356,13 +356,13 @@ namespace pimoroni {
adc_level = ADC_HIGH;
}
const ModuleInfo* detected = __match_module(adc_level, slow1, slow2, slow3);
const ModuleType* detected = __match_module(adc_level, slow1, slow2, slow3);
__deselect_address();
return detected;
}
const ModuleInfo* Yukon::detect_module(uint slot_id) {
const ModuleType* Yukon::detect_module(uint slot_id) {
if(is_main_output()) {
throw std::runtime_error("Cannot detect modules whilst the main output is active\n");
}
@ -372,7 +372,7 @@ namespace pimoroni {
return __detect_module(slot);
}
const ModuleInfo* Yukon::detect_module(SLOT slot) {
const ModuleType* Yukon::detect_module(SLOT slot) {
if(is_main_output()) {
throw std::runtime_error("Cannot detect modules whilst the main output is active\n");
}
@ -401,11 +401,11 @@ namespace pimoroni {
YukonModule* module = it->second;
logging.info("[Slot" + std::to_string(slot.ID) + "] ");
const ModuleInfo* detected = __detect_module(slot);
const ModuleType* detected = __detect_module(slot);
if(detected == nullptr) {
if(module != nullptr) {
logging.info("No module detected! Expected a '" + module->instance_name() + "' module.\n");
logging.info("No module detected! Expected a '" + module->name() + "' module.\n");
if(!allow_undetected) {//if slot not in allow_undetected:
raise_undetected = true;
}
@ -417,18 +417,18 @@ namespace pimoroni {
}
else {
if(module != nullptr) {
if(std::type_index(typeid(*module)) == detected->type) {
logging.info("'" + module->instance_name() + "' module detected and registered.\n");
if(std::type_index(typeid(*module)) == detected->TYPE) {
logging.info("'" + module->name() + "' module detected and registered.\n");
}
else {
logging.info("Module discrepency! Expected a '" + module->instance_name() + "}' module, but detected a '" + detected->name + "' module.\n");
logging.info("Module discrepency! Expected a '" + module->name() + "}' module, but detected a '" + detected->NAME + "' module.\n");
if(!allow_discrepencies) { //if slot not in allow_discrepencies:
raise_discrepency = true;
}
}
}
else {
logging.info("'" + detected->name + "' module detected but not registered.\n");
logging.info("'" + detected->NAME + "' module detected but not registered.\n");
if(!allow_unregistered) { //if slot not in allow_unregistered:
raise_unregistered = true;
}
@ -472,7 +472,7 @@ namespace pimoroni {
YukonModule* module = it->second;
if(module != nullptr) {
logging.info("[Slot" + std::to_string(slot.ID) + " '" + module->instance_name() + "'] Initialising ... ");
logging.info("[Slot" + std::to_string(slot.ID) + " '" + module->name() + "'] Initialising ... ");
//TODO module.initialise(slot, self.read_slot_adc1, self.read_slot_adc2)
logging.info("done\n");
}

Wyświetl plik

@ -190,7 +190,7 @@ namespace pimoroni {
SLOT __check_slot(uint slot_id);
SLOT __check_slot(SLOT slot);
std::vector<uint> find_slots_with_module(ModuleInfo module_type);
std::vector<uint> find_slots_with_module(const ModuleType& module_type);
void register_with_slot(YukonModule* module, uint slot_id);
void register_with_slot(YukonModule* module, SLOT slot);
@ -198,10 +198,10 @@ namespace pimoroni {
void deregister_slot(uint slot_id);
void deregister_slot(SLOT slot);
const ModuleInfo* __match_module(uint adc_level, bool slow1, bool slow2, bool slow3);
const ModuleInfo* __detect_module(SLOT slot);
const ModuleInfo* detect_module(uint slot_id);
const ModuleInfo* detect_module(SLOT slot);
const ModuleType* __match_module(uint adc_level, bool slow1, bool slow2, bool slow3);
const ModuleType* __detect_module(SLOT slot);
const ModuleType* detect_module(uint slot_id);
const ModuleType* detect_module(SLOT slot);
void __expand_slot_list(std::vector<SLOT> slot_list);
void __verify_modules(bool allow_unregistered, bool allow_undetected, bool allow_discrepencies, bool allow_no_modules);