EndpointRaspberry::EndpointRaspberry(ptree &pt) :HardwareEndpoint(pt), pinNumber(pt.get<int>("pin")), invert(pt.get<bool>("invert",false)) { if(!initialized) { if(wiringPiSetup()) throw HeinzException("unable to initialize wiringPi"); initialized=true; } string pull_mode_s=pt.get<string>("pull","off"); int pull_mode=PUD_OFF; if(pull_mode_s=="off") pull_mode=PUD_OFF; else if(pull_mode_s=="up") pull_mode=PUD_UP; else if(pull_mode_s=="down") pull_mode=PUD_DOWN; else BOOST_THROW_EXCEPTION(ConfigException()<<ExErrorMessage((boost::format("unknown pull mode: %1%")%pull_mode_s).str())); if(allocatedPins.find(pinNumber)!=allocatedPins.end()) BOOST_THROW_EXCEPTION(ConfigException()<<ExErrorMessage((boost::format("pin %1% already in use")%pinNumber).str())); allocatedPins.insert(pinNumber); pinMode(pinNumber,getIsInput()?INPUT:OUTPUT); if(getIsInput()) pullUpDnControl(pinNumber, pull_mode); }
bool EndpointRaspberry::updatesAvailable() { if(!getIsInput()) return false; bool v=digitalRead(pinNumber)==HIGH; if((cachedValue==1)!=v) { cachedValue=v?1:0; return true; } return false; }
/// mode changed handler void SignalItem::onParentModeChanged(int) { isOutputChanged(getIsOutput()); isInputChanged(getIsInput()); }