2025-10-21 15:34:24 +08:00
|
|
|
|
// #include "piper_tts_interface.h"
|
|
|
|
|
|
// #include <string>
|
|
|
|
|
|
// #include <iostream>
|
2025-10-13 13:55:15 +08:00
|
|
|
|
|
2025-10-21 15:34:24 +08:00
|
|
|
|
// int main() {
|
|
|
|
|
|
// PiperTTSInterface tts_processor;
|
|
|
|
|
|
// // 示例 1: 只提供文本和输出文件名
|
|
|
|
|
|
// std::string text1 = "你好,世界。温度传感器出现故障。只需输入文本即可。";
|
|
|
|
|
|
// std::string file1 = "hello_world.wav";
|
|
|
|
|
|
// if (tts_processor.text_to_speech(text1, file1)) {
|
|
|
|
|
|
// std::cout << "Audio for '" << text1 << "' generated successfully!" << std::endl;
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// std::cerr << "Failed to generate audio for '" << text1 << "'." << std::endl;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return 0;
|
|
|
|
|
|
// }
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
#include "systemMonitor/iio_sensor.h" // 包含我们刚刚创建的头文件
|
2025-10-16 17:42:59 +08:00
|
|
|
|
int main() {
|
2025-10-21 15:34:24 +08:00
|
|
|
|
// --- 配置参数 ---
|
|
|
|
|
|
// !!! 修改这里以匹配你的设备和通道 !!!
|
|
|
|
|
|
const std::string iio_device_path = "/sys/bus/iio/devices/iio:device0";
|
|
|
|
|
|
const std::string iio_channel_name = "in_voltage2_raw"; // 例如,连接到 IN2 通道
|
|
|
|
|
|
|
|
|
|
|
|
const double adc_reference_voltage = 1.8; // ADC参考电压
|
|
|
|
|
|
const int64_t adc_resolution = 4096; // ADC分辨率 (e.g., 2^12 for 12-bit)
|
|
|
|
|
|
const double signal_gain = 11.0; // 信号通路的增益
|
|
|
|
|
|
std::cout << "--- Starting IIO Sensor Reader (Version 2) ---" << std::endl;
|
|
|
|
|
|
std::cout << "Reading from device: " << iio_device_path << std::endl;
|
|
|
|
|
|
std::cout << "Reading channel: " << iio_channel_name << std::endl;
|
|
|
|
|
|
std::cout << "-----------------------------------------------" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
// 注意:传感器对象在 try 块外创建,如果构造失败(找不到文件),会立即被捕获
|
|
|
|
|
|
IioSensor sensor(iio_device_path, iio_channel_name);
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 封装后的调用方式非常简洁!
|
|
|
|
|
|
// 每次调用 readVoltage,内部都会重新打开文件读取一次
|
|
|
|
|
|
double actual_voltage = sensor.readVoltage(adc_reference_voltage, adc_resolution, signal_gain);
|
|
|
|
|
|
// 输出结果
|
|
|
|
|
|
std::cout << "Actual Voltage: " << actual_voltage << " V" << std::endl;
|
|
|
|
|
|
} catch (const IioSensorError& e) {
|
|
|
|
|
|
// 如果单次读取失败(例如文件内容格式错误、无权限等),打印错误但继续循环
|
|
|
|
|
|
std::cerr << "[!] Read Error: " << e.what() << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 每秒钟读取一次
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
2025-10-17 09:58:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
2025-10-21 15:34:24 +08:00
|
|
|
|
}
|