wfs: C port; C++ wraps C

Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
Jon Trulson
2017-01-26 15:06:05 -07:00
parent 0a91eb0b46
commit 849711c47d
11 changed files with 537 additions and 208 deletions

View File

@ -33,46 +33,47 @@ int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a Water Flow Sensor on digital pin D2
upm::WFS* flow = new upm::WFS(2);
// set the flow counter to 0 and start counting
flow->clearFlowCounter();
flow->startFlowCounter();
// Instantiate a Water Flow Sensor on digital pin D2. This must
// be an interrupt capable pin.
upm::WFS* flow = new upm::WFS(2);
while (shouldRun)
// set the flow counter to 0 and start counting
flow->clearFlowCounter();
flow->startFlowCounter();
while (shouldRun)
{
// we grab these (,illis and flowCount) just for display
// purposes in this example
uint32_t millis = flow->getMillis();
uint32_t flowCount = flow->flowCounter();
// we grab these (millis and flowCount) just for display
// purposes in this example
uint32_t millis = flow->getMillis();
uint32_t flowCount = flow->flowCounter();
float fr = flow->flowRate();
float fr = flow->flowRate();
// output milliseconds passed, flow count, and computed flow rate
cout << "Millis: " << millis << " Flow Count: " << flowCount;
cout << " Flow Rate: " << fr << " LPM" << endl;
// output milliseconds passed, flow count, and computed flow rate
cout << "Millis: " << millis << " Flow Count: " << flowCount;
cout << " Flow Rate: " << fr << " LPM" << endl;
// best to gather data for at least one second for reasonable
// results.
sleep(2);
// best to gather data for at least one second for reasonable
// results.
sleep(2);
}
flow->stopFlowCounter();
flow->stopFlowCounter();
//! [Interesting]
cout << "Exiting..." << endl;
cout << "Exiting..." << endl;
delete flow;
return 0;
delete flow;
return 0;
}