鸿蒙ACE框架-使用JS调用C++(1) 原创 精华

卡哇伊大喵
发布于 2021-4-29 09:27
浏览
0收藏

鸿蒙ACE框架-使用JS调用C++(1)

鸿蒙ACE框架-使用JS调用C++(1)-开源基础软件社区

1.下载编译烧录代码
https://blog.csdn.net/qq_33259323/article/details/116143820

2.编写测试用例
打开foundation\ace\ace_engine_lite\frameworks\src\core\modules\app_module.h

static JSIValue ToggleLed(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum);
JSI::SetModuleAPI(exports, "toggleLed", AppModule::ToggleLed);

鸿蒙ACE框架-使用JS调用C++(1)-开源基础软件社区打开foundation\ace\ace_engine_lite\frameworks\src\core\modules\app_module.cpp

JSIValue AppModule::ToggleLed(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum)
{
    HILOG_ERROR(HILOG_MODULE_ACE, "led button pressed.");
    printf("led button pressed\n");
 
    return JSI::CreateUndefined();
}

鸿蒙ACE框架-使用JS调用C++(1)-开源基础软件社区

之后就进行编译烧录,C++层的就弄好了

3.编写HAP
打开C:\Users\XX\AppData\Local\Huawei\Sdk\js\2.1.1.18\api\smartVision\@system.app.d.ts添加API

static toggleLed(): void;

鸿蒙ACE框架-使用JS调用C++(1)-开源基础软件社区然后打开DEVECO在你的页面上写个按钮和加个点击事件

<input class="btu" type="button" value="进入" onclick="led"></input>
import router from '@system.router';
import app from '@system.app'
 
export default {
    data: {
 
    },
    onInit() {
 
    },
    led: function(){
        
        app.toggleLed();
    }
}

然后把编写好的HAP包装到3516上面

https://blog.csdn.net/qq_33259323/article/details/111307192

4.运行
 

鸿蒙ACE框架-使用JS调用C++(1)-开源基础软件社区

参考:https://harmonyos.51cto.com/posts/3112

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
标签
3
收藏
回复
举报
1条回复
按时间正序
/
按时间倒序
Whyalone
Whyalone

喵喵喵!

回复
2021-4-29 10:10:54
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源 去关联
    相关推荐