upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
kx122.hpp
Go to the documentation of this file.
1 /*
2 * The MIT License (MIT)
3 *
4 * Author: Samuli Rissanen <samuli.rissanen@hotmail.com>
5 * Copyright (c) 2018 Rohm Semiconductor.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24 
25 #pragma once
26 
27 #include <vector>
28 #include <mraa/gpio.hpp>
29 
30 #include "kx122.h"
31 
40 namespace upm{
41 
42  class KX122{
43  public:
44 
58  KX122(int bus, int addr, int chip_select, int spi_bus_frequency = DEFAULT_SPI_FREQUENCY);
59 
63  ~KX122();
64 
77  void deviceInit(KX122_ODR_T odr, KX122_RES_T res, KX122_RANGE_T grange);
78 
83  float getSamplePeriod();
84 
91  uint8_t getWhoAmI();
92 
100  void getRawAccelerationData(float *x, float *y, float *z);
101 
110  void getAccelerationData(float *x, float *y, float *z);
111 
118  std::vector<float> getAccelerationDataVector();
119 
130  void softwareReset();
131 
139  void enableIIR();
140 
148  void disableIIR();
149 
163  void selfTest();
164 
170  void setSensorStandby();
171 
177  void setSensorActive();
178 
187  void setODR(KX122_ODR_T odr);
188 
197  void setGrange(KX122_RANGE_T grange);
198 
210  void setResolution(KX122_RES_T res);
211 
220  void setBW(LPRO_STATE_T lpro);
221 
230  void setAverage(KX122_AVG_T avg);
231 
242  void installISR(mraa::Edge edge, KX122_INTERRUPT_PIN_T intp, int pin, void (*isr)(void*), void *arg);
243 
250  void uninstallISR(KX122_INTERRUPT_PIN_T intp);
251 
265  void enableInterrupt1(KX122_INTERRUPT_POLARITY_T polarity);
266 
280  void enableInterrupt2(KX122_INTERRUPT_POLARITY_T polarity);
281 
289  void disableInterrupt1();
290 
298  void disableInterrupt2();
299 
310  void routeInterrupt1(uint8_t bits);
311 
322  void routeInterrupt2(uint8_t bits);
323 
331  bool getInterruptStatus();
332 
348  uint8_t getInterruptSource();
349 
357  void clearInterrupt();
358 
368 
377 
388 
397 
405  void enableBuffer();
406 
414  void disableBuffer();
415 
430  void bufferInit(uint samples, KX122_RES_T res, KX122_BUFFER_MODE_T mode);
431 
440  void setBufferResolution(KX122_RES_T res);
441 
456  void setBufferThreshold(uint samples);
457 
471  void setBufferMode(KX122_BUFFER_MODE_T mode);
472 
479  uint getBufferStatus();
480 
488  std::vector<float> getRawBufferSamples(uint len);
489 
497  std::vector<float> getBufferSamples(uint len);
498 
504  void clearBuffer();
505  private:
506  //Device context
507  kx122_context m_kx122;
508 
509  /* Disable implicit copy and assignment operators */
510  KX122(const KX122&) = delete;
511  KX122 &operator=(const KX122&) = delete;
512  };
513 }
std::vector< float > getAccelerationDataVector()
Definition: kx122.cxx:84
void enableInterrupt1(KX122_INTERRUPT_POLARITY_T polarity)
Definition: kx122.cxx:181
bool getInterruptStatus()
Definition: kx122.cxx:223
void disableInterrupt2()
Definition: kx122.cxx:202
void setBufferMode(KX122_BUFFER_MODE_T mode)
Definition: kx122.cxx:308
void disableBufferFullInterrupt()
Definition: kx122.cxx:266
void setODR(KX122_ODR_T odr)
Definition: kx122.cxx:134
void selfTest()
Definition: kx122.cxx:113
void disableInterrupt1()
Definition: kx122.cxx:195
void bufferInit(uint samples, KX122_RES_T res, KX122_BUFFER_MODE_T mode)
Definition: kx122.cxx:287
void routeInterrupt1(uint8_t bits)
Definition: kx122.cxx:209
void setResolution(KX122_RES_T res)
Definition: kx122.cxx:148
float getSamplePeriod()
Definition: kx122.cxx:55
void installISR(mraa::Edge edge, KX122_INTERRUPT_PIN_T intp, int pin, void(*isr)(void *), void *arg)
Definition: kx122.cxx:169
void enableIIR()
Definition: kx122.cxx:99
void uninstallISR(KX122_INTERRUPT_PIN_T intp)
Definition: kx122.cxx:176
void setBufferThreshold(uint samples)
Definition: kx122.cxx:301
void getAccelerationData(float *x, float *y, float *z)
Definition: kx122.cxx:77
void setBufferResolution(KX122_RES_T res)
Definition: kx122.cxx:294
uint getBufferStatus()
Definition: kx122.cxx:315
uint8_t getWhoAmI()
Definition: kx122.cxx:60
void setBW(LPRO_STATE_T lpro)
Definition: kx122.cxx:155
std::vector< float > getBufferSamples(uint len)
Definition: kx122.cxx:346
~KX122()
Definition: kx122.cxx:43
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
void disableDataReadyInterrupt()
Definition: kx122.cxx:252
void clearInterrupt()
Definition: kx122.cxx:238
void setSensorStandby()
Definition: kx122.cxx:120
std::vector< float > getRawBufferSamples(uint len)
Definition: kx122.cxx:328
Definition: kx122.hpp:42
void setSensorActive()
Definition: kx122.cxx:127
void disableIIR()
Definition: kx122.cxx:106
void softwareReset()
Definition: kx122.cxx:92
void setGrange(KX122_RANGE_T grange)
Definition: kx122.cxx:141
void enableInterrupt2(KX122_INTERRUPT_POLARITY_T polarity)
Definition: kx122.cxx:188
void getRawAccelerationData(float *x, float *y, float *z)
Definition: kx122.cxx:70
void deviceInit(KX122_ODR_T odr, KX122_RES_T res, KX122_RANGE_T grange)
Definition: kx122.cxx:48
void disableBuffer()
Definition: kx122.cxx:280
void enableBuffer()
Definition: kx122.cxx:273
void enableDataReadyInterrupt()
Definition: kx122.cxx:245
void setAverage(KX122_AVG_T avg)
Definition: kx122.cxx:162
uint8_t getInterruptSource()
Definition: kx122.cxx:228
C API for the kx122 driver.
KX122(int bus, int addr, int chip_select, int spi_bus_frequency=DEFAULT_SPI_FREQUENCY)
Definition: kx122.cxx:35
void clearBuffer()
Definition: kx122.cxx:364
void routeInterrupt2(uint8_t bits)
Definition: kx122.cxx:216
void enableBufferFullInterrupt()
Definition: kx122.cxx:259
Definition: kx122.h:140