// // Created by yingluo907 on 2019/4/11. // #include "Gpio.h" #include #include "DevUtil.h" #define IOPATH "%s/gpio%d/%s" const std::string Gpio::falling = "falling"; const std::string Gpio::rising = "rising"; const std::string Gpio::both = "both"; const std::string Gpio::none = "none"; const std::string Gpio::in = "in"; const std::string Gpio::out = "out"; Gpio::Gpio(int port) { this->port = port; path_value = utils::format_string(IOPATH, path_gpiobase.c_str(), port, path_value.c_str()); path_edge = utils::format_string(IOPATH, path_gpiobase.c_str(), port, path_edge.c_str()); path_direction = utils::format_string(IOPATH, path_gpiobase.c_str(), port, path_direction.c_str()); path_active_low = utils::format_string(IOPATH, path_gpiobase.c_str(), port, path_active_low.c_str()); } int Gpio::getPort() { return port; } void Gpio::setValue(GpioLevel level) { write_dev(path_value, level); } Gpio::GpioLevel Gpio::getValue() { return (Gpio::GpioLevel)read_dev_i(path_value); } std::string Gpio::getDirection() { return read_dev_s(path_direction); } void Gpio::setDirection(std::string direction) { write_dev(path_direction, direction); } void Gpio::setActive(GpioLevel level) { write_dev(path_active_low, level); } Gpio::GpioLevel Gpio::getActive() { return (GpioLevel)read_dev_i(path_active_low); } void Gpio::setEdge(std::string edge) { write_dev(path_edge, edge); } std::string Gpio::getEdge() { return read_dev_s(path_edge); } GpioOut::GpioOut(int port) : Gpio(port) { setDirection(out); }