8#include <boost/thread.hpp>
23RpiPin::RpiPin(
int pin,
int mode):
30 if (mMode == PWM_OUTPUT && mPin != 18)
32 softPwmCreate(mPin, 0, 100);
34 else if (mMode == SOFT_DIGITAL_INPUT)
37 mThread = boost::thread(&RpiPin::threadLoop,
this);
55 if (mMode == PWM_OUTPUT && mPin != 18)
59 else if (mMode == PWM_OUTPUT)
64 if (mMode == OUTPUT || mMode == PWM_OUTPUT)
66 digitalWrite(mPin, 0);
71void RpiPin::threadLoop()
79 for (
int i = 0; i < NUMREADINGS && mState; i++)
81 pinMode(mPin, OUTPUT);
82 digitalWrite(mPin, LOW);
87 while (digitalRead(mPin) == LOW && mState)
95 mSoftValue = value / NUMREADINGS;
96 boost::this_thread::sleep_for(boost::chrono::milliseconds(16));
101void RpiPin::SetPullUpDnControl(
int mode)
104 pullUpDnControl(mPin, mode);
108void RpiPin::DigitalWrite(
int value)
111 digitalWrite(mPin, value);
115int RpiPin::DigitalRead()
118 return digitalRead(mPin);
124void RpiPin::AnalogWrite(
int value)
127 if (mMode == PWM_OUTPUT)
131 softPwmWrite(mPin, value);
135 pwmWrite(mPin, value);
139 analogWrite(mPin, value);
143int RpiPin::AnalogRead()
146 if (mMode == SOFT_DIGITAL_INPUT)
152 return analogRead(mPin);
159void RpiPin::PwmWrite(
int value)
163 else if (value > 1023)
169 softPwmWrite(mPin, value);
173 pwmWrite(mPin, value);