首页 > 其他 > 详细

8040 迪文程序

时间:2017-10-17 23:56:44      阅读:381      评论:0      收藏:0      [点我收藏+]
 1  switch(menucount)
 2             {
 3                  case 0xFFFF:
 4                  default: break;
 5                  case 0xEEEE:
 6                  {
 7                                  switch(TouchKey)
 8                                          {                                        
 9                                                  case 0x03F1:                      //输入准值
10                                                  {
11                                                             float TMP       =   1;
12                                                             u8    backValue;
13                                                             backValue = Edit_Float(&TMP, "%06.1f", "工况>工况设置>环温", "如用户需要自行设置当前环境温度值,可以通过修改此值并选中生效!");
14                                                             switch(backValue)
15                                                                              {
16                                                                                  case EDIT_SUCCESS:                       //如果成功编辑
17                                                                                             {
18                                                                                                 if(TMP<=0)      TMP    = 1;
19                                                                                                 if(TMP>=9999)   TMP    = 9999;
20 
21                                                 if(Instru_Data.Flow_B>0.5)
22                                                                                                 {
23                                                                                                     SwitchPage(62); 
24                                                                                                     CORRECT.Rate_B[correctNumTem]  =  TMP/Instru_Data.Flow_B;                                                                                                     
25                                                                                                  }
26                                                 else
27                                                                                                 {
28                                                                                                     SwitchPage(62);
29                                                                                                     DisplayString(0x0294,"流量应大于0!");
30                                                                                                     delay_ms(1000);    
31                                                                                                     DisplayString(0x0294,"           ");
32                                                                                                  }                                                                                                                                                                                                                                                                                                
33                                                                                                 DisplayDoubleWord(0x0290,TMP*10); 
34                                                                                                 DisplayDoubleWord(0x0292,CORRECT.Rate_B[correctNumTem]*10000);
35                                                                                                 updatacount =50;                                                                                          
36                                                                                              }
37                                                                                  break;
38                                                                                  case EDIT_ERROR:
39                                                                                  case EDIT_QUIT:
40                                                                                  default:
41                                                                                             {
42                                                                                                 SwitchPage(62);
43                                                                                                 updatacount =50;                                                                                                        
44                                                                                             }
45                                                                                  break;                                                                                                       
46                                                                              }                                                         
47                                                     }
48                                                  break;    
49                          case 0x03F2:           //修改系数
50                                                  {
51                                                             float TMP       =   CORRECT.Rate_B[correctNumTem];
52                                                             u8    backValue;
53                                                             backValue = Edit_Float(&TMP, "%06.4f", "工况>工况设置>环温", "如用户需要自行设置当前环境温度值,可以通过修改此值并选中生效!");
54                                                             switch(backValue)
55                                                                              {
56                                                                                  case EDIT_SUCCESS:                       //如果成功编辑
57                                                                                             {
58                                                                                                 if(TMP<=0)      TMP    = 1;
59                                                                                                 if(TMP>=9)      TMP    = 9;
60 
61                                                                                                 CORRECT.Rate_B[correctNumTem] = TMP;                                                                                                                                                                                        
62                                                                                                 SwitchPage(62);
63                                                                                                 DisplayDoubleWord(0x0292,CORRECT.Rate_B[correctNumTem]*10000);                                                                                                                                                 
64                                                                                                 updatacount =50;                                                                                          
65                                                                                              }
66                                                                                  break;
67                                                                                  case EDIT_ERROR:
68                                                                                  case EDIT_QUIT:
69                                                                                  default:
70                                                                                             {
71                                                                                                 SwitchPage(62);
72                                                                                                 updatacount =50;                                                                                                        
73                                                                                             }
74                                                                                  break;                                                                                                       
75                                                                              }                                                                                                           
76                                                   }
77                          break;                                                     
78                                                  case 0x03F3:                      //保存系数并返回
79                                                  {
80                             ftosave(adrCORRECT+correctNumTem*4,CORRECT.Rate_B[correctNumTem]); 
81                                                   }
82                                                  return  groupNumTem;        
83                                                  case 0x03F4:          //不保存系数返回
84                                                       CORRECT.Rate_B[correctNumTem] = correctRatebuf;
85                                                  return  groupNumTem;    
86                                             }
87                     }
88                  break;                                        
89             }     
90 
91 
92     oneSecondCount++;
93         updatacount++;    
94         delay_ms(20);     
95       }            
96  }

 

 

