upm  0.2.0
Sensor/Actuator repository for libmraa (v0.6.1)
grovewfs.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <string>
27 #include <stdint.h>
28 #include <sys/time.h>
29 #include <mraa/gpio.h>
30 
31 namespace upm {
32 
66  class GroveWFS {
67  public:
73  GroveWFS(int pin);
77  ~GroveWFS();
84  uint32_t getMillis();
85 
90  void initClock();
91 
97  void clearFlowCounter() { m_flowCounter = 0; };
98 
103  void startFlowCounter();
104 
109  void stopFlowCounter();
110 
116  uint32_t flowCounter() { return m_flowCounter; };
117 
122  static void flowISR(void *ctx);
123 
129  float flowRate();
130 
131  private:
132  volatile uint32_t m_flowCounter;
133  struct timeval m_startTime;
134  mraa_gpio_context m_gpio;
135  bool m_isrInstalled;
136  };
137 }
138 
139 
void initClock()
Definition: grovewfs.cxx:55
float flowRate()
Definition: grovewfs.cxx:112
Definition: a110x.h:29
void startFlowCounter()
Definition: grovewfs.cxx:88
void stopFlowCounter()
Definition: grovewfs.cxx:98
void clearFlowCounter()
Definition: grovewfs.h:97
GroveWFS(int pin)
Definition: grovewfs.cxx:32
~GroveWFS()
Definition: grovewfs.cxx:47
uint32_t flowCounter()
Definition: grovewfs.h:116
C++ API for the Grove Water Flow Sensor.
Definition: grovewfs.h:66
static void flowISR(void *ctx)
Definition: grovewfs.cxx:106
uint32_t getMillis()
Definition: grovewfs.cxx:60