我希望能够检测到外围传感器何时未连接到我的 Raspberry Pi 3。
例如,如果我有一个 GPIO 无源红外传感器。
我可以像这样获得所有 GPIO 端口:
PeripheralManagerService manager = new PeripheralManagerService();
List<String> portList = manager.getGpioList();
if (portList.isEmpty()) {
Log.i(TAG, "No GPIO port available on this device.");
} else {
Log.i(TAG, "List of available ports: " + portList);
}
然后我可以连接到这样的端口:
try {
Gpio pir = new PeripheralManagerService().openGpio("BCM4")
} catch (IOException e) {
// not thrown in the case of an empty pin
}
但是,即使引脚为空,我仍然可以连接到它(这在技术上是有道理的,因为 gpio 只是二进制打开或关闭)。似乎没有任何 api,我无法从逻辑上合理地思考如何区分连接了外围传感器的引脚和“空”的引脚。
因此,目前,我无法以编程方式断言我的传感器和电路设置正确。
有人有想法么?从电子学的角度来看,它甚至可能吗?
参考文档: