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 | #include <stdint.h> |
| 36 | #include <errno.h> |
| 37 | #include <unistd.h> |
| 38 | #include <string.h> |
| 39 | #include <inttypes.h> |
| 40 | |
| 41 | #include <memory> |
| 42 | #include <thread> |
| 43 | #include <functional> |
| 44 | |
| 45 | #include <HfManager.h> |
| 46 | |
| 47 | int main(int argc, char **argv) { |
| 48 | int fd = -1; |
| 49 | int sensor = 0, action = 0, delay = 0, latency = 0; |
| 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, "command: [%d,%d,%d,%d]\n", sensor, action, delay, latency); |
| 63 | |
| 64 | std::unique_ptr<HfManager> mHfManager(new HfManager()); |
| 65 | fd = mHfManager->getFd(); |
| 66 | std::thread looperThread([fd]() { |
| 67 | std::unique_ptr<HfLooper> mHfLooper(new HfLooper(fd, 64)); |
| 68 | while (1) { |
| 69 | int err = mHfLooper->eventLooper([](sensors_event_t const * event) { |
| 70 | fprintf(stderr, "data: [%d,%d,%" PRId64 ",%f,%f,%f]\n", |
| 71 | event->sensor, event->reserved0, event->timestamp, |
| 72 | event->data[0], event->data[1], event->data[2]); |
| 73 | }); |
| 74 | switch (err) { |
| 75 | case -ENODEV: |
| 76 | fprintf(stderr, "looper stop nodevice error\n"); |
| 77 | return; |
| 78 | } |
| 79 | }; |
| 80 | }); |
| 81 | looperThread.detach(); |
| 82 | if (mHfManager->findSensor(sensor) < 0) |
| 83 | return -2; |
| 84 | switch (action) { |
| 85 | case HF_MANAGER_SENSOR_DISABLE: |
| 86 | mHfManager->disableSensor(sensor); |
| 87 | break; |
| 88 | case HF_MANAGER_SENSOR_ENABLE: |
| 89 | mHfManager->enableSensor(sensor, delay, latency); |
| 90 | break; |
| 91 | case HF_MANAGER_SENSOR_ENABLE_CALI: |
| 92 | mHfManager->requestFactoryCalibration(sensor, true); |
| 93 | mHfManager->enableFactoryCalibration(sensor); |
| 94 | break; |
| 95 | case HF_MANAGER_SENSOR_RAWDATA: |
| 96 | mHfManager->enableRawData(sensor); |
| 97 | break; |
| 98 | } |
| 99 | while (1) |
| 100 | sleep(1); |
| 101 | return 0; |
| 102 | } |