成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

[FFH]標準系統(tǒng)HDF平臺驅(qū)動(三)——ADC應(yīng)用實現(xiàn)

系統(tǒng) OpenHarmony
結(jié)合之前學(xué)的一些知識,設(shè)計一個基于NAPI框架和HDF框架讀取溫度傳感器數(shù)據(jù)的程序應(yīng)用。

??想了解更多關(guān)于開源的內(nèi)容,請訪問:??

??51CTO 開源基礎(chǔ)軟件社區(qū)??

??https://ost.51cto.com??

前言

前面兩篇文章已經(jīng)實現(xiàn)了ADC的HDF框架接入,現(xiàn)在已經(jīng)可以正常調(diào)用HDF提供的ADC統(tǒng)一驅(qū)動接口進行應(yīng)用開發(fā)。結(jié)合之前學(xué)的一些知識,設(shè)計一個基于NAPI框架和HDF框架讀取溫度傳感器數(shù)據(jù)的程序應(yīng)用。

#創(chuàng)作者激勵# [FFH]標準系統(tǒng)HDF平臺驅(qū)動(三)——ADC應(yīng)用實現(xiàn)-開源基礎(chǔ)軟件社區(qū)

參考

??平臺驅(qū)動使用??標準系統(tǒng)HDF平臺驅(qū)動(一)——ADC驅(qū)動適配
標準系統(tǒng)HDF平臺驅(qū)動(二)——ADC平臺驅(qū)動使用

環(huán)境

  • OpenHarmony-3.2-Beta5
  • 九聯(lián)UnionPi-Tiger開發(fā)板
  • Visual Studio Code(版本需1.62.0及以上)
  • USB_Burning_Tool燒錄工具
  • napi_generator工具可執(zhí)行文件或vs code插件
  • Deveco Studio(API 9 )
  • LM35線性模擬溫度傳感器

概述

開發(fā)步驟

一、編譯構(gòu)建實現(xiàn)

添加子系統(tǒng)。

"napisubsys":{
"path":"vendor/unionman/unionpi_tiger/sample/napi/napisubsys",
"name":"napisubsys"
}

添加組件,打開unionpi_tiger/sample/napi/napisubsys/ohos.build文件,在"parts":中添加下列語句。

"adc_hdf": {
"variants": [
"phone"
],
"module_list": [
"http://vendor/unionman/unionpi_tiger/sample/napi/napisubsys/adc_hdf:adc_hdf"
]
}

添加產(chǎn)品定義,打開vendor/unionman/unionpi_tiger/config.json文件,在"subsystems":中添加下列語句。

{
"subsystem": "napisubsys",
"components": [
{
"component": "adc_hdf",
"features": []
}
]
},

二、NAPI接口設(shè)計及NAPI框架生成

編寫ts文件,新建文件@ohos.adc_hdf.d.ts于vendor/unionman/unionpi_tiger/sample/napi/napisubsys/adc_hdf目錄下,聲明應(yīng)用接口函數(shù)get_adc_value,傳入?yún)?shù)為通道號,返回值為ADC采樣值,北向應(yīng)用通過調(diào)用該接口獲取的ADC采樣值計算溫度。

declare namespace adc_hdf {
function get_adc_value(channel: number): number;
}

export default adc_hdf;

生成NAPI框架,使用napi_generator可執(zhí)行程序或者vscode插件生成NAPI框架。

生成框架路徑也選擇當前路徑,number類型選擇uint32_t。

三、NAPI接口實現(xiàn)

實現(xiàn)adc_hdf.cpp接口,文件生成結(jié)束后,我們定義的北向應(yīng)用接口需要在adc_hdf.cpp中實現(xiàn),具體代碼如下:

#include "adc_hdf.h"
#include "adc_if.h"
#include "hdf_log.h"
#include <cstdio>

namespace adc_hdf {
bool get_adc_value(NUMBER_TYPE_1& channel, NUMBER_TYPE_2& out)
{
int32_t ret;
DevHandle adcHandle = NULL;
uint32_t read_val = 0;

/* 打開ADC設(shè)備 */
adcHandle = AdcOpen(ADC_DEVICE_NUM);
if (adcHandle == NULL) {
printf("%s: Open ADC%u fail!", __func__, ADC_DEVICE_NUM);
return false;
}
/* 讀取ADC采樣值 */
ret = AdcRead(adcHandle, (uint32_t)channel, &read_val);
if (ret != HDF_SUCCESS) {
printf("%s: ADC read fail!:%d", __func__, ret);
AdcClose(adcHandle);
return false;
}
/* 結(jié)果返回值 */
out = (NUMBER_TYPE_2)read_val;
printf("ADC read:%d\r\n",read_val);
/* 訪問完畢關(guān)閉ADC設(shè)備 */
AdcClose(adcHandle);
return true;
}
}

修改BUILD.gn文件,主要添加了ADC平臺驅(qū)動所需依賴及頭文件路徑,并且修改目標子系統(tǒng)及所屬部件,編譯后會生成相應(yīng)的.so共享庫文件,存放在/system/lib/module目錄下。

import("http://build/ohos.gni")

ohos_shared_library("adc_hdf")
{
sources = [
"adc_hdf_middle.cpp",
"adc_hdf.cpp",
"tool_utility.cpp",
]
include_dirs = [
".",
"http://third_party/node/src",
"http://drivers/hdf_core/framework/include/platform"
]
deps=[
"http://foundation/arkui/napi:ace_napi",
"http://drivers/hdf_core/adapter/uhdf2/platform:libhdf_platform"
]
external_deps = [
"hdf_core:libhdf_utils",
"hiviewdfx_hilog_native:libhilog",
]

remove_configs = [ "http://build/config/compiler:no_rtti" ]
cflags=[
]
cflags_cc=[
"-frtti",
]
ldflags = [
]

relative_install_dir = "module"
part_name = "adc_hdf"
subsystem_name = "napisubsys"
}

四、編譯打包燒錄

進入源碼根目錄,執(zhí)行如下命令進行編譯:

./build.sh --product-name unionpi_tiger

編譯完成后需要打包成可以給開發(fā)板燒錄的鏡像,執(zhí)行一下命令:

./device/board/unionman/unionpi_tiger/common/tools/packer-unionpi.sh

固件打包完成,生成路徑為編譯根目錄下的out/unionpi_tiger/packages/phone/images/OpenHarmony.img,下載或映射到Windows上進行燒錄。

打開燒錄工具,連接PC與開發(fā)板OTG口并接通電源,導(dǎo)入燒錄包進行燒錄。

#創(chuàng)作者激勵# [FFH]標準系統(tǒng)HDF平臺驅(qū)動(三)——ADC應(yīng)用實現(xiàn)-開源基礎(chǔ)軟件社區(qū)

或者使用hdc_std工具:

hdc_std shell mount -o remount,rw /
hdc_std file send libadc_hdf.z.so /system/lib/module/

五、NAPI應(yīng)用實現(xiàn)

新建OpenHarmony工程(stage+ArkTs)。

導(dǎo)入外部接口,adc_hdf為上述定義NAPI接口生成的動態(tài)庫文件名字一致,直接導(dǎo)入會報找不到包,忽略即可,prompt為彈窗組件接口。

// @ts-ignore
import adc_hdf from '@ohos.adc_hdf';
import prompt from '@system.prompt'

ADC通道選擇組件(使用Swiper滑塊視圖容器實現(xiàn))。新建滑塊視圖數(shù)據(jù)類。

class MyDataSource implements IDataSource {
private list: string[] = []
private listener: DataChangeListener

constructor(list: string[]) {
this.list = list
}

totalCount(): number {
return this.list.length
}

getData(index: number): any {
return this.list[index]
}

registerDataChangeListener(listener: DataChangeListener): void {
this.listener = listener
}

unregisterDataChangeListener() {
}
}

Swiper滑塊視圖容器組件,滑動或點擊可以切換ADC通道,點擊select進行數(shù)據(jù)采集。

//通道選擇組件實現(xiàn)
@Component
struct channel_chose {
private swiperController: SwiperController = new SwiperController()
private data: MyDataSource = new MyDataSource([])
private channelNum: number = 2
private tmp: number = 1
@Link channel: number
//導(dǎo)入輪播內(nèi)容
aboutToAppear(): void {
let list = []
for (var i = 1; i <= this.channelNum; i++) {
list.push('ADC_' + i.toString());
}
this.data = new MyDataSource(list)
}

build() {
Column({ space: 5 }) {
Swiper(this.swiperController) {
LazyForEach(this.data, (item: string) => {
Text(item)
.borderRadius(10)
.width('80%')
.height(70)
.fontColor('#ff1a5ea4')
.fontWeight(FontWeight.Bolder)
.textAlign(TextAlign.Center)
.fontSize(30)
}, item => item)
}
.cachedCount(2)
.interval(4000)
.indicator(false)
.duration(1000)
.itemSpace(10)
.vertical(true)
.curve(Curve.Linear)
.onChange((index: number) => {
this.tmp = index + 1
})

Row({ space: 12 }) {
Button('Change').backgroundColor('#ff366fb1').fontSize(20).height(50).width(120)
.onClick(() => {
this.swiperController.showNext()
})
Button('Select').backgroundColor('#ff366fb1').fontSize(20).height(50).width(120)
.onClick(() => {
this.channel = this.tmp;
prompt.showToast({ message: 'Select data From ADC_'+this.channel.toString() })
console.info('Select data From Channel_'+this.channel.toString())
})
}.margin(20)
}.width('50%')
}
}

文本組件顯示溫度值。

@Component
struct show_temperature{
@Link temperature: Number
build(){
Text(this.temperature.toFixed(1)+'°C')
.width('50%')
.fontSize(60)
.fontColor(Color.White)
.fontStyle(FontStyle.Italic)
.textAlign(TextAlign.Center)
.fontWeight(FontWeight.Bold)
}
}

溫度計算及首頁內(nèi)容組件,程序啟動時開啟定時器,每隔1s獲取一次ADC溫度值。

@Entry
@Component
struct Index {
@State channel: number = 1
@State adc_val: number = 0
@State temperature: number = 0
private timerId: number = -1

//獲取溫度傳感器ADC采樣值并計算溫度
private get_adc_value() {
let get_value = adc_hdf.get_adc_value(this.channel-1);
if (get_value <= 1500) {
this.adc_val = get_value;
this.temperature = (this.adc_val / 4096) * 1.8 * 100;
}
else {
this.temperature = 0
prompt.showToast({
message: "獲取失敗,請檢查連線", // 顯示文本
duration: 1000, // 顯示時長
})
}
}

//程序運行時開啟定時器Interval,每隔一秒調(diào)用get_adc_value更新溫度值
aboutToAppear(): void {
this.timerId = setInterval(() => {
this.get_adc_value()
}, 1000)
}
//銷毀定時器
aboutToDisappear() {
if (this.timerId > 0) {
clearTimeout(this.timerId)
this.timerId = -1
}
}

build() {
Row() {
show_temperature({temperature: $temperature})
Column({space:0}){
channel_chose({channel:$channel})
}.height('80%')
}.height('100%')
.backgroundImage($r('app.media.bg')).backgroundImageSize(ImageSize.Cover)
}
}

應(yīng)用簽名。

安裝應(yīng)用到開發(fā)板。

結(jié)果演示

https://ost.51cto.com/show/22186

文章相關(guān)附件可以點擊下面的原文鏈接前往下載:

https://ost.51cto.com/resource/2661

??想了解更多關(guān)于開源的內(nèi)容,請訪問:??

??51CTO 開源基礎(chǔ)軟件社區(qū)??

??https://ost.51cto.com??

責(zé)任編輯:jianghua 來源: 51CTO 開源基礎(chǔ)軟件社區(qū)
相關(guān)推薦

2023-03-20 16:21:26

ADC數(shù)字轉(zhuǎn)換器

2023-03-21 18:06:49

ADC數(shù)字轉(zhuǎn)換器

2022-09-13 16:10:15

鴻蒙操作系統(tǒng)

2023-09-14 15:49:42

PWM鴻蒙

2021-12-15 10:02:25

鴻蒙HarmonyOS應(yīng)用

2022-10-12 15:14:08

開機動畫鴻蒙

2023-09-06 15:27:22

ADC鴻蒙

2021-11-30 14:52:41

鴻蒙HarmonyOS應(yīng)用

2022-04-02 20:45:04

Hi3516開發(fā)板操作系統(tǒng)鴻蒙

2022-12-28 09:30:07

鴻聯(lián)系統(tǒng)開發(fā)

2022-08-08 19:35:37

HDF驅(qū)動開發(fā)鴻蒙

2022-09-15 14:56:12

GDB調(diào)試鴻蒙

2023-09-13 15:33:57

I2C鴻蒙

2021-09-16 15:04:28

鴻蒙HarmonyOS應(yīng)用

2021-11-08 07:19:45

鴻蒙HarmonyOS應(yīng)用

2021-01-21 13:27:37

鴻蒙HarmonyOS應(yīng)用開發(fā)

2022-09-16 15:01:37

操作系統(tǒng)技術(shù)鴻蒙

2022-09-07 15:08:58

操作系統(tǒng)鴻蒙

2022-09-06 15:46:52

speexdsp鴻蒙

2022-06-10 14:37:24

鴻蒙操作系統(tǒng)
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 成人日韩精品 | 作爱视频免费观看 | 99精品欧美一区二区蜜桃免费 | 国产精品一区二区在线播放 | av在线免费网 | 51ⅴ精品国产91久久久久久 | 欧美日韩在线免费观看 | 欧美日韩成人 | 精品欧美色视频网站在线观看 | 亚洲午夜小视频 | 欧美黄色片| 日韩在线观看中文字幕 | av国产在线观看 | 日韩中文久久 | 中文字幕影院 | 免费一级淫片aaa片毛片a级 | 免费国产视频 | 日韩视频精品在线 | 欧美日韩福利视频 | 九九精品在线 | 久久亚洲一区二区三区四区 | 欧美黄在线观看 | 久久久久久成人网 | 成人免费共享视频 | 在线播放国产一区二区三区 | 日韩中文字幕视频 | 午夜在线影院 | 国产98色在线 | 日韩 | 在线中文字幕视频 | 国产精品久久久久久久久久久久冷 | 国产一级片免费在线观看 | 国产成人精品网站 | 亚洲精品一区二区 | aaaaaa大片免费看最大的 | 国产精品国产成人国产三级 | 91pao对白在线播放 | 国产视频1区 | 欧美精品99| 日韩伦理电影免费在线观看 | 免费精品久久久久久中文字幕 | 日韩免费视频 |