Difference between revisions of "Talk:LazDeviceAPIs"

From Free Pascal wiki
Jump to navigationJump to search
(Link added to LazDeviceAPIs in See Also section and this page excluded from category)
m (Fixed syntax highlighting)
 
Line 12: Line 12:
 
调用 Accelerometer.StopReadingAccelerometerData 函数,停止监听加速度传感器:
 
调用 Accelerometer.StopReadingAccelerometerData 函数,停止监听加速度传感器:
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
//使用加速度传感器的例子
 
//使用加速度传感器的例子
 
//在uses 内容中加入lazdeivicepis元文件
 
//在uses 内容中加入lazdeivicepis元文件

Latest revision as of 01:49, 19 February 2020

LazDeviceAPIs 是一个 LCL 单元文件提供一个软件接口用于连接多种硬件设备,包括(such as the accelerometer 加速度传感器, GPS positioning GPS定位设备, SMS sending 短信发送, etc 其它环境传感器. 这个API主要是为智能手机平台设计的, 这个API正在做移植到桌面系统的工作.

介绍

LazDeviceAPIs 和其它来自 LCL 硬件设备 APIs 建模是相似的。

历史

我们有两个硬件全局操作对象: 鼠标和屏幕, 定位设备 (鼠标也用于触摸屏的定位)和屏幕的显示. LazDeviceAPIs 内置的全局操作对象: 加速度传感器, 位置信息, 信息, etc其它环境传感器.

加速度传感器

加速度传感器很容易调用. 调用 Accelerometer.StartReadingAccelerometerData 函数,开始监听加速度传感器 调用 Accelerometer.StopReadingAccelerometerData 函数,停止监听加速度传感器:

//使用加速度传感器的例子
//在uses 内容中加入lazdeivicepis元文件
uses lazdeviceapis;

//startaccel开始加速度传感器监听
procedure TForm2.btnStartAccelClick(Sender: TObject);
begin
  Accelerometer.OnSensorChanged := @HandleAccelerometerChanged;
  Accelerometer.StartReadingAccelerometerData();
end;

//stopaccel结束加速度传感器监听
procedure TForm2.btnStopAccelClick(Sender: TObject);
begin
  Accelerometer.StopReadingAccelerometerData();
end;

procedure TForm2.HandleAccelerometerChanged(Sender: TObject);
begin
  labelSensorData.Caption := Format('X=%f Y=%f Z=%f', [Accelerometer.xaxis,
    Accelerometer.yaxis, Accelerometer.zaxis]);
  DebugLn(labelSensorData.Caption);
end;

安卓权限

This object requires no special permissions under Android. 这个对象体不需要特殊的安卓权限。

位置信息

安卓权限

Android 在安卓系统内使用定位信息,需要添加以下权限到 AndroidManifest.xml 文件的应用程序, 可以看到如下.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

短信

安卓权限

Android 在安卓系统内使用短信息功能,需要添加以下权限到 AndroidManifest.xml 文件的应用程序, 可以看到如下.
<uses-permission android:name="android.permission.SEND_SMS" />

Possible Windows implementation

Windows 7 或更高版本的 Windows 都一套传感器 API 用于采集传感器信息 (e.g. GPS); 请参阅 MSDN Windows 中的传感器和位置平台简介. 感兴趣的开发人员可以用这些 APIs 加强 LazDeviceAPIs 函数.

路线图

LazDeviceAPIs 目前仅仅在 LCL-CustomDrawn-Android 中实现

参阅