鴻蒙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

作者:卡哇伊大喵
想了解更多內容,請訪問51CTO和華為合作共建的鴻蒙社區:https://harmonyos.51cto.com


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM