【环境专家之智能手表】Part15:加入环境光,所有属性都全了!
<p><strong><span style="font-size:20px;">1.介绍</span></strong></p><p><span style="font-size:16px;">之前已经有了活动状态、信号强度、温度、湿度和气压,唯独缺少了一个光照参数,前几天看到【justd0】大佬已经移植好了,那么就拿过来用就好啦,非常感觉前浪的支持!今天这个闲暇时间,我就完善一下我的手表属性吧~</span></p>
<p><strong><span style="font-size:20px;">2.移植</span></strong></p>
<p><span style="font-size:16px;">我采用的是【sense_product_test】工程进行开发的,所以移植也是非常容易的,首先拿到下图1四个文件,拷贝到自己的工程中。</span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-align: center;"><span style="font-size:16px;">图1</span></p>
<p><span style="font-size:16px;">然后修改【NOA1305】的接口为【LV0140CS】就可以了,首先添加头文件:</span></p>
<pre>
<code class="language-cpp">#include <lv0104cs.h>
#include <lv0104cs_lux.h></code></pre>
<p><span style="font-size:16px;">然后将环境光状态变量修改名称:</span></p>
<pre>
<code class="language-cpp">int32_t lv0104cs_status = -1; //int32_t noa1305_status = -1;</code></pre>
<p><span style="font-size:16px;">然后将初始化部分的函数接口修改一下:</span></p>
<pre>
<code class="language-cpp">/** Initialize LV0104CS. */
retval = LV0104CS_LUX_Initialize();
if (retval == LV0104CS_OK)
{
retval = LV0104CS_LUX_StartContinuous(0, NULL);
if (retval == LV0104CS_OK)
{
lv0104cs_status = 0;
}
else
{
lv0104cs_status = 2;
}
}
else
{
lv0104cs_status = 1;
}</code></pre>
<p><span style="font-size:16px;">最后在循环中获取数据即可,获取数据的接口为【int32_t LV0104CS_LUX_ReadLux(uint32_t *lux)】,这里我获取到光照值之后,需要进行一定的缩小,因为我给光照值只保留了1个字节,使用手电筒给【LV0140CS】强光,得到的数值最高约15000+,猜测最大值应该是16383,所以我在获取到数值后,将数值缩小60倍,光照值得大部分范围就都能显示,防止溢出则将大于15300的值直接取255赋给环境光变量,代码如下:</span></p>
<pre>
<code class="language-cpp">if (lv0104cs_status == 0)
{
LV0104CS_LUX_ReadLux(&lux);
if(lux < 15300)
Broadcaster_Data = lux / 60;
else
Broadcaster_Data = 255;
}</code></pre>
<p><span style="font-size:16px;">最后在矿井外设备查看一下环境光的变化情况吧。</span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-align: center;"><span style="font-size:16px;">图2</span></p>
<p><strong><span style="font-size:20px;">3.总结</span></strong></p>
<p><span style="font-size:16px;">这个移植文件是直接修改【NOA3105】的驱动程序的,所以兼容性非常好,感谢大佬栽树,也让我乘了一波凉,不过也学习到了!</span></p>
<p>棒,踩在巨人的肩膀上 啊哈哈</p>
页:
[1]