|
| 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 | +#include <stdio.h> |
| 26 | +#include <unistd.h> |
| 27 | +#include <signal.h> |
| 28 | + |
| 29 | +#include "kx122.h" |
| 30 | + |
| 31 | +bool shouldRun = true; |
| 32 | + |
| 33 | +void sig_handler(int signo) |
| 34 | +{ |
| 35 | + if(signo == SIGINT){ |
| 36 | + shouldRun = false; |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +int main(int argc, char **argv) |
| 41 | +{ |
| 42 | + signal(SIGINT,sig_handler); |
| 43 | + kx122_context sensor = kx122_init(0,-1,24); |
| 44 | + if (!sensor) |
| 45 | + { |
| 46 | + printf("kx122_init() failed.\n"); |
| 47 | + return 1; |
| 48 | + } |
| 49 | + |
| 50 | + kx122_sensor_software_reset(sensor); |
| 51 | + kx122_device_init(sensor,KX122_ODR_50,HIGH_RES,KX122_RANGE_2G); |
| 52 | + |
| 53 | + float x,y,z; |
| 54 | + float wait_time = (kx122_get_sample_period(sensor) * MICRO_S); |
| 55 | + |
| 56 | + while(shouldRun){ |
| 57 | + kx122_get_acceleration_data(sensor,&x,&y,&z); |
| 58 | + |
| 59 | + printf("%.02f | %.02f | %.02f\n",x,y,z); |
| 60 | + usleep(wait_time); |
| 61 | + } |
| 62 | + |
| 63 | + kx122_close(sensor); |
| 64 | + return 0; |
| 65 | +} |
0 commit comments