📄 51.c
字号:
#include <ansi_c.h>
#include <formatio.h>
#include <cvirte.h>
#include <userint.h>
#include "51.h"
static int panelHandle;
static int childpanelhandle;
//自定义函数
void chushi(void);
int fangshi0(float jingzhen, float shijian);
int fangshi1(float jingzhen, float shijian);
int fangshi2(float jingzhen, float shijian);
int fangshi3(float jingzhen, float shijian);
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "51.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
//自定义函数
chushi();
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK Quit (int panel, int event, void *callbackData,
int eventData1, int eventData2)
{
switch (event)
{
case EVENT_GOT_FOCUS:
break;
case EVENT_LOST_FOCUS:
break;
case EVENT_CLOSE:
QuitUserInterface (0);
break;
}
return 0;
}
int CVICALLBACK OK (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int value;
char jingzhen[10];
char shijian[10];
double intjingzhen;
double intshijian;
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (panelHandle, PANEL_RING, &value);
GetCtrlVal (panelHandle, PANEL_STRING, jingzhen);
GetCtrlVal (panelHandle, PANEL_STRING_2, shijian);
Fmt (&intjingzhen, "%f<%s", jingzhen);
Fmt (&intshijian, "%f<%s", shijian);
switch(value)
{
case 0:
fangshi0(intjingzhen, intshijian);
break;
case 1:
fangshi1(intjingzhen, intshijian);
break;
case 2:
fangshi2(intjingzhen, intshijian);
break;
case 3:
fangshi3(intjingzhen, intshijian);
break;
}
break;
}
return 0;
}
//自定义函数
void chushi()
{
SetActiveCtrl (panelHandle, PANEL_STRING);
}
int fangshi0(float jingzhen, float shijian)
{
int i;
double miao = shijian * 1000;
double zhouqi = 12/jingzhen;
double chuzhi;
int xchuzhi;
long int zhishu = 1;
char schuzhi[20];
double maxtime;
for(i=0; i<13; i++)
{
zhishu = zhishu *2;
}
//计算最大定时时间
maxtime = (zhouqi * zhishu)/1000.0;
chuzhi = zhishu - (miao/zhouqi);
//判断是否超过最大定时时间
if(chuzhi <=0)
{
childpanelhandle = LoadPanel (0, "51.uir", PANEL_2);
InstallPopup (childpanelhandle);
SetCtrlVal (childpanelhandle, PANEL_2_NUMERIC, maxtime);
SetCtrlVal (panelHandle, PANEL_STRING, "");
SetCtrlVal (panelHandle, PANEL_STRING_2, "");
SetCtrlVal (panelHandle, PANEL_STRING_3, "");
return -1;
}
//进行十进制转十六进制
//十六进制转成字符串
Fmt(&xchuzhi,"%i<%f", chuzhi);
Fmt(&xchuzhi,"%x<%i", xchuzhi);
Fmt(schuzhi, "%s<%x", xchuzhi);
strcat(schuzhi,"H");
SetCtrlVal (panelHandle, PANEL_STRING_3, schuzhi);
return 0;
}
int fangshi1(float jingzhen, float shijian)
{
int i;
double miao = shijian * 1000;
double zhouqi = 12/jingzhen;
double chuzhi;
int xchuzhi;
long int zhishu = 1;
char schuzhi[20];
double maxtime;
for(i=0; i<16; i++)
{
zhishu = zhishu *2;
}
//计算最大定时时间
maxtime = (zhouqi * zhishu)/1000.0;
chuzhi = zhishu - (miao/zhouqi);
//判断是否超过最大定时时间
if(chuzhi <=0)
{
childpanelhandle = LoadPanel (0, "51.uir", PANEL_2);
InstallPopup (childpanelhandle);
SetCtrlVal (childpanelhandle, PANEL_2_NUMERIC, maxtime);
SetCtrlVal (panelHandle, PANEL_STRING, "");
SetCtrlVal (panelHandle, PANEL_STRING_2, "");
SetCtrlVal (panelHandle, PANEL_STRING_3, "");
return -1;
}
Fmt(&xchuzhi,"%i<%f", chuzhi);
Fmt(&xchuzhi,"%x<%i", xchuzhi);
Fmt(schuzhi, "%s<%x", xchuzhi);
strcat(schuzhi,"H");
SetCtrlVal (panelHandle, PANEL_STRING_3, schuzhi);
return 0;
}
int fangshi2(float jingzhen, float shijian)
{
int i;
double miao = shijian * 1000;
double zhouqi = 12.0/jingzhen;
double chuzhi;
int xchuzhi;
long int zhishu = 1;
char schuzhi[20];
double maxtime;
for(i=0; i<8; i++)
{
zhishu = zhishu *2;
}
//计算最大定时时间
maxtime = (zhouqi * zhishu)/1000.0;
chuzhi = zhishu - (miao/zhouqi);
//判断是否超过最大定时时间
if(chuzhi <=0)
{
childpanelhandle = LoadPanel (0, "51.uir", PANEL_2);
InstallPopup (childpanelhandle);
SetCtrlVal (childpanelhandle, PANEL_2_NUMERIC, maxtime);
SetCtrlVal (panelHandle, PANEL_STRING, "");
SetCtrlVal (panelHandle, PANEL_STRING_2, "");
SetCtrlVal (panelHandle, PANEL_STRING_3, "");
return -1;
}
Fmt(&xchuzhi,"%i<%f", chuzhi);
Fmt(&xchuzhi,"%x<%i", xchuzhi);
Fmt(schuzhi, "%s<%x", xchuzhi);
strcat(schuzhi,"H");
SetCtrlVal (panelHandle, PANEL_STRING_3, schuzhi);
return 0;
}
int fangshi3(float jingzhen, float shijian)
{
int i;
double miao = shijian * 1000;
double zhouqi = 12/jingzhen;
double chuzhi;
int xchuzhi;
long int zhishu = 1;
char schuzhi[20];
double maxtime;
for(i=0; i<8; i++)
{
zhishu = zhishu *2;
}
//计算最大定时时间
maxtime = (zhouqi * zhishu)/1000.0;
chuzhi = zhishu - (miao/zhouqi);
//判断是否超过最大定时时间
if(chuzhi <=0)
{
childpanelhandle = LoadPanel (0, "51.uir", PANEL_2);
InstallPopup (childpanelhandle);
SetCtrlVal (childpanelhandle, PANEL_2_NUMERIC, maxtime);
SetCtrlVal (panelHandle, PANEL_STRING, "");
SetCtrlVal (panelHandle, PANEL_STRING_2, "");
SetCtrlVal (panelHandle, PANEL_STRING_3, "");
return -1;
}
Fmt(&xchuzhi,"%i<%f", chuzhi);
Fmt(&xchuzhi,"%x<%i", xchuzhi);
Fmt(schuzhi, "%s<%x", xchuzhi);
strcat(schuzhi,"H");
SetCtrlVal (panelHandle, PANEL_STRING_3, schuzhi);
return 0;
}
int CVICALLBACK OKK (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
RemovePopup (0);
break;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -