rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright Statement: |
| 3 | * |
| 4 | * This software/firmware and related documentation ("MediaTek Software") are |
| 5 | * protected under relevant copyright laws. The information contained herein is |
| 6 | * confidential and proprietary to MediaTek Inc. and/or its licensors. Without |
| 7 | * the prior written permission of MediaTek inc. and/or its licensors, any |
| 8 | * reproduction, modification, use or disclosure of MediaTek Software, and |
| 9 | * information contained herein, in whole or in part, shall be strictly |
| 10 | * prohibited. |
| 11 | * |
| 12 | * MediaTek Inc. (C) 2017. All rights reserved. |
| 13 | * |
| 14 | * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 15 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 16 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER |
| 17 | * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL |
| 18 | * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED |
| 19 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR |
| 20 | * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH |
| 21 | * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, |
| 22 | * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES |
| 23 | * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. |
| 24 | * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO |
| 25 | * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK |
| 26 | * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE |
| 27 | * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR |
| 28 | * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S |
| 29 | * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE |
| 30 | * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE |
| 31 | * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE |
| 32 | * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 33 | */ |
| 34 | |
| 35 | |
| 36 | #include <stdio.h> |
| 37 | #include <stdint.h> |
| 38 | #include <errno.h> |
| 39 | #include <unistd.h> |
| 40 | #include <string.h> |
| 41 | #include <inttypes.h> |
| 42 | #include <stdlib.h> |
| 43 | #include <functional> |
| 44 | |
| 45 | #include <HfManagerWrapper.h> |
| 46 | |
| 47 | int main(int argc, char **argv) { |
| 48 | int sensor = 0, action = 0, delay = 0, latency = 0; |
| 49 | sensors_event_t data[32]; |
| 50 | |
| 51 | if (argc != 5) { |
| 52 | fprintf(stderr, "usage: execute sensor action delay latency\n"); |
| 53 | fprintf(stderr, " ./high_freq_sensor_tool 1 1 5000000 0\n"); |
| 54 | return -1; |
| 55 | } |
| 56 | |
| 57 | sensor = atoi(argv[1]); |
| 58 | action = atoi(argv[2]); |
| 59 | delay = atoi(argv[3]); |
| 60 | latency = atoi(argv[4]); |
| 61 | |
| 62 | fprintf(stderr, "cwrapper command: [%d,%d,%d,%d]\n", sensor, action, delay, latency); |
| 63 | |
| 64 | void *mHfManager = HfManagerCreate(); |
| 65 | void *mHfLooper = HfLooperCreate(HfManagerGetFd(mHfManager), 64); |
| 66 | |
| 67 | if (HfManagerFindSensor(mHfManager, sensor) < 0) |
| 68 | return -2; |
| 69 | switch (action) { |
| 70 | case HF_MANAGER_SENSOR_DISABLE: |
| 71 | HfManagerDisableSensor(mHfManager, sensor); |
| 72 | break; |
| 73 | case HF_MANAGER_SENSOR_ENABLE: |
| 74 | HfManagerEnableSensor(mHfManager, sensor, delay, latency); |
| 75 | break; |
| 76 | case HF_MANAGER_SENSOR_RAWDATA: |
| 77 | HfManagerEnableRawData(mHfManager, sensor); |
| 78 | break; |
| 79 | } |
| 80 | while (1) { |
| 81 | int err = HfLooperEventLooper(mHfLooper, data, 32); |
| 82 | switch (err) { |
| 83 | case -ENODEV: |
| 84 | fprintf(stderr, "cwrapper looper stop nodevice error\n"); |
| 85 | return -3; |
| 86 | } |
| 87 | for (int i = 0; i < err; ++i) { |
| 88 | fprintf(stderr, "cwrapper data: [%d,%d,%" PRId64 ",%f,%f,%f]\n", |
| 89 | data[i].sensor, data[i].reserved0, data[i].timestamp, |
| 90 | data[i].data[0], data[i].data[1], data[i].data[2]); |
| 91 | } |
| 92 | } |
| 93 | return 0; |
| 94 | } |