zoukankan      html  css  js  c++  java
  • 使用C++ Builder XE5获取Sensor值之Light Sensor

    献上代码C++代码,仅供參考。

    若使用Delphi。请參考文献,http://blogs.embarcadero.com/davidi/2013/12/02/43032/

    一定记得要安装FireMonkey哦。否则没有Fmx的库文件在里面。


    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    TSensorArray   sa;
    TCustomLightSensor *myLightSensor;
    
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
    	: TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
    
    	TSensorManager::Current->Activate();
    	int count;
    	int i;
    
    	count = TSensorManager::Current->Count;
    	Memo1->Clear();
    	for (i=0; i <count; i++) {
    		Memo1->Lines->Add(TSensorManager::Current->Sensors[i]->Name);
    	}
    
    	sa  = TSensorManager::Current->GetSensorsByCategory(TSensorCategory::Light);
    	if (sa.Length!=0) {
    		myLightSensor = static_cast<TCustomLightSensor*>(sa[0]);
    		Label1->Caption = FloatToStr(myLightSensor->Lux);
    	}
    //    Label1->Caption = ls->Lux;
    
    
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Timer1Timer(TObject *Sender)
    {
    	if (sa.Length !=0){
    		Label1->Caption = FloatToStr(myLightSensor->Lux);
    	}
    }
    //---------------------------------------------------------------------------
    

    头文件

    //---------------------------------------------------------------------------
    
    #ifndef Unit1H
    #define Unit1H
    //---------------------------------------------------------------------------
    #include <System.Classes.hpp>
    #include <Vcl.Controls.hpp>
    #include <Vcl.StdCtrls.hpp>
    #include <Vcl.Forms.hpp>
    #include <Vcl.ExtCtrls.hpp>
    #include <Fmx.Sensors.hpp>
    
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published:	// IDE-managed Components
    	TMemo *Memo1;
    	TLabel *Label1;
    	Vcl::Extctrls::TTimer *Timer1;
    	void __fastcall FormCreate(TObject *Sender);
    	void __fastcall Timer1Timer(TObject *Sender);
    private:	// User declarations
    public:		// User declarations
    	__fastcall TForm1(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif


  • 相关阅读:
    笔记:Oracle查询重复数据并删除,只保留一条记录
    64位系统安装ODBC驱动的方法
    批量Excel数据导入Oracle数据库
    Oracle自我补充之Decode()函数使用介绍
    解决nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed错误
    Linux命令区
    Linux下安装PHP+Nginx+Msql
    Thinkphp时间转换与统计的问题
    phpStydy配置memcache扩展
    Thinkphp+Nginx(PHPstudy)下报的404错误,403错误解决
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/7358195.html
Copyright © 2011-2022 走看看