#include <stdio.h>
#include <pthread.h>
#include “HW_INPUT.h”
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h> //define O_WRONLY and O_RDONLY
//#include “…/DRIVER/GPIO/driver_gpio.h”
#include “/home/zlgmcu/vscode/EMS_SNV/source/DRIVER/GPIO/GPIO.h”
/*
*************************** Product Code Begin ************************************
*/
#define GPIO_134_LDI1 134
#define GPIO_135_LDI2 135
#define GPIO_136_LDI3 136
#define GPIO_137_LDI4 137
#define GPIO_488_HDI1 488
#define GPIO_489_HDI2 489
#define GPIO_490_HDI3 490
#define GPIO_491_HDI4 491
#define ADC1 1
#define ADC2 2
#define ADC3 3
#define ADC4 4
static int ret;
char direction[4];
int Ldi[4];
int Hdi[4];
double AdcValue[4];
int HW_INPUT_GetLdiValue(int channel)
{
if((channel>0)&&(channel<=4))
{
return Ldi[channel-1];
}
else
{
return -1;
/* code */
}
}
void SetLdiValue(int channel,int value)
{
if((channel>0)&&(channel<=4))
{
Ldi[channel-1]=value;
}
}
//
int HW_INPUT_GetHdiValue(int channel)
{
if((channel>0)&&(channel<=4))
{
return Hdi[channel-1];
}
else
{
return -1;
/* code */
}
}
void SetHdiValue(int channel,int value)
{
if((channel>0)&&(channel<=4))
{
Hdi[channel-1]=value;
}
}
//
void SetAdcValue(int channel,double value)
{
if((channel>0)&&(channel<=4))
{
AdcValue[channel-1]=value;
}
}
//
double HW_INPUT_GetAdcValue(int channel)
{
if((channel>0)&&(channel<=4))
{
return AdcValue[channel-1];
}
else
{
return -1;
/* code */
}
}
void HW_INPUT_Init()
{
//LDI
sysfs_gpio_export(GPIO_134_LDI1);//export gpio key1
sysfs_gpio_export(GPIO_135_LDI2);//export gpio key2
sysfs_gpio_export(GPIO_136_LDI3);//export gpio key2
sysfs_gpio_export(GPIO_137_LDI4);//export gpio key2
sysfs_gpio_set_dir(GPIO_134_LDI1, 0);//set as input
sysfs_gpio_set_dir(GPIO_135_LDI2, 0);//set as input
sysfs_gpio_set_dir(GPIO_136_LDI3, 0);//set as input
sysfs_gpio_set_dir(GPIO_137_LDI4, 0);//set as input
//HDI
sysfs_gpio_export(GPIO_488_HDI1);//export gpio key1
sysfs_gpio_export(GPIO_489_HDI2);//export gpio key2
sysfs_gpio_export(GPIO_490_HDI3);//export gpio key2
sysfs_gpio_export(GPIO_491_HDI4);//export gpio key2
sysfs_gpio_set_dir(GPIO_488_HDI1, 0);//set as input
sysfs_gpio_set_dir(GPIO_489_HDI2, 0);//set as input
sysfs_gpio_set_dir(GPIO_490_HDI3, 0);//set as input
sysfs_gpio_set_dir(GPIO_491_HDI4, 0);//set as input
}
void *HW_INPUT_ThreadFunction(void arg)
{
char buf[10];
unsigned int value1;
double value2;
while (1)
{
/ code */
usleep(50000);//50 ms
sysfs_gpio_get_value(GPIO_134_LDI1, &value1);
SetLdiValue(GPIO_134_LDI1,value1);
sysfs_gpio_get_value(GPIO_135_LDI2, &value1);
SetLdiValue(GPIO_135_LDI2,value1);
sysfs_gpio_get_value(GPIO_136_LDI3, &value1);
SetLdiValue(GPIO_136_LDI3,value1);
sysfs_gpio_get_value(GPIO_137_LDI4, &value1);
SetLdiValue(GPIO_137_LDI4,value1);
//HDI
sysfs_gpio_get_value(GPIO_488_HDI1, &value1);
SetHdiValue(GPIO_488_HDI1,value1);
sysfs_gpio_get_value(GPIO_489_HDI2, &value1);
SetHdiValue(GPIO_489_HDI2,value1);
sysfs_gpio_get_value(GPIO_490_HDI3, &value1);
SetHdiValue(GPIO_490_HDI3,value1);
sysfs_gpio_get_value(GPIO_491_HDI4, &value1);
SetHdiValue(GPIO_491_HDI4,value1);
//ADC
sysfs_adc_get_value(ADC1, &value2);
SetAdcValue(ADC1,value2);
sysfs_adc_get_value(ADC2, &value2);
SetAdcValue(ADC2,value2);
sysfs_adc_get_value(ADC3, &value2);
SetAdcValue(ADC3,value2);
sysfs_adc_get_value(ADC4, &value2);
SetAdcValue(ADC4,value2);
}
}
void HW_INPUT_CreateThread()
{
pthread_t threadID;
pthread_create(&threadID,NULL,HW_INPUT_ThreadFunction,NULL);
}