本文整理汇总了C++中Gpio::openDevice方法的典型用法代码示例。如果您正苦于以下问题:C++ Gpio::openDevice方法的具体用法?C++ Gpio::openDevice怎么用?C++ Gpio::openDevice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gpio
的用法示例。
在下文中一共展示了Gpio::openDevice方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
Gpio gpio;
/// open device (/dev/mem)
if (gpio.openDevice() < 0) {
std::cerr << __func__ << ":" << __LINE__ << " openDevice failed" << std::endl;
return 0;
}
#if 0
/// set all gpio's as output - skip Gpio2 (i2c SCL) and Gpio3 (i2c data)
for (int i = 0; i < GPIO::GpioSize; i++) {
if (GPIO::GpioList[i] == GPIO::Gpio2) continue; /// i2c scl
if (GPIO::GpioList[i] == GPIO::Gpio3) continue; /// i2c data
gpio.setGpioDirection(GPIO::GpioList[i], GPIO::GpioOutput);
}
#endif
int output = GPIO::Gpio4;
gpio.setGpioDirection(output, GPIO::GpioOutput);
/// toggle outputs
//for (int loop = 0; loop < 100; loop++) {
while (true) {
/// wait for MicroSeconds microseconds
usleep(MicroSeconds);
/// switch all gpio's on - skip Gpio2 and Gpio3- this is i2c SCL and sda
#if 0
std::cout << "Turning all gpio's on" << std::endl;
for (int i = 0; i < GPIO::GpioSize; i++) {
if (GPIO::GpioList[i] == GPIO::Gpio2) continue;
if (GPIO::GpioList[i] == GPIO::Gpio3) continue;
gpio.setGpio(GPIO::GpioList[i], GPIO::GpioOn);
}
#endif
std::cout << "Turning on gpio " << std::dec << output << std::endl;
gpio.setGpio(output, GPIO::GpioOn);
/// wait for MicroSeconds microseconds
usleep(MicroSeconds);
std::cout << "Turning off gpio " << std::dec << output << std::endl;
gpio.setGpio(output, GPIO::GpioOff);
#if 0
/// switch all gpio's off - skip Gpio2 - this is i2c SCL
std::cout << "Turning all gpio's off" << std::endl;
for (int i = 0; i < GPIO::GpioSize; i++) {
if (GPIO::GpioList[i] == GPIO::Gpio2) continue;
if (GPIO::GpioList[i] == GPIO::Gpio3) continue;
gpio.setGpio(GPIO::GpioList[i], GPIO::GpioOff);
}
#endif
}
return 0;
}