1#include "sensor/sensor_detector.h"
2#include "core/globals.h"
3#include "core/aqm_platform.h"
4#include "sensor/sensor_utils.h"
9int detect_available_sensors(
DetectedSensor *detected_sensors,
int max_sensors) {
10 const char *sensor_modes[] = {
"dht22",
"bme680",
"pms5003",
"mhz19"};
13 for (
size_t i = 0; i <
sizeof(sensor_modes) /
sizeof(sensor_modes[0]) && count < max_sensors; i++) {
14 const char *mode = sensor_modes[i];
15 const char *plugin_path = resolve_default_plugin_path(mode);
22 snprintf(ds->
mode,
sizeof(ds->
mode),
"%s", mode);
29 if (sensor_module_load(plugin_path, &module) == 0) {
31 if (module.plugin->name) {
34 if (module.plugin->init() == 0) {
36 module.plugin->shutdown();
38 sensor_module_unload(&module);
47void run_auto_detection_and_prompt(
void) {
48 printf(
"\n=== Auto-Detecting Sensors ===\n");
49 printf(
"Scanning for available sensor plugins...\n\n");
52 int count = detect_available_sensors(detected_sensors, MAX_SENSORS);
55 printf(
"No sensor plugins found in the plugins directory.\n");
59 printf(
"Found %d sensor plugin(s):\n\n", count);
61 int available_count = 0;
62 for (
int i = 0; i < count; i++) {
63 printf(
"%d. %s (%s)\n", i + 1, detected_sensors[i].mode, detected_sensors[i].plugin_path);
64 if (detected_sensors[i].detected) {
65 printf(
" Status: Plugin loaded successfully\n");
66 printf(
" Name: %s\n", detected_sensors[i].plugin_name[0] ? detected_sensors[i].plugin_name :
"Unknown");
67 if (detected_sensors[i].can_initialize) {
68 printf(
" Hardware: Sensor initialized successfully (likely connected)\n");
71 printf(
" Hardware: Sensor failed to initialize (may not be connected)\n");
74 printf(
" Status: Plugin not found or failed to load\n");
79 if (available_count == 0) {
80 printf(
"No sensors could be initialized. You can still use mock mode.\n");
84 printf(
"%d sensor(s) appear to be connected and ready.\n", available_count);
85 printf(
"\nDo you want to enable these sensors for multi-sensor data collection? (y/n): ");
88 if (fgets(input,
sizeof(input), stdin) && (input[0] ==
'y' || input[0] ==
'Y')) {
89 printf(
"\nEnabling detected sensors...\n");
91 init_sensor_configs();
92 active_sensor_count = 0;
94 for (
int i = 0; i < count; i++) {
95 if (detected_sensors[i].detected && detected_sensors[i].can_initialize) {
96 if (active_sensor_count < MAX_SENSORS) {
97 SensorConfig *config = &sensor_configs[active_sensor_count];
98 snprintf(config->
mode,
sizeof(config->
mode),
"%s", detected_sensors[i].mode);
102 printf(
" - Enabled %s (sensor_id: %d)\n", detected_sensors[i].plugin_name[0] ? detected_sensors[i].plugin_name : detected_sensors[i].mode, active_sensor_count);
103 active_sensor_count++;
108 if (active_sensor_count > 0) {
109 printf(
"\nSuccessfully enabled %d sensor(s) for multi-sensor data collection.\n", active_sensor_count);
110 printf(
"Configuration will be saved when you exit.\n");
112 printf(
"\nNo sensors were enabled.\n");
115 printf(
"\nAuto-detection canceled. No changes made.\n");
Result of probing one sensor mode during auto-detection.
char mode[32]
Sensor mode identifier, e.g.
int detected
Non-zero if the plugin library was found and loaded.
char plugin_name[64]
Plugin-reported name, populated only if detection succeeded.
int can_initialize
Non-zero if the loaded plugin's init() also succeeded.
char plugin_path[256]
Resolved plugin library path that was probed.
Configuration for one sensor slot in multi-sensor mode.
char mode[32]
Sensor mode identifier, e.g.
char plugin_path[256]
Path to the plugin library; empty string means use the default resolved by resolve_default_plugin_pat...
int enabled
Non-zero if this sensor slot is active for data collection.
A dynamically loaded sensor plugin and its OS-level handle.