鴻蒙ACE框架-使用JS調(diào)用C++(1)
51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)
鴻蒙ACE框架-使用JS調(diào)用C++(1)
1.下載編譯燒錄代碼
https://blog.csdn.net/qq_33259323/article/details/116143820
2.編寫測(cè)試用例
打開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);
打開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();
- }
之后就進(jìn)行編譯燒錄,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;
然后打開DEVECO在你的頁面上寫個(gè)按鈕和加個(gè)點(diǎn)擊事件
- <input class="btu" type="button" value="進(jìn)入" 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.運(yùn)行
參考:https://harmonyos.51cto.com/posts/3112
51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)