Parcourir la source

显示ok,刷新速度需优化

guohui il y a 1 an
Parent
commit
58e1d8e376

+ 1 - 1
f407/applications/cfg.h

@@ -52,7 +52,7 @@
     #define PROD_TYPE                           PDU_AC_I3O1_H
     
     #define USE_UI
-
+    #define ROTATE                             90
 
 #else
     #error define a PRJ_XXXX please!

+ 11 - 5
f407/applications/power.c

@@ -351,6 +351,8 @@ static int total_proc(power_handle_t *h)
             }
         }
     }
+    
+    h->ttl.type = h->prod->pwr_type;
     for(k=0; k<times; k++) {
         h->ttl.total[k].voltage = tmp[k].voltage;
         h->ttl.total[k].current = tmp[k].current;
@@ -361,9 +363,6 @@ static int total_proc(power_handle_t *h)
         h->ttl.total[k].active  = tmp[k].active;
         h->ttl.total[k].reactive = tmp[k].reactive;
     }
-    
-    h->ttl.type = h->prod->pwr_type;
-    memcpy(h->ttl.total, tmp, sizeof(tmp));
     lock_off(h->lck);
     
     return 0;
@@ -377,6 +376,7 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
     
     lock_on(h->lck);
     if(pbrd) {
+        time_t tm = mktime(localtime(NULL));
         switch(pbrd->type) {
             case AC_SINGLE_S_TYPE:
             case AC_SINGLE_B_TYPE:
@@ -389,6 +389,7 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
                     LOGE("read_reg failed, addr:%d reg:0x%04x/%d cnt:%d\n", pbrd->addr, offset, offset, pbrd->chs*12);
                     break;
                 }
+
                 
                 for (i=0; i<pbrd->chs; i++) {
                     int idx = i * 12;
@@ -411,6 +412,8 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
                     
                     val = (tmp[11 + idx] << 16) | tmp[10 + idx];
                     pwr->factor = val / 1000.0;
+                    
+                    pbrd->pch[i].time = tm;
                 }
 
                 offset = POWER_AC_STAT_INFO_L;
@@ -463,6 +466,7 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
 
                     pwr->freq = 0;
                     pwr->factor = 1;
+                    pbrd->pch[i].time = tm;
                 }
 
                 offset = POWER_DC_STAT_INFO;
@@ -548,6 +552,8 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
                     
                     value = (tmp[15+Index] << 16) + tmp[14+Index];
                     pwr->factor = value / 1023.0f;
+                    
+                    pbrd->pch[i].time = tm;
                 }
                 
                 //获取通道开关状态及零线状态 
@@ -1086,8 +1092,8 @@ int power_set_all_sw(uint8_t on)
     
     power_handle_t *h=&pwrHandle;
     