借用8040里的  edit函数   目前这个editfloat函数  我估计他是   用来将键盘值输出的

 

8040里的sprintf函数很好  可以借用

 

  1 uint8_t DWIN_sprintf(
  2     uint16_t Address,
  3     const char* fmt,    /* Pointer to the format string */
  4     ...                    /* Optional arguments... */
  5 )
  6 {
  7     static char StringCache[256];
  8     uint16_t retry;
  9     va_list arp;
 10     uint8_t flag, width, fractionWidth, r;
 11     uint8_t c, d, *p, s[16];
 12     uint8_t CacheIndex, fmtIndex;
 13     uint16_t i, j;
 14     int32_t varible;
 15     double Fvarible;
 16 
 17 //    for(retry=0; retry<250; retry++){
 18 //        if(Printer_Lock == SET){
 19 //            OSTimeDly(OS_TICKS_PER_SEC/100);
 20 //        }
 21 //        else{
 22 //            break;
 23 //        }
 24 //    }
 25     if(retry == 250){
 26         return ERROR;
 27     }
 28     
 29     va_start(arp, fmt);
 30 
 31     for (fmtIndex=0,CacheIndex=0; ;fmtIndex++){
 32         c = fmt[fmtIndex];
 33         if (c == 0){                            /* End of string */
 34             StringCache[CacheIndex++] = 0;
 35             break;
 36         }
 37         if (c != %){                            /* Non escape character */
 38             StringCache[CacheIndex++] = c;
 39             continue;
 40         }
 41         width = fractionWidth = flag = 0;
 42         c = fmt[++fmtIndex];
 43         if (c == 0) {                            /* Flag: ‘0‘ padding */
 44             flag |= 0x01;
 45             c = fmt[++fmtIndex];
 46         }
 47         if (c == -) {                            /* Flag: left justified */
 48             flag |= 0x02;
 49             c = fmt[++fmtIndex];
 50         }
 51         if (c == +) {                            /* Flag: left justified */
 52             flag |= 0x04;
 53             c = fmt[++fmtIndex];
 54         }
 55         while (IsDigit(c)) {                    /* Precision */
 56             width = width * 10 + c - 0;
 57             c = fmt[++fmtIndex];
 58         }
 59         if(c == .){
 60             c = fmt[++fmtIndex];
 61             while (IsDigit(c)) {                /* fraction Width */
 62                 fractionWidth = fractionWidth * 10 + c - 0;
 63                 c = fmt[++fmtIndex];
 64             }
 65         }
 66         if (c == l || c == L){                /* Prefix: Size is long int */
 67             flag |= 4;
 68             c = fmt[++fmtIndex];
 69         }
 70         if (IsLower(c)){
 71             d = c - 0x20;
 72         }
 73         else{
 74             d = c;
 75         }
 76         switch (d) {                            /* Type is... */
 77         case S :                                /* String */
 78             p = (uint8_t *)va_arg(arp, char*);
 79             for(i = 0; p[i]; i++);                /* Find the end of the string */
 80             if (!(flag & 2)) {                    /* Right justified */
 81                 while (i++ < width)
 82                 {
 83                     StringCache[CacheIndex++] =  ;
 84                 }
 85             }
 86             while (*p){
 87                 StringCache[CacheIndex++] = *p++;    /* Copy the string to cache */
 88             }
 89             while (i++ < width){
 90                 StringCache[CacheIndex++] =  ;
 91             }
 92             continue;
 93         case C :                                /* Character */
 94             StringCache[CacheIndex++] = (char)va_arg(arp, int);
 95             continue;
 96         case B :                                /* Binary */
 97             r = 2;
 98             break;
 99         case O :                                /* Octal */
100             r = 8;
101             break;
102         case D :                                /* Signed decimal */
103         case U :                                /* Unsigned decimal */
104             r = 10;
105             break;
106         case X :                                /* Hexdecimal */
107             r = 16;
108             break;
109         case F :                                /* Float */
110             r = 10;
111             if(fractionWidth > 6){
112                 fractionWidth = 6;
113             }
114             if(width<fractionWidth){
115                 width = fractionWidth + 2;
116             }
117             break;
118         default:                                /* Unknown type (pass-through) */
119             StringCache[CacheIndex++] = c;
120             continue;
121         }
122 
123         /* Get an argument and put it in numeral */
124         if(d != F){
125             /* Prefix: Size is long int */
126             varible = (flag & 4) ? 
127                         (long)va_arg(arp, long) : 
128                         ((c == D) ? (long)va_arg(arp, int) : (long)va_arg(arp, unsigned int));
129             if (d == D && (varible & 0x80000000)) {
130                 varible = 0 - varible;
131                 flag |= 8;
132             }
133             
134             j = 0;
135             do {
136                 d = (char)(varible % r);
137                 varible /= r;
138                 if (d > 9){
139                     d += (c == x) ? 0x27 : 0x07;
140                 }
141                 s[j++] = d + 0;
142             } while (varible && j<sizeof(s)/sizeof(s[0]));
143             if (flag & 8){
144                 s[j++] = -;
145             }
146             d = (flag & 1) ? 0 :  ;
147             for(i=j; !(flag & 2) && i++<width; ){
148                 StringCache[CacheIndex++] = d;
149             }
150             do{
151                 StringCache[CacheIndex++] = s[--j];
152             } while (j);
153             while (i++ < width){
154                 StringCache[CacheIndex++] = d;
155             }
156         }
157         else{
158             Fvarible = va_arg(arp, double);
159             if (Fvarible<0) {
160                 Fvarible = -Fvarible;
161                 flag |= 8;
162             }
163             for(i=0; i<fractionWidth; i++){
164                 Fvarible *= 10.0;
165             }
166             if(Fvarible-(int)Fvarible >= 0.5){
167                 Fvarible += 1;
168             }
169             varible = (uint32_t)Fvarible;
170             for(j=0; j<fractionWidth && j<sizeof(s)/sizeof(s[0]);){
171                 s[j++] = (char)(varible % r) + 0; 
172                 varible /= r;
173             }
174             if(fractionWidth>0){
175                 s[j++] = .;
176             }
177             for( ;j<sizeof(s)/sizeof(s[0]) ;){
178                 s[j++] = (char)(varible % r) + 0; 
179                 varible /= r;
180                 if(varible == 0){
181                     break;
182                 }
183             }
184             if (flag & 8){
185                 s[j++] = -;
186             }
187             /* filled the rest with ‘0‘ or ‘ ‘ */
188             d = (flag & 1) ? 0 :  ;
189             // must be the situation of right align
190             for(i=j; !(flag & 2) && i++<width; ){
191                 StringCache[CacheIndex++] = d;
192             }
193             do{
194                 StringCache[CacheIndex++] = s[--j];
195             } while (j);
196             while (i++ < width){
197                 StringCache[CacheIndex++] = d;
198             }
199         }
200     }
201     va_end(arp);
202     
203     //DWIN_Write_Txt(Address, StringCache);
204     DisplayString(Address, StringCache);    
205     return SUCCESS;
206 }

 

8040 迪文程序

原文:http://www.cnblogs.com/qdrs/p/7684409.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!