📄 dlg_ad.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/ioctl.h>
#include <pthread.h>
#include <fcntl.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#define IDC_AD_WINFO 101
#define IDC_AD_WATER 102
#define IDC_AD_AINFO 103
#define IDC_AD_AIR 104
#define IDC_AD_SINFO 105
#define IDC_AD_SOIL 106
#define IDC_AD_CANCEL 107
static HWND hwnd_ad; //AD转换窗口句柄
static BOOL STOP; //线程停止标志
static BOOL PAUSE; //线程暂停标志
#include "s3c2410-adc.h"
#define ADC_DEV "/dev/adc/0raw"
static int adc_fd = -1;
int init_ADdevice(void)
{
if((adc_fd=open(ADC_DEV, O_RDWR))<0){
printf("Error opening %s adc device\n", ADC_DEV);
return -1;
}
}
int GetADresult(int channel)
{
int PRESCALE=0XFF;
int data=ADC_WRITE(channel, PRESCALE);
write(adc_fd, &data, sizeof(data));
read(adc_fd, &data, sizeof(data));
return data;
}
static DLGTEMPLATE DlgAD =
{
WS_BORDER | WS_CAPTION,
WS_EX_NONE,
25, 45, 270, 150,
"数据采集",
0,
0,
7, NULL,
0
};
static CTRLDATA CtrlAD [] =
{
{
"static",
WS_VISIBLE | SS_SIMPLE,
10, 50, 30, 16,
IDC_AD_WINFO,
"水质:",
0
},
{
"static",
WS_VISIBLE | SS_SIMPLE,
40, 50, 50, 16,
IDC_AD_WATER,
"0.0",
0
},
{
"static",
WS_VISIBLE | SS_SIMPLE,
100, 50, 30, 16,
IDC_AD_AINFO,
"空气:",
0
},
{
"static",
WS_VISIBLE | SS_SIMPLE,
130, 50, 50, 16,
IDC_AD_AIR,
"0.0",
0
},
{
"static",
WS_VISIBLE | SS_SIMPLE,
190, 50, 30, 16,
IDC_AD_SINFO,
"土壤:",
0
},
{
"static",
WS_VISIBLE | SS_SIMPLE,
220, 50, 50, 16,
IDC_AD_SOIL,
"0.0",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
150, 80, 60, 25,
IDC_AD_CANCEL,
"取消",
0
}
};
static void* GetADData (void * arg)
{
int i;
float ad_data[3]={0.0, 0.0, 0.0};
char ptr[3][7];
usleep(1);
while(STOP == FALSE)
{
if(PAUSE == FALSE)
{
for (i=0;i<3;i++)
{
ad_data[i] = ((float)GetADresult(i)* 3.3) / 1024.0;
gcvt(ad_data[i], 5, ptr[i]);
ptr[i][6] = '\0';
}
/*将获得的通道数据显示到相应控件中*/
SetWindowText(GetDlgItem(hwnd_ad,IDC_AD_WATER),ptr[0]);
SetWindowText(GetDlgItem(hwnd_ad,IDC_AD_AIR),ptr[1]);
SetWindowText(GetDlgItem(hwnd_ad,IDC_AD_SOIL),ptr[2]);
sleep(1);
}
}
}
static int DlgADProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
char buf[7] = {'\0'};
time_t timep;
struct tm *gmt;
hwnd_ad = hDlg;
switch (message)
{
case MSG_COMMAND:
switch (wParam)
{
case IDC_AD_CANCEL:
PAUSE =TRUE;
STOP = TRUE;
EndDialog (hDlg, wParam);
break;
}
break;
case MSG_CLOSE:
STOP = TRUE;
EndDialog (hDlg,wParam);
break;
}
return DefaultDialogProc (hDlg, message, wParam, lParam);
}
int OpenAD (HWND hWnd)
{
pthread_t th_ad;
STOP = FALSE;
/*初始化A/D设备*/
init_ADdevice();
DlgAD.controls = CtrlAD;
//建立数据采集线程
pthread_create (&th_ad, NULL, GetADData, 0);
//建立AD对话框
DialogBoxIndirectParam (&DlgAD, hWnd, DlgADProc, 0L);
//关闭数据采集线程
pthread_join (th_ad, NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -