/*********************************************************************************
|
* Copyright: (C) 2019 LingYun IoT System Studio
|
* All rights reserved.
|
*
|
* Filename: hal.c
|
* Description: This file is RPi HAL(Hardware Abstract Layer) initial functions
|
*
|
* Version: 1.0.0(2019年06月24日)
|
* Author: Guo Wenxue <guowenxue@gmail.com>
|
* ChangeLog: 1, Release initial version on "2019年06月24日 23时46分47秒"
|
*
|
********************************************************************************/
|
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <unistd.h>
|
#include <fcntl.h>
|
#include <dirent.h>
|
#include <string.h>
|
#include <time.h>
|
#include <errno.h>
|
|
#include "logger.h"
|
#include "hal.h"
|
|
int hal_init(hal_ctx_t *ctx)
|
{
|
if(!ctx)
|
{
|
log_error("Invalid input arguments\n");
|
return -1;
|
}
|
|
if( ctx->sht2x_enable )
|
{
|
if( sht2x_init()< 0 )
|
{
|
log_error("R&H sensor SHT2X initialise failure\n");
|
return -2;
|
}
|
else
|
{
|
log_info("R&H sensor SHT2X initialise okay\n");
|
}
|
}
|
|
if( ctx->lux_enable )
|
{
|
if( tsl2561_init() < 0 )
|
{
|
log_error("LUX sensor TSL2561 initialise failure\n");
|
return -2;
|
}
|
else
|
{
|
log_info("LUX sensor TSL2561 initialise okay\n");
|
}
|
}
|
|
gpio_init(&ctx->gpio);
|
|
return 0;
|
}
|
|
|
void hal_term(hal_ctx_t *ctx)
|
{
|
if(!ctx)
|
{
|
log_error("Invalid input arguments\n");
|
return ;
|
}
|
|
|
if( ctx->sht2x_enable )
|
{
|
sht2x_term();
|
}
|
|
if( ctx->lux_enable )
|
{
|
tsl2561_term();
|
}
|
|
gpio_term();
|
|
return ;
|
}
|