guohui 1 年之前
父节点
当前提交
53c8289ccc

+ 2 - 1
f407/applications/datadef.h

@@ -301,7 +301,8 @@ typedef struct {
     int (*detect)(uint8_t addr);
     int (*get_info)(uint8_t addr, board_info_t *info);
     //int (*get_board)(board_data_t *pbrd);
-    int (*set_all)(uint8_t addr, uint8_t on);
+    int (*set_board)(uint8_t addr, uint8_t on);
+    int (*set_all)(uint8_t on);
 }board_fn_t;
 
 typedef struct board_data {

+ 80 - 47
f407/applications/power.c

@@ -36,20 +36,81 @@ typedef struct {
     product_data_t *prod;
     power_data_t   pdat;
 }power_handle_t;
+
+static int get_power(power_ch_t *pch)
+{
+    return power_get_ch(pch->info.ch, pch);
+}
+static int get_alarm(power_ch_t *pch)
+{
+    power_ch_t pc;
+    int r = power_get_ch(pch->info.ch, &pc);
+    if(r==0) {
+        pch->alarm = pc.alarm;
+    }
+    return r;
+}
+static int set_ch(power_ch_t *pch)
+{
+    return power_set_ch_sw(pch->info.ch, pch->power[0].status);
+}
+static int set_open_delay(power_ch_t *pch)
+{
+    return power_set_start_delay(pch);
+}
+static int set_close_delay(power_ch_t *pch)
+{
+    return power_set_stop_delay(pch);
+}
+static int set_kb_value(power_ch_t *pch)
+{
+    return 0;//power_set_kb_val(pch);
+}
+static int set_threshold(power_ch_t *pch)
+{
+    return power_set_threshold(pch);
+}
+static int reset_consump(power_ch_t *pch)
+{
+    return power_reset();
+}
+static int do_detect(uint8_t addr)
+{
+    return 0;
+}
+static int get_info(uint8_t addr, board_info_t *info)
+{
+    return 0;
+}
+static int get_board(board_data_t *pbrd)
+{
+    return 0;
+}
+static int set_board(uint8_t addr, uint8_t on)
+{
+    return power_set_board_sw(addr, on);
+}
+static int set_all(uint8_t on)
+{
+    return power_set_all_sw(on);
+}
+
+
 static board_fn_t board_fn={
-    .get_power = NULL,
-    .get_alarm = NULL,
-    .set_ch = NULL,
-    .set_open_delay = NULL,
-    .set_close_delay = NULL,
-    .set_kb_value = NULL,
-    .set_threshold = NULL,
-    .reset_consump = NULL,
+    .get_power = get_power,
+    .get_alarm = get_alarm,
+    .set_ch = set_ch,
+    .set_open_delay = set_open_delay,
+    .set_close_delay = set_close_delay,
+    .set_kb_value = set_kb_value,
+    .set_threshold = set_threshold,
+    .reset_consump = reset_consump,
 
-    .detect = NULL,
-    .get_info = NULL,
-    //.get_board = NULL,
-    .set_all = NULL,
+    .detect = do_detect,
+    .get_info = get_info,
+    //.get_board = get_board,
+    .set_board = set_board,
+    .set_all = set_all,
 };
 static power_handle_t pwrHandle={0};
 
@@ -133,7 +194,7 @@ static int get_key(power_handle_t *h, uint8_t addr, board_key_t *key)
     return r;
 }
 ////////////////////////////////////////////////////////////////
-static int set_kb_value(power_handle_t *h, int type, int addr, kb_val_t *kv)
+int power_set_kb_value(power_handle_t *h, int type, int addr, kb_val_t *kv)
 {
     switch(type) {
         case AC_SINGLE_S_TYPE:
@@ -212,36 +273,6 @@ static int set_kb_value(power_handle_t *h, int type, int addr, kb_val_t *kv)
         return -1;
     }
 }
-static int reset_consump(power_handle_t *h, int type, int addr)
-{
-    switch(type) {
-        case AC_SINGLE_S_TYPE:
-        case AC_SINGLE_B_TYPE:
-        {
-            
-        }
-        break;
-
-        case DCPDU_TYPE:
-        {
-            
-        }
-        break;
-        
-        case TREE_AC_TYPE:
-        {
-            
-        }
-        break;
-        
-        case AC_MULTI_S_TYPE:
-        case AC_MULTI_B_TYPE:
-        case DC_OUT_TYPE:
-        case DC_IN_TYPE:
-        default:
-        return -1;
-    }
-}
 
 
 //////////////////////////////////////////////////////////////////
@@ -757,16 +788,16 @@ int power_get_ch(uint8_t ch, power_ch_t *pch)
 }
 
 
