zoukankan      html  css  js  c++  java
  • I.MX6 Linux、Jni ioctl 差异

    /***********************************************************************
     *                      I.MX6 Linux、Jni ioctl 差异
     * 声明:
     *     在使用Jni的ioctl()的过程中,发现不能像普通的Linux函数那样使用,
     * 必须使用3各参数的ioctl()函数。
     * 
     *                                   2015-12-20 深圳 南山平山村 曾剑锋
     **********************************************************************/
    
    
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <string.h>
    #include <jni.h>
    
    #include "android/log.h"
    static const char *TAG="Buzz";
    #define LOGE(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, TAG, fmt, ##args)
    
    #define BUZZER_ENABLE   82
    #define BUZZER_FREQENCY 83
    #define BUZZER_DISABLE  84
    
    /*
     * Class:     com_android_buzz_Buzz
     * Method:    enable
     * Signature: ()V
     */
    JNIEXPORT void JNICALL Java_com_android_buzz_Buzz_enable
      (JNIEnv *env, jobject obj) {
        int fd = open("/dev/buzzer", O_RDWR);
        if ( fd == -1 ) {
            LOGE("open buzzer device error.");
            return;
        }
    
        // ioctl(fd, BUZZER_ENABLE);        // 不能这样使用
        ioctl(fd, BUZZER_ENABLE, 0);        // 得这么使用
    
        close(fd);
    
        //LOGE("enable buzzer device. ");
    }
    
    /*
     * Class:     com_android_buzz_Buzz
     * Method:    setFrequency
     * Signature: (I)V
     */
    JNIEXPORT void JNICALL Java_com_android_buzz_Buzz_setFrequency
      (JNIEnv *env, jobject obj, jint frequency) {
    
        int fd = open("/dev/buzzer", O_RDWR);
        if ( fd == -1 ) {
            LOGE("open buzzer device error.");
            return;
        }
    
        ioctl(fd, BUZZER_FREQENCY, frequency);
    
        close(fd);
    
        //LOGE("set buzzer device frequency. ");
    }
    
    /*
     * Class:     com_android_buzz_Buzz
     * Method:    disable
     * Signature: ()V
     */
    JNIEXPORT void JNICALL Java_com_android_buzz_Buzz_disable
      (JNIEnv *env, jobject obj) {
    
        int fd = open("/dev/buzzer", O_RDWR);
        if ( fd == -1 ) {
            LOGE("open buzzer device error.");
            return;
        }
    
        // ioctl(fd, BUZZER_DISABLE);       // 不能这样使用
        ioctl(fd, BUZZER_DISABLE, 0);       // 得这么使用
    
        close(fd);
    
        //LOGE("disable buzzer device. ");
    }
  • 相关阅读:
    欧拉公式
    isap的一些想法
    错误合集
    Hello World
    PAT (Advanced Level) Practice 1068 Find More Coins
    PAT (Advanced Level) 1087 All Roads Lead to Rome
    PAT (Advanced Level) 1075 PAT Judge
    PAT (Advanced Level) 1067 Sort with Swap(0, i)
    PAT (Advanced Level) 1017 Queueing at Bank
    PAT (Advanced Level) 1025 PAT Ranking
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/5060715.html
Copyright © 2011-2022 走看看