upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
kxtj3.hpp
1 /*
2 * The MIT License (MIT)
3 *
4 * Author: Assam Boudjelthia
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 "kxtj3.h"
31 
53 namespace upm
54 {
55 class KXTJ3
56 {
57 public:
67  KXTJ3(int bus, uint8_t addr = 0x0f);
68 
77  virtual ~KXTJ3();
78 
90  void SensorInit(KXTJ3_ODR_T odr, KXTJ3_RESOLUTION_T resolution, KXTJ3_G_RANGE_T g_range);
91 
98  uint8_t GetWhoAmI();
99 
105  void SensorActive();
106 
112  void SensorStandby();
113 
124  void SetGRange(KXTJ3_G_RANGE_T g_range);
125 
138  void SetResolution(KXTJ3_RESOLUTION_T resolution);
139 
148  void SetOdr(KXTJ3_ODR_T odr);
149 
158  void SetOdrForWakeup(KXTJ3_ODR_WAKEUP_T odr);
159 
172 
185  void SensorSelfTest();
186 
197  void SensorSoftwareReset();
198 
205  std::vector<float> GetAccelerationRawVector();
206 
213  std::vector<float> GetAccelerationVector();
214 
223 
231  float GetWakeUpSamplePeriod();
232 
242 
251 
259  void EnableWakeUpInterrupt();
260 
268  void DisableWakeUpInterrupt();
269 
285  void EnableInterruptPin(KXTJ3_INTERRUPT_POLARITY_T polarity, KXTJ3_INTERRUPT_RESPONSE_T response_type);
286 
294  void DisableInterruptPin();
295 
306  void SetInterruptPolarity(KXTJ3_INTERRUPT_POLARITY_T polarity);
307 
323  void SetInerruptResponse(KXTJ3_INTERRUPT_RESPONSE_T response_type);
324 
333  bool GetInterruptStatus();
334 
344  uint8_t ReadInterruptSource1();
345 
353  KXTJ3_INTERRUPT_SOURCE_T GetInterruptSource();
354 
364  void InstallIsr(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args);
365 
371  void UninstallIsr();
372 
380  void ClearInterrupt();
381 
390  void EnableWakeUpSingleAxisDirection(KXTJ3_WAKEUP_SOURCE_T axis);
391 
400  void DisableWakeUpSingleAxisDirection(KXTJ3_WAKEUP_SOURCE_T axis);
401 
411 
422  void EnableWakeUpLatch();
423 
439  void DisableWakeUpLatch();
440 
456  void SetWakeUpMotionCounter(uint8_t count);
457 
470  void SetWakeUpMotionTime(float desired_time);
471 
478  float GetWakeUpMotionTime();
479 
495  void SetWakeUpNonActivityCounter(uint8_t count);
496 
509  void SetWakeUpNonActivityTime(float desired_time);
510 
517  float GetWakeUpNonActivityTime();
518 
533  void SetWakeUpThresholdCounter(uint16_t count);
534 
548  void SetWakeUpThresholdGRange(float g_threshold);
549 
556  float GetWakeUpThresholdGRange();
557 
558 private:
559  kxtj3_context m_kxtj3;
560 
561  /* Disable implicit copy and assignment operators */
562  KXTJ3(const KXTJ3 &) = delete;
563  KXTJ3 &operator=(const KXTJ3 &) = delete;
564 };
565 } // namespace upm
void EnableWakeUpSingleAxisDirection(KXTJ3_WAKEUP_SOURCE_T axis)
Enables wakeup interrupt for the given axis (axis with direction)
Definition: kxtj3.cxx:225
float GetWakeUpThresholdGRange()
Get the current threshold difference value before sending wakeup interrupt.
Definition: kxtj3.cxx:308
void SetResolution(KXTJ3_RESOLUTION_T resolution)
Sets the resolution of the sensor. High resolution (14 bits and 12 bits) or low resolution (8 bits)...
Definition: kxtj3.cxx:77
void SensorSelfTest()
Performs a self-test of the sensor. The test applies an electrostatic force to the sensor...
Definition: kxtj3.cxx:101
Definition: kxtj3.hpp:55
void DisableInterruptPin()
Disables interrupts on the interrupt pin of the sensor.
Definition: kxtj3.cxx:171
void SetGRange(KXTJ3_G_RANGE_T g_range)
Sets the acceleration range of the sensor.
Definition: kxtj3.cxx:71
void SensorActive()
Sets the sensor to active mode.
Definition: kxtj3.cxx:59
void SetWakeUpMotionTime(float desired_time)
Sets the timer of motion before sending a wakeup interrupt.
Definition: kxtj3.cxx:260
void SensorStandby()
Sets the sensor to standby mode.
Definition: kxtj3.cxx:65
void SetWakeUpNonActivityTime(float desired_time)
Sets the timer of non-activity before sending another wakeup interrupt.
Definition: kxtj3.cxx:281
void SetWakeUpNonActivityCounter(uint8_t count)
Sets the timer counter of non-activity before sending another wakeup interrupt.
Definition: kxtj3.cxx:275
float GetWakeUpMotionTime()
Get the current count value of the timer of motion before sending a wakeup interrupt.
Definition: kxtj3.cxx:266
void SetInerruptResponse(KXTJ3_INTERRUPT_RESPONSE_T response_type)
Sets the response type of the interrupt pin.
Definition: kxtj3.cxx:183
float GetWakeUpNonActivityTime()
Get the current count value of the timer of non-activity before sending another wakeup interrupt...
Definition: kxtj3.cxx:287
void SetInterruptPolarity(KXTJ3_INTERRUPT_POLARITY_T polarity)
Sets the polarity of the interrupt pin.
Definition: kxtj3.cxx:177
void UninstallIsr()
Uninstalls a previously installed interrupt handler for interrupt pin.
Definition: kxtj3.cxx:214
void DisableWakeUpInterrupt()
Disables the wakeup function (motion detection)
Definition: kxtj3.cxx:159
Use it to get axis and direction for wake-up function.
Definition: kxtj3.h:168
void SensorSoftwareReset()
Performs a sensor software reset. The software reset clears the RAM of the sensor and resets all regi...
Definition: kxtj3.cxx:107
void DisableWakeUpSingleAxisDirection(KXTJ3_WAKEUP_SOURCE_T axis)
Disables wakeup interrupt for the given axis (axis with direction)
Definition: kxtj3.cxx:231
void SetWakeUpThresholdGRange(float g_threshold)
Sets the threshold g value for acceleration difference before sending a wakeup interrupt.
Definition: kxtj3.cxx:302
void DisableDataReadyInterrupt()
Disables the data ready interrupt.
Definition: kxtj3.cxx:147
void SetWakeUpThresholdCounter(uint16_t count)
Sets the threshold counter for acceleration difference before sending a wakeup interrupt.
Definition: kxtj3.cxx:296
void SensorInit(KXTJ3_ODR_T odr, KXTJ3_RESOLUTION_T resolution, KXTJ3_G_RANGE_T g_range)
Initializes the sensor with given sampling rate, resolution and acceleration range. This gets called in the constructor, so it will not need to be called unless the device is reset.
Definition: kxtj3.cxx:44
void EnableWakeUpLatch()
Enables the Unlatched mode motion interrupt (ULMODE). This mode is always by default enabled...
Definition: kxtj3.cxx:242
float GetWakeUpSamplePeriod()
Gets the duration of one sample period (in seconds) for the wakeup function depending on the sampling...
Definition: kxtj3.cxx:136
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
bool GetInterruptStatus()
Gets the status of the interrupts. (Has an interrupt occurred)
Definition: kxtj3.cxx:189
void InstallIsr(mraa_gpio_edge_t edge, int pin, void(*isr)(void *), void *isr_args)
Installs an interrupt handler to be executed when an interrupt is detected on the interrupt pin...
Definition: kxtj3.cxx:208
void SetOdr(KXTJ3_ODR_T odr)
Sets the ODR of the sensor.
Definition: kxtj3.cxx:83
float GetAccelerationSamplePeriod()
Gets the duration of one sample period (in seconds) for getting the acceleration data depending on th...
Definition: kxtj3.cxx:131
std::vector< float > GetAccelerationVector()
Definition: kxtj3.cxx:122
void SetWakeUpMotionCounter(uint8_t count)
Sets the timer counter of motion before sending a wakeup interrupt.
Definition: kxtj3.cxx:254
std::vector< float > GetAccelerationRawVector()
Definition: kxtj3.cxx:113
void DisableWakeUpLatch()
Disables the Unlatched mode motion interrupt (ULMODE). This mode is always by default enabled...
Definition: kxtj3.cxx:248
void EnableDataReadyInterrupt()
Enables the data ready interrupt. Availability of new acceleration data is reflected as an interrupt...
Definition: kxtj3.cxx:141
virtual ~KXTJ3()
KXTJ3 destructor.
Definition: kxtj3.cxx:39
uint8_t ReadInterruptSource1()
Gets the source of the interrupt The value stored is one or more of the KXTJ3_INTERRUPT_SOURCE_T valu...
Definition: kxtj3.cxx:194
KXTJ3(int bus, uint8_t addr=0x0f)
KXTJ3 constructor.
Definition: kxtj3.cxx:33
void ClearInterrupt()
Clears latching interrupts information of Wakeup (with axis and direction information) and Data Ready...
Definition: kxtj3.cxx:219
void SelfTestDigitalCommunication()
Performs a self-test for digital communication of the sensor. The test sets DCST bit in CTRL_REG2...
Definition: kxtj3.cxx:95
uint8_t GetWhoAmI()
Gets "who am I" value of the sensor.
Definition: kxtj3.cxx:50
void SetOdrForWakeup(KXTJ3_ODR_WAKEUP_T odr)
Sets the ODR of the wakeup function of the sensor.
Definition: kxtj3.cxx:89
KXTJ3_INTERRUPT_SOURCE_T GetInterruptSource()
Gets the source of the interrupt.
Definition: kxtj3.cxx:203
void EnableInterruptPin(KXTJ3_INTERRUPT_POLARITY_T polarity, KXTJ3_INTERRUPT_RESPONSE_T response_type)
Enables interrupts on the interrupt pin, sets polarity and response types. Polarity ACTIVE_HIGH or AC...
Definition: kxtj3.cxx:165
kxtj3_wakeup_axes GetWakeUpAxisDirection()
Gets the source axis and direction of motion detection of the wakeup function interrupt.
Definition: kxtj3.cxx:237
Sensor context.
Definition: kxtj3.h:181
void EnableWakeUpInterrupt()
Enables the wakeup function (motion detection)
Definition: kxtj3.cxx:153