android 4 led insmod,Android LED HAL调试

本文介绍了Mokoid Led Service中JNI的实现,包括定义常量LOG_TAG,包含多个JNI方法如setOn和setOff,用于LED设备的控制操作。还展示了如何初始化LED模块、打开设备和注册Native方法。
摘要由CSDN通过智能技术生成

#define LOG_TAG "Mokoid"

#include "utils/Log.h"

#include

#include

#include

#include

#include

#include "led.h"

// ----------------------------------------------------------------------------

structled_control_device_t*sLedDevice=NULL;

staticjboolean mokoid_setOn(JNIEnv*env,jobject thiz,jint led)

{

LOGI("LedService JNI: mokoid_setOn() is invoked.");

if(sLedDevice==NULL){

LOGI("LedService JNI: sLedDevice was not fetched correctly.");

return-1;

}else{

returnsLedDevice->set_on(sLedDevice,led);

}

}

staticjboolean mokoid_setOff(JNIEnv*env,jobject thiz,jint led)

{

LOGI("LedService JNI: mokoid_setOff() is invoked.");

if(sLedDevice==NULL){

LOGI("LedService JNI: sLedDevice was not fetched correctly.");

return-1;

}else{

returnsLedDevice->set_off(sLedDevice,led);

}

}

/** helper APIs */

staticinlineintled_control_open(conststructhw_module_t*module,

structled_control_device_t**device){

returnmodule->methods->open(module,

LED_HARDWARE_MODULE_ID,(structhw_device_t**)device);

}

staticjboolean mokoid_init(JNIEnv*env,jclass clazz)

{

led_module_t*module;

if(hw_get_module(LED_HARDWARE_MODULE_ID,(consthw_module_t**)&module)==0){

LOGI("LedService JNI: LED Stub found.");

if(led_control_open(&module->common,&sLedDevice)==0){

LOGI("LedService JNI: Got Stub operations.");

return0;

}

}

LOGE("LedService JNI: Get Stub operations failed.");

return-1;

}

// --------------------------------------------------------------------------

/*

* Array of methods.

*

* Each entry has three fields: the name of the method, the method

* signature, and a pointer to the native implementation.

*/

staticconstJNINativeMethod gMethods[]={

{"_init","()Z",(void*)mokoid_init},

{"_set_on","(I)Z",(void*)mokoid_setOn},

{"_set_off","(I)Z",(void*)mokoid_setOff},

};

intregister_mokoid_server_LedService(JNIEnv*env){

staticconstchar*constkClassName=

"com/mokoid/server/LedService";

jclass clazz;

/* look up the class */

clazz=env->FindClass(kClassName);

if(clazz==NULL){

LOGE("Can't find class %s\n",kClassName);

return-1;

}

/* register all the methods */

if(env->RegisterNatives(clazz,gMethods,

sizeof(gMethods)/sizeof(gMethods[0]))!=JNI_OK)

{

LOGE("Failed registering methods for %s\n",kClassName);

return-1;

}

/* fill out the rest of the ID cache */

return0;

}

staticintregisterMethods(JNIEnv*env){

staticconstchar*constkClassName="com/mokoid/server/LedService";

jclass clazz;

/* look up the class */

clazz=env->FindClass(kClassName);

if(clazz==NULL){

LOGE("Can't find class %s/n",kClassName);

return-1;

}

/* register all the methods */

if(env->RegisterNatives(clazz,gMethods,

sizeof(gMethods)/sizeof(gMethods[0]))!=JNI_OK)

{

LOGE("Failed registering methods for %s/n",kClassName);

return-1;

}

/* fill out the rest of the ID cache */

return0;

}

/*

* This is called by the VM when the shared library is first loaded.

*/

jint JNI_OnLoad(JavaVM*vm,void*reserved){

JNIEnv*env=NULL;

jint result=-1;

LOGI("JNI_OnLoad LED");

if(vm->GetEnv((void**)&env,JNI_VERSION_1_4)!=JNI_OK){

LOGE("ERROR: GetEnv failed/n");

gotofail;

}

assert(env!=NULL);

if(registerMethods(env)!=0){

LOGE("ERROR: PlatformLibrary native registration failed/n");

gotofail;

}

/* success -- return valid version number */

result=JNI_VERSION_1_4;

fail:

returnresult;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值