-int power_get_board(board_data_t *pb)
+int power_get_board(board_data_t *pbrd)
 {
     power_handle_t *h=&pwrHandle;
     
     lock_on(h->lck);
-    if(!pb || !h->pch || !h->cnt || !h->pbrd[pb->addr]) {
+    if(!pbrd || !h->pch || !h->cnt || !h->pbrd[pbrd->addr]) {
         lock_off(h->lck);
         return -1;
     }
-    *pb = *h->pbrd[pb->addr];
+    *pbrd = *h->pbrd[pbrd->addr];
     lock_off(h->lck);
     
     return 0;
@@ -1086,12 +1117,14 @@ int power_set_ch_sw(uint8_t ch, uint8_t on)
 }
 
 
-static int set_board_sw(board_data_t *pbrd, uint8_t on)
+int power_set_board_sw(uint8_t addr, uint8_t on)
 {
     int i,r;
     power_ch_t *pch;
+    board_data_t *pbrd;
     power_handle_t *h=&pwrHandle;
     
+    pbrd = h->pbrd[addr];
     if(!pbrd) {
         return -1;
     }

+ 2 - 0
f407/applications/power.h

@@ -163,11 +163,13 @@ int power_get_ch(uint8_t ch, power_ch_t *pch);
 int power_get_board(board_data_t *pb);
 
 int power_set_ch_sw(uint8_t ch, uint8_t on);
+int power_set_board_sw(uint8_t addr, uint8_t on);
 int power_set_all_sw(uint8_t on);
 int power_set_alarm(power_ch_t *pch);
 int power_set_threshold(power_ch_t *pch);
 int power_set_start_delay(power_ch_t *pch);
 int power_set_stop_delay(power_ch_t *pch);
+int power_get_board(board_data_t *pbrd);
 int power_reset(void);
 
 power_data_t power_data_get(void);

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

@@ -34,7 +34,7 @@ typedef struct {
 typedef struct {
     key_info_t  k1;
     key_info_t  k2;
-    int         long_trigged;
+    uint8_t     long_trigged;
 }key_data_t;
 typedef struct {
     io_info_t   *io;

+ 13 - 15
f407/applications/ui/lcd.c

@@ -27,9 +27,12 @@ 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);
+extern void st77xx_fill(lcd_handle_t *h, uint32_t color);
+extern void st77xx_fill_rect(lcd_handle_t *hd, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color);
 
 static inline int set_point(lcd_handle_t *h, int x, int y, uint32_t data)
 {
+#if 0
     int pos,bit;
 
     if(h->rotate==180) {
@@ -45,6 +48,9 @@ static inline int set_point(lcd_handle_t *h, int x, int y, uint32_t data)
     else {
         h->buf[pos*h->width+x] &= ~BIT(bit);        		/* set 0 */
     }
+#else
+    st77xx_draw_pixel(h,x,y,data);
+#endif
     
 	return 0;
 }
@@ -116,8 +122,7 @@ void lcd_set_win(int x, int y, int w, int h)
 void lcd_fill(uint32_t color)
 {
     lcd_handle_t *h=&lcdHandle;
-    
-    lcd_fill_rect(0, 0, h->width, h->height, color);
+    st77xx_fill(h, color);
 }
 
 
@@ -212,14 +217,8 @@ void lcd_draw_rect(int x, int y, int w, int h, uint32_t color)
 
 void lcd_fill_rect(int x, int y, int w, int h, uint32_t color)
 {
-    int i,j;
-    lcd_handle_t *h2=&lcdHandle;
-
-    for(i=x; i<x+w; i++) {
-        for(j=y; j<y+h; j++) {
-            set_point(h2, i, j, color);
-        }
-    }
+    lcd_handle_t *hd=&lcdHandle;
+    st77xx_fill_rect(hd, x, y, w, h, color);
 }
 
 
@@ -279,13 +278,12 @@ 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];
         for(j=0; j<8; j++)  {
             if((x<x2 && x<hd->width) && (y<y2 && y<hd->height)) 
             {
-                int dx=x-x0,dy=y-y0;
+                int dx=x-x1,dy=y-y1;
                 
                 if(tmp&0x01) {
                     hd->buf[dy*fdata.width+dx] = color;
@@ -300,7 +298,7 @@ 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);
+    st77xx_refresh(hd, x1, y1, fdata.width, fdata.height, hd->buf, fdata.width*fdata.height*2);
     #else
     for(i=0; i<fdata.dlen; i++)  {
         tmp = fdata.data[i];
@@ -308,10 +306,10 @@ int lcd_draw_char(lcd_handle_t *hd, int x, int y, int w, int h, uint8_t *c, int
             if((x<x2 && x<hd->width) && (y<y2 && y<hd->height)) 
             {
                 if(tmp&0x01) {
-                    st77xx_draw_pixel(hd, x, y, color);
+                    set_point(hd, x, y, color);
                 }
                 else {
-                    st77xx_draw_pixel(hd, x, y, bgcolor);
+                    set_point(hd, x, y, bgcolor);
                 }
             }
             tmp >>= 1;

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

@@ -161,14 +161,14 @@ static void tmr_stop(menu_handle_t *h)
 static void get_curtime(char *time, int len)
 {
     struct tm *t=localtime(NULL);
-    snprintf(time, len, "%02d%/%02d/%02d %02d:%02d:%02d", (t->tm_year+1900)/100, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
+    snprintf(time, len, "%02d%/%02d/%02d %02d:%02d:%02d", (t->tm_year+1900)%100, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
 }
 
 static void menu_system_paint(menu_handle_t *h, int font1, int font2, int item_h, key_val_t *kv)
 {
     char time[40],tmp[60];
 
-    lcd_fill(0);
+    lcd_fill(COLOR_BLACK);
     sprintf(tmp, "SmartPDU");
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
 
@@ -199,7 +199,7 @@ static void menu_input_paint(menu_handle_t *h, int font1, int font2, int item_h,
         }
     }
 
-    lcd_fill(0);
+    lcd_fill(COLOR_BLACK);
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
 
 #ifdef TEXT_ALIGN
@@ -239,7 +239,7 @@ static void menu_output_paint(menu_handle_t *h, int font1, int font2, int item_h
         sprintf(tmp, "%s CH%d", lang_get_str(h->lang, STR_ID_OUTPUT), h->ch_out+1);
     }
 
-    lcd_fill(0);
+    lcd_fill(COLOR_BLACK);
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
 
     char *pon=((pwr->status)?lang_get_str(h->lang, STR_ID_ON):lang_get_str(h->lang, STR_ID_OFF));
@@ -270,7 +270,7 @@ static void menu_sensor_paint(menu_handle_t *h, int font1, int font2, int item_h
 {
     char tmp[100];
 
-    lcd_fill(0);
+    lcd_fill(COLOR_BLACK);
     sprintf(tmp, "%s/%s", lang_get_str(h->lang, STR_ID_TEMP), lang_get_str(h->lang, STR_ID_HUMI));
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
 
@@ -306,7 +306,7 @@ static void menu_modbus_paint(menu_handle_t *h, int font1, int font2, int item_h
         flash_cnt++;
     }
 
-    lcd_fill(0);
+    lcd_fill(COLOR_BLACK);
 
     sprintf(tmp, "MODBUS %s", lang_get_str(h->lang, STR_ID_SETT));
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
@@ -369,7 +369,7 @@ int menu_init(void)
     
     memset(h, 0, sizeof(menu_handle_t));
     h->lang = lang_id;
-    h->tmr = timer_init();
+    //h->tmr = timer_init();
     h->flip_ms = get_ms();
     h->refresh_ms = get_ms();
     h->uflag |= UFLAG_REFRESH;

+ 21 - 9
f407/applications/ui/st77xx.c

@@ -25,7 +25,7 @@
 
 #define delay_ms(x)             rt_thread_mdelay(x)
 
-static void st77xx_fill(lcd_handle_t *h, uint16_t color);
+void st77xx_fill(lcd_handle_t *h, uint32_t color);
 
 static void write_cmd(lcd_handle_t *h, uint8_t reg)
 {
@@ -232,17 +232,31 @@ static void write_color(lcd_handle_t *h, uint16_t color, int cnt)
         write_16bit(h, color);
     }
 }
-static void st77xx_fill(lcd_handle_t *h, uint16_t color)
+
+void st77xx_fill_rect(lcd_handle_t *hd, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color)
 {
-    int i,height=h->height/DIV_NUM;
+    int height=hd->height/DIV_NUM;
+    int i,y1=0,h1=0,times=h/height,left=h%height;
     
-    fill_color(h, color, h->buflen/2);
-    for(i=0; i<DIV_NUM; i++) {
-        st77xx_refresh(h, 0, i*height, h->width, height, h->buf, h->buflen);
+    times += left?1:0;
+    fill_color(hd, color, hd->buflen/2);
+    for(i=0; i<times; i++) {
+        y1 = y+i*height;
+        h1 = ((h1+height)>h)?(h-h1):height;
+        
+        st77xx_refresh(hd, x, y1, w, h1, hd->buf, w*h1*2);
     }
 }
 
 
+void st77xx_fill(lcd_handle_t *h, uint32_t color)
+{
+    st77xx_fill_rect(h, 0, 0, h->width, h->height, color);
+}
+
+
+
+
 #define SPI_BUS  "spi2"
 #define SPI_DEV_NAME   "spi2.0"
 int st77xx_init(lcd_handle_t *h)
@@ -275,14 +289,12 @@ int st77xx_init(lcd_handle_t *h)
         LOGE("malloc buffer falied\n");
         return -1;
     }
-    
+return 0;    
     st77xx_reset(h);
     st77xx_reg_init(h);
     st77xx_rotate(h, h->rotate);
     gpio_set(BK_PIN, 1);
-    
     st77xx_fill(h, COLOR_BLACK);
-    
 
     return 0;
 }

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

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

+ 1 - 1
f407/tools/web/JS/channel_display.js

@@ -28,7 +28,7 @@ function channel_display(j_data,channel_power_infro)
 
             //自动生成相序列
             const xiangxu_td = document.createElement('td');
-            xiangxu_td.textContent = "L"+j
+            xiangxu_td.textContent = "L1"
             dataList.appendChild(xiangxu_td);
 
         // 自动生成电压列

+ 114 - 0
f407/tools/web/JS/data_process.js

@@ -0,0 +1,114 @@
+channle_datas = []
+let currentNumber = 1;
+let resultArray = [];
+const cyclesPerNumber = 3;
+let button_status = [];
+const data = [];
+const datas = []
+const finall_data = []
+const processing_data = {}
+// function data_process()
+// {
+//     //chaannle_length = pageData.length
+//     // for(let i = 1;i<chaannle_length;i++)
+//     // {
+//     //     channle_datas.push(pageData[i])
+//     // }
+//     //const totalIterations = channle_datas.length;
+//     const text_length = data_arr.length
+//     // for (let i = 0; i < totalIterations; i++) {
+//     //     resultArray.push(currentNumber);
+//     //     if ((i + 1) % cyclesPerNumber === 0) {
+//     //         // 如果是,则递增数字
+//     //         currentNumber++;
+//     //     }
+//     // }
+//     channle_datas = data_arr
+//     for(let j = 0;j < text_length;j++)
+//     {
+//         j_type = channle_datas[j].info.type
+//         if(j_type = 1)
+//         {
+//             j_c_type = '直流'
+//         }
+//         if(j_type = 3)
+//         {
+//             j_c_type = '三相'
+//         }
+//         if(j_type = 5)
+//         {
+//             j_c_type = '单相'
+//         }
+//         j_open_time = channle_datas[j].info.start_delay
+//         j_close_time = channle_datas[j].info.stop_delay
+//         j_device_name = 'SmartPDU'
+//         j_channle_name = `CH${j+1}`
+//         for(let i = 0;i<3;i++)
+//         {
+//             j_status = channle_datas[j].power[i].status
+//             j_channle = channle_datas[j].power[i]
+//             j_infor = channle_datas[j].info
+//             if(j_status = 0)
+//             {
+//                 j_c_status = '关闭'
+//                 datas.push(j_device_name),
+//                 datas.push(j_channle_name),
+//                 datas.push(j),
+//                 datas.push(j_c_type),
+//                 datas.push(j_c_status),
+//                 datas.push(j_open_time),
+//                 datas.push(j_close_time),
+//                 datas.push(j_channle.voltage),
+//                 datas.push(j_channle.current),
+//                 datas.push(j_channle.power),
+//                 datas.push(j_channle.freq),
+//                 datas.push(j_channle.consump)
+//                 datas.push(j_channle.factor)
+//                 num = datas
+//             }
+//             if(j_status = 1)
+//             {
+//                 j_c_status = '关闭'
+//                 datas.push(j_device_name),
+//                 datas.push(j_channle_name),
+//                 datas.push(j),
+//                 datas.push(j_c_type),
+//                 datas.push(j_c_status),
+//                 datas.push(j_open_time),
+//                 datas.push(j_close_time),
+//                 datas.push(j_channle.voltage),
+//                 datas.push(j_channle.current),
+//                 datas.push(j_channle.power),
+//                 datas.push(j_channle.freq),
+//                 datas.push(j_channle.consump)
+//                 datas.push(j_channle.factor)
+//                 num = datas
+//             }
+//             for(let n = 0;n<num.length;n++)
+//             {
+//                 processing_data[chanle_data_process[n]] = num[n];
+//             }
+//             finall_data.push(processing_data)
+//         }
+//     }
+//     j_processed_data = finall_data
+// }
+const result = [];
+function alarm_process(alarmd_data)
+{
+    const alarmProperties = alarmd_data.alarm;
+    const baseProperties = {
+        "ch": alarmd_data.ch,
+        "time": alarmd_data.time
+    };
+    let idCounter = 1;
+ 
+    for (const key in alarmProperties) {
+        if (alarmProperties.hasOwnProperty(key) && alarmProperties[key] == 1) {
+            const newObj = { ...baseProperties, [key]: alarmProperties[key], "id": idCounter++ };
+            result.push(newObj);
+        }
+    }
+ 
+    return result;
+}