-    for(i=0; i<h->brd_max; i++) {
-        set_board_sw(h->pbrd[i], on);
+    for(i=1; i<=h->chs; i++) {
+        power_set_ch_sw(i, on);
     }
     
     return 0;

+ 4 - 0
f407/applications/rtconfig.h

@@ -256,5 +256,9 @@
 #define PKG_USING_MBEDTLS_V2281
 
 
+#define NTP_USING_AUTO_SYNC
+#define NETUTILS_NTP_HOSTNAME   "cn.ntp.org.cn"
+//#define NETUTILS_NTP_HOSTNAME2  ""
+//#define NETUTILS_NTP_HOSTNAME3  ""
 
 #endif

+ 26 - 3
f407/applications/ui/lcd.c

@@ -26,7 +26,7 @@ extern int st77xx_init(lcd_handle_t *h);
 extern int st77xx_deinit(lcd_handle_t *h);
 extern void st77xx_refresh(lcd_handle_t *hd, uint16_t x, uint16_t y, uint16_t w, uint16_t h, void *data, uint32_t len);
 extern void st77xx_rotate(lcd_handle_t *h, int rotate);
-
+extern void st77xx_draw_pixel(lcd_handle_t *hd, uint16_t x, uint16_t y, uint32_t color);
 
 static inline int set_point(lcd_handle_t *h, int x, int y, uint32_t data)
 {
@@ -75,8 +75,6 @@ void lcd_init(int width, int height, int rotate)
     h->rotate = rotate;
     
     st77xx_init(h);
-    
-    lcd_draw_string(0, 60, LCD_WIDTH, LCD_HEIGHT/10, "SmartPDU", FONT_12, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
 }
 
 void lcd_deinit(void)
@@ -280,6 +278,7 @@ int lcd_draw_char(lcd_handle_t *hd, int x, int y, int w, int h, uint8_t *c, int
         }
     }
 #else
+    #if 0
     set_color(hd, bgcolor, fdata.width*h);
     for(i=0; i<fdata.dlen; i++)  {
         tmp = fdata.data[i];
@@ -302,6 +301,30 @@ int lcd_draw_char(lcd_handle_t *hd, int x, int y, int w, int h, uint8_t *c, int
         }
     }
     st77xx_refresh(hd, x0, y0, fdata.width, h, hd->buf, fdata.width*h*2);
+    #else
+    for(i=0; i<fdata.dlen; i++)  {
+        tmp = fdata.data[i];
+        for(j=0; j<8; j++)  {
+            if((x<x2 && x<hd->width) && (y<y2 && y<hd->height)) 
+            {
+                if(tmp&0x01) {
+                    st77xx_draw_pixel(hd, x, y, color);
+                }
+                else {
+                    st77xx_draw_pixel(hd, x, y, bgcolor);
+                }
+            }
+            tmp >>= 1;
+            y++;
+
+            if((y-y1)>=fdata.height) {
+                y=y1; x++;
+                break;
+            }
+        }
+    }
+    #endif
+    
 #endif
 
     return fdata.width;

+ 1 - 1
f407/applications/ui/menu.c

@@ -661,7 +661,7 @@ int menu_handle(void)
     key_val_t kv;
     int rotate=lcd_get_rotate();
     int item_h=LCD_HEIGHT/4;
-    int font1=FONT_12,font2=FONT_12;
+    int font1=FONT_24,font2=FONT_24;
     menu_handle_t *h=&mnHandle;
     
     r = key_get(&kv); key_remap(&kv, rotate);

+ 26 - 17
f407/applications/ui/st77xx.c

@@ -3,9 +3,7 @@
 
 #define DIV_NUM                 10
 #define INVERSE                 1
-#define X_OFFSET                0//80
-#define Y_OFFSET                80
-
+#define ST_OFFSET               80
 
 #define ST77XX_CASET            0x2A
 #define ST77XX_RASET            0x2B
@@ -15,15 +13,14 @@
 #define ST77XX_MADCTL           0x36
 #define ST77XX_PIXEL_FORMAT     0x3A
 
-#define ST77XX_MADCTL_MY        0x80
-#define ST77XX_MADCTL_MX        0x40
 #define ST77XX_MADCTL_MV        0x20
+#define ST77XX_MADCTL_MX        0x40
+#define ST77XX_MADCTL_MY        0x80
+
+#define ST77XX_MADCTL_MH        0x04
 #define ST77XX_MADCTL_ML        0x10
 #define ST77XX_MADCTL_RGB       0x00
 #define ST77XX_MADCTL_BGR       0x08
-#define ST77XX_MADCTL_MH        0x04
-
-
 
 
 #define delay_ms(x)             rt_thread_mdelay(x)
@@ -68,19 +65,19 @@ void st77xx_rotate(lcd_handle_t *h, int rotate)
     switch (rotate)
     {
         case 0:
-        madctl = (0 << 3) | (0 << 5) | (0 << 6) | (0 << 7);
+        madctl = mode;
         break;
         
         case 90:
-        madctl = (0 << 3) | (1 << 5) | (1 << 6) | (0 << 7);
+        madctl = (ST77XX_MADCTL_MV | ST77XX_MADCTL_MX | mode);
         break;
         
         case 180:
-        madctl = (0 << 3) | (0 << 5) | (1 << 6) | (1 << 7);
+        madctl = (ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | mode);
         break;
         
         case 270:
-        madctl = (0 << 3) | (1 << 5) | (0 << 6) | (1 << 7);
+        madctl = (ST77XX_MADCTL_MV | ST77XX_MADCTL_MY | mode);
         break;
         
         default:
@@ -91,8 +88,15 @@ void st77xx_rotate(lcd_handle_t *h, int rotate)
 
 static void st77xx_set_win(lcd_handle_t *hd, int x, int y, int w, int h)
 {
-    int x1=X_OFFSET+x,y1=Y_OFFSET+y;
-     
+    int x1=x,y1=y;    
+    
+    if(hd->rotate==90) {
+        //y1 += ST_OFFSET;
+    }
+    else if(hd->rotate==270) {
+        x1 += ST_OFFSET;
+    }
+    
     write_cmd (hd,ST77XX_CASET);
     write_data(hd,x1>>8);
     write_data(hd,x1&0xff);
@@ -122,6 +126,13 @@ void st77xx_refresh(lcd_handle_t *hd, uint16_t x, uint16_t y, uint16_t w, uint16
 }
 
 
+void st77xx_draw_pixel(lcd_handle_t *hd, uint16_t x, uint16_t y, uint32_t color)
+{
+    st77xx_set_win(hd, x, y, x+1, y+1);
+    write_16bit(hd, color);
+}
+
+
 static void st77xx_reg_init(lcd_handle_t *h)
 {
     write_cmd (h,ST77XX_MADCTL);
@@ -206,10 +217,8 @@ static void st77xx_reg_init(lcd_handle_t *h)
 
 static void st77xx_reset(lcd_handle_t *h)
 {
-    gpio_set(RST_PIN, 1);       /* LCD Hardware Reset */
-    delay_ms(120);
     gpio_set(RST_PIN, 0);       /* LCD Hardware Reset */
-    delay_ms(120);
+    delay_ms(100);
     gpio_set(RST_PIN, 1);
     delay_ms(120);              /* Delay 120ms */
     write_cmd(h,0x11);          /* Sleep out */

+ 1 - 2
f407/applications/ui/ui.c

@@ -38,8 +38,7 @@ int ui_init(void)
 {
     ui_handle_t *h=&uiHandle;
 
-    //menu_init();
-#if 0//def USE_UI
+#ifdef USE_UI
     thread_start(THREAD_ID_UI, ui_thread, h);
 #endif
 

Fichier diff supprimé car celui-ci est trop grand
+ 287 - 293
f407/project/app/app.uvoptx


+ 81 - 0
f407/project/app/app.uvprojx

@@ -1506,6 +1506,87 @@
         </Group>
         <Group>
           <GroupName>packages/tftp</GroupName>
+          <GroupOption>
+            <CommonProperty>
+              <UseCPPCompiler>0</UseCPPCompiler>
+              <RVCTCodeConst>0</RVCTCodeConst>
+              <RVCTZI>0</RVCTZI>
+              <RVCTOtherData>0</RVCTOtherData>
+              <ModuleSelection>0</ModuleSelection>
+              <IncludeInBuild>0</IncludeInBuild>
+              <AlwaysBuild>2</AlwaysBuild>
+              <GenerateAssemblyFile>2</GenerateAssemblyFile>
+              <AssembleAssemblyFile>2</AssembleAssemblyFile>
+              <PublicsOnly>2</PublicsOnly>
+              <StopOnExitCode>11</StopOnExitCode>
+              <CustomArgument></CustomArgument>
+              <IncludeLibraryModules></IncludeLibraryModules>
+              <ComprImg>1</ComprImg>
+            </CommonProperty>
+            <GroupArmAds>
+              <Cads>
+                <interw>2</interw>
+                <Optim>0</Optim>
+                <oTime>2</oTime>
+                <SplitLS>2</SplitLS>
+                <OneElfS>2</OneElfS>
+                <Strict>2</Strict>
+                <EnumInt>2</EnumInt>
+                <PlainCh>2</PlainCh>
+                <Ropi>2</Ropi>
+                <Rwpi>2</Rwpi>
+                <wLevel>0</wLevel>
+                <uThumb>2</uThumb>
+                <uSurpInc>2</uSurpInc>
+                <uC99>2</uC99>
+                <uGnu>2</uGnu>
+                <useXO>2</useXO>
+                <v6Lang>0</v6Lang>
+                <v6LangP>0</v6LangP>
+                <vShortEn>2</vShortEn>
+                <vShortWch>2</vShortWch>
+                <v6Lto>2</v6Lto>
+                <v6WtE>2</v6WtE>
+                <v6Rtti>2</v6Rtti>
+                <VariousControls>
+                  <MiscControls></MiscControls>
+                  <Define></Define>
+                  <Undefine></Undefine>
+                  <IncludePath></IncludePath>
+                </VariousControls>
+              </Cads>
+              <Aads>
+                <interw>2</interw>
+                <Ropi>2</Ropi>
+                <Rwpi>2</Rwpi>
+                <thumb>2</thumb>
+                <SplitLS>2</SplitLS>
+                <SwStkChk>2</SwStkChk>
+                <NoWarn>2</NoWarn>
+                <uSurpInc>2</uSurpInc>
+                <useXO>2</useXO>
+                <ClangAsOpt>0</ClangAsOpt>
+                <VariousControls>
+                  <MiscControls></MiscControls>
+                  <Define></Define>
+                  <Undefine></Undefine>
+                  <IncludePath></IncludePath>
+                </VariousControls>
+              </Aads>
+            </GroupArmAds>
+          </GroupOption>
+          <Files>
+            <File>
+              <FileName>tftp_server.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\rt-thread\components\net\lwip\lwip-2.1.2\src\apps\tftp\tftp_server.c</FilePath>
+            </File>
+            <File>
+              <FileName>tftp_port.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\rt-thread\components\net\lwip\lwip-2.1.2\src\apps\tftp\tftp_port.c</FilePath>
+            </File>
+          </Files>
         </Group>
         <Group>
           <GroupName>packages/lfs</GroupName>

+ 9 - 1
f407/tools/web/JS/data.js

@@ -415,7 +415,11 @@ function bin_to_total(bin) {
     length += 4;
     
     tmp = new DataView(bin, length);
-    this.consump = tmp.getFloat32 (0,true);
+    this.factor = tmp.getFloat32(0,true);
+    length += 4;
+    
+    tmp = new DataView(bin, length);
+    this.consump = tmp.getFloat32(0,true);
     length += 4;
 
     tmp = new DataView(bin, length);
@@ -696,6 +700,10 @@ function total_to_bin(js) {
     tmp.setFloat32(0,js.freq,true);
     length += 4;
     
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.factor,true);
+    length += 4;
+    
     tmp = new DataView(buffer, length);
     tmp.setFloat32(0,js.consump,true);
     length += 4;

+ 14 - 15
f407/tools/web/JS/display_data.js

@@ -38,23 +38,17 @@ function Channel_Info(j_data,channel_power_infro)
     channel_display(j_data,channel_power_infro,channel_infro)
 }
 
-function threshold_mannage(orgin_data,channel_power_infro,threshold)
+function threshold_mannage(orgin_data,channel_power_infro)
 {
     // 获取要插入新行的DOM元素
     const dataList = document.getElementById('threshold_mannage');
 
     // 清空现有的列表项
     dataList.innerHTML = '';
-    channel_length = threshold.c_upper.act_para.length
-    current_upper =  threshold.c_upper.act_para
-    voltage_upper =  threshold.v_upper.act_para
-    voltage_lower =  threshold.v_lower.act_para
-    power_upper =  threshold.p_upper.act_para
-    consump_upper = threshold.w_upper.act_para
+    channel_length = channel_power_infro.length
     //遍历数据数组
-    for(let i = 0;i<=channel_length-1;i++)
+    for(let j = 1;j<channel_length;j++)
     {
-        j = i + 1
         // 创建一个新的列表项元素
         const listItem = document.createElement('tr');
         dataList.appendChild(listItem);
@@ -75,33 +69,38 @@ function threshold_mannage(orgin_data,channel_power_infro,threshold)
 
         //自动生成电流上限列
         const current_max_td = document.createElement('td');
-        current_max_td.textContent = current_upper[i] 
+        c_val = channel_power_infro[j].thr.c_upper.val
+        current_max_td.textContent = c_val
         dataList.appendChild(current_max_td);
 
         // 自动生成电压上限列
         const voltage_max_td = document.createElement('td');
-        voltage_max_td.textContent = voltage_upper[i];
+        u_u_val = channel_power_infro[j].thr.v_upper.val;
+        voltage_max_td.textContent = u_u_val;
         dataList.appendChild(voltage_max_td);
 
         // 自动生成电压下限列
         const voltage_min_td = document.createElement('td');
-        voltage_min_td.textContent = voltage_lower[i];
+        u_l_val = channel_power_infro[j].thr.v_lower.val;
+        voltage_min_td.textContent = u_l_val
         dataList.appendChild(voltage_min_td);
 
         // 自动生成功率上限列
         const power_max_td = document.createElement('td');
-        power_max_td.textContent = power_upper[i];
+        p_val = channel_power_infro[j].thr.p_upper.val;
+        power_max_td.textContent = p_val
         dataList.appendChild(power_max_td);
 
         // 自动生成耗电量上限列
         const consump_td = document.createElement('td');
-        consump_td.textContent = consump_upper[i];
+        c_val = channel_power_infro[j].thr.w_upper.val;
+        consump_td.textContent = c_val
         dataList.appendChild(consump_td);
 
         // 自动生成配置按钮列
         const operation_td = document.createElement('button');
         operation_td.textContent = '配置';
-        operation_td.id = "edite"+{i}
+        operation_td.id = "edite"+{j}
         operation_td.addEventListener('click', function() {
             editRow(orgin_data,threshold,i,channel_power_infro)
         });

+ 7 - 5
f407/tools/web/JS/operation.js

@@ -8,16 +8,18 @@ function all_close()
     ws.send(mk_hdr(PKT_TYPE.PKT_TYPE_CH_ALL,0));
 }
 
-function single_open(j_data,channel_power_infro)
+function single_open(j_data,channel_power_infro,j)
 {
     j_c_data  = j_data
     data = channel_power_infro
     j_status = data[j].power[0].status
-    if(j_status = 1)
+    if(j_status == 0)
     {
-        data[j].power[0].status = 0
+        data[j].power[0].status = 1
     }
-    ws.send(mk_pkt(PKT_TYPE.PKT_TYPE_POWER_CH,SUB_TYPE.SUB_TYPE_POWER_SWITCH,data[j]))
+    a = pkt_to_bin(PKT_TYPE.PKT_TYPE_POWER_CH,SUB_TYPE.SUB_TYPE_POWER_SWITCH,data[j])
+    var b = bin_to_pkt(a)
+    ws.send(a)
 }
 
 function single_close(j_data,channel_power_infro,j)
@@ -25,7 +27,7 @@ function single_close(j_data,channel_power_infro,j)
     j_c_data  = j_data
     data = channel_power_infro
     j_status = data[j].power[0].status
-    if(j_status = 1)
+    if(j_status == 1)
     {
         data[j].power[0].status = 0
     }

+ 1 - 2
f407/tools/web/JS/ws.js

@@ -11,13 +11,12 @@ function on_ws_msg(bin){
     if(j.powerc != undefined){
         channel_power_infro = j.powerc
         channel_infro = channel_power_infro.power
-        threshold = j.powerc.thr
         alarm = j.powerc.alarm
         channel_number = j.powerc.info
         channel_power = j.powerc.power
         j_data = j
         Channel_Info(j_data,channel_power_infro)
-        //threshold_mannage(j,channel_power_infro,threshold)
+        threshold_mannage(j,channel_power_infro)
         //populateTable(j_data,channel_power)
     }
     if(j.alarmd != undefined)