| Kevin Tung | 994a77f | 2024-12-23 17:48:56 +0800 | [diff] [blame] | 1 | #include "eeprom_device_version.hpp" | 
 | 2 |  | 
 | 3 | #include "pt5161l/pt5161l.hpp" | 
 | 4 |  | 
 | 5 | #include <functional> | 
 | 6 | #include <unordered_map> | 
 | 7 |  | 
 | 8 | using ProviderFactory = std::function<std::unique_ptr<DeviceVersion>( | 
 | 9 |     const std::string&, const uint16_t, const uint8_t)>; | 
 | 10 |  | 
 | 11 | template <typename ProviderType> | 
 | 12 | std::unique_ptr<DeviceVersion> createProvider( | 
 | 13 |     const std::string& chipModel, const uint16_t bus, const uint8_t address) | 
 | 14 | { | 
 | 15 |     return std::make_unique<ProviderType>(chipModel, bus, address); | 
 | 16 | } | 
 | 17 |  | 
 | 18 | static const std::unordered_map<std::string, ProviderFactory> providerMap = { | 
| Kevin Tung | 30fd7e4 | 2025-05-14 13:40:18 +0800 | [diff] [blame] | 19 |     {"PT5161LFirmware", createProvider<PT5161LDeviceVersion>}}; | 
| Kevin Tung | 994a77f | 2024-12-23 17:48:56 +0800 | [diff] [blame] | 20 |  | 
 | 21 | std::unique_ptr<DeviceVersion> getVersionProvider( | 
 | 22 |     const std::string& chipModel, const uint16_t bus, const uint8_t address) | 
 | 23 | { | 
 | 24 |     auto it = providerMap.find(chipModel); | 
 | 25 |     if (it != providerMap.end()) | 
 | 26 |     { | 
 | 27 |         return it->second(chipModel, bus, address); | 
 | 28 |     } | 
 | 29 |  | 
 | 30 |     return nullptr; | 
 | 31 | } |