feat: gpio feature根据操作系统自动判断
This commit is contained in:
parent
2ce3b11628
commit
bf6a401cf7
10
Cargo.toml
10
Cargo.toml
@ -6,7 +6,7 @@ authors = ["Meteor Detection Team"]
|
||||
description = "A Raspberry Pi based meteor detection system"
|
||||
|
||||
[features]
|
||||
# 默认features,在Linux上自动包含gpio
|
||||
# 默认features
|
||||
default = []
|
||||
|
||||
# 如果在Linux上运行,则默认启用GPIO support
|
||||
@ -14,6 +14,14 @@ default = []
|
||||
[target.'cfg(target_os = "linux")'.features]
|
||||
default = ["gpio"]
|
||||
|
||||
# 树莓派特定target配置
|
||||
[target.'cfg(all(target_os = "linux", target_arch = "arm"))'.features]
|
||||
default = ["gpio"]
|
||||
|
||||
# 64位树莓派target配置
|
||||
[target.'cfg(all(target_os = "linux", target_arch = "aarch64"))'.features]
|
||||
default = ["gpio"]
|
||||
|
||||
# 定义常规的features (全平台通用)
|
||||
gpio = ["rppal", "embedded-hal"] # Feature to enable GPIO functionality
|
||||
opencv-4-11-plus = [] # For OpenCV 4.11 and newer versions
|
||||
|
||||
5
build.rs
5
build.rs
@ -8,11 +8,14 @@ fn main() {
|
||||
let supports_gpio = detect_gpio_support();
|
||||
|
||||
// 设置环境变量,告诉lib.rs是否有实际的GPIO支持
|
||||
// 注意:这只影响PLATFORM_SUPPORTS_GPIO的值,不影响依赖的启用
|
||||
if supports_gpio {
|
||||
// 设置编译器配置,lib.rs会使用它
|
||||
println!("cargo:rustc-env=HAS_GPIO_SUPPORT=true");
|
||||
println!("cargo:warning=GPIO support detected, PLATFORM_SUPPORTS_GPIO will be true");
|
||||
|
||||
// 强制启用gpio feature,确保依赖包含rppal
|
||||
println!("cargo:rustc-cfg=feature=\"gpio\"");
|
||||
println!("cargo:warning=Also enabling gpio feature to include rppal dependency");
|
||||
} else if cfg!(target_os = "linux") {
|
||||
// 特殊情况:Linux但没有GPIO支持
|
||||
println!("cargo:rustc-env=HAS_GPIO_SUPPORT=false");
|
||||
|
||||
@ -6,6 +6,10 @@ pub const PLATFORM_SUPPORTS_GPIO: bool = option_env!("HAS_GPIO_SUPPORT").map_or(
|
||||
#[cfg(not(feature = "gpio"))]
|
||||
pub const PLATFORM_SUPPORTS_GPIO: bool = false;
|
||||
|
||||
// 强制在条件编译中使用rppal库,解决编译依赖问题
|
||||
#[cfg(all(feature = "gpio", target_os = "linux"))]
|
||||
pub use rppal;
|
||||
|
||||
// 将所有模块重新导出,使它们对例子可见
|
||||
pub mod camera;
|
||||
pub mod config;
|
||||
|
||||
@ -7,6 +7,10 @@ use std::sync::Mutex;
|
||||
#[cfg(feature = "gpio")]
|
||||
use rppal::gpio::{Gpio, Level, Mode, OutputPin};
|
||||
|
||||
// 确保即使启用了gpio feature,但在非Linux平台上也不尝试使用rppal
|
||||
#[cfg(all(feature = "gpio", not(target_os = "linux")))]
|
||||
compile_error!("GPIO feature enabled but not on Linux platform");
|
||||
|
||||
#[cfg(not(feature = "gpio"))]
|
||||
use rand::Rng;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user