2#include "rpishiftdriver.h"
9#include <boost/thread.hpp>
21RpiShiftDriver::RpiShiftDriver()
25RpiShiftDriver::RpiShiftDriver(
int data,
int clock,
int latch,
int nbOut):
34 pinMode(mData, OUTPUT);
35 pinMode(mClock, OUTPUT);
36 pinMode(mLatch, OUTPUT);
38 digitalWrite(mData, LOW);
39 digitalWrite(mClock, LOW);
40 digitalWrite(mLatch, LOW);
44RpiShiftDriver::~RpiShiftDriver()
55 digitalWrite(mData, LOW);
56 digitalWrite(mClock, LOW);
57 digitalWrite(mLatch, LOW);
61void RpiShiftDriver::threadLoop()
66 if (mCurPos >= mValues.size())
69 WriteValue(mValues[mCurPos].first);
72 boost::this_thread::sleep_for(boost::chrono::microseconds(mValues[mCurPos].second));
78void RpiShiftDriver::WriteValue(
int value)
82 for (
int i = 0; i < mNbOut; i++)
84 val = (value & (1 << i)) ? HIGH : LOW;
85 digitalWrite(mData, val);
86 digitalWrite(mClock, HIGH);
88 digitalWrite(mClock, LOW);
91 digitalWrite(mLatch, HIGH);
93 digitalWrite(mLatch, LOW);
97void RpiShiftDriver::SetValues(std::vector<shiftValue> values)
108 if (mValues.size() > 1)
112 mThread = boost::thread(&RpiShiftDriver::threadLoop,
this);
116 if (mValues.size() > 0)
117 WriteValue(mValues[0].first);