/*********************************************************************** * I.MX6 Linux、Jni ioctl 差异 * 声明: * 在使用Jni的ioctl()的过程中,发现不能像普通的Linux函数那样使用, * 必须使用3各参数的ioctl()函数。 * * 2015-12-20 深圳 南山平山村 曾剑锋 **********************************************************************/#include#include #include #include #include #include #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. ");}