Quellcode durchsuchen

添加beep和led接口
改控制板阈值设置bug

guohui vor 1 Jahr
Ursprung
Commit
66680ebd11
10 geänderte Dateien mit 282 neuen und 79 gelöschten Zeilen
  1. 1 0
      pro/CMakeLists.txt
  2. 2 2
      pro/src/appweb_handle.c
  3. 3 39
      pro/src/switch_ctrl.c
  4. 87 8
      pro/ui/beep.c
  5. 4 3
      pro/ui/beep.h
  6. 114 4
      pro/ui/led.c
  7. 10 3
      pro/ui/led.h
  8. 14 4
      pro/ui/menu.c
  9. 45 14
      pro/ui/timer.c
  10. 2 2
      pro/ui/timer.h

+ 1 - 0
pro/CMakeLists.txt

@@ -76,6 +76,7 @@ set(PDU_SRC_LIST
 	${PROJECT_SOURCE_DIR}/ui/menu.c
 	${PROJECT_SOURCE_DIR}/ui/timer.c
 	${PROJECT_SOURCE_DIR}/ui/key.c
+	${PROJECT_SOURCE_DIR}/ui/led.c
     ${PROJECT_SOURCE_DIR}/ui/lcd.c
     ${PROJECT_SOURCE_DIR}/ui/ui.c
 

+ 2 - 2
pro/src/appweb_handle.c

@@ -2988,7 +2988,7 @@ char* setThresholdToCh(_AlarmRequestInfo* _alarm_request_info,int nChID)
                                                     _globalPowerMangerSaveTemp->product_ch_type,
                                                     _pTreeACPowerMangerTemp->product_saddr,
                                                     _pTreeACPowerMangerTemp->product_ch_addr,
-                                                    _globalPowerMangerSaveTemp, 0);
+                                                    _globalPowerMangerSaveTemp, 1);
         }
     }
     else
@@ -2997,7 +2997,7 @@ char* setThresholdToCh(_AlarmRequestInfo* _alarm_request_info,int nChID)
                                                 _globalPowerMangerSaveTemp->product_ch_type,
                                                 _globalPowerMangerSaveTemp->product_saddr,
                                                 _globalPowerMangerSaveTemp->product_ch_addr,
-                                                _globalPowerMangerSaveTemp, 0);
+                                                _globalPowerMangerSaveTemp, 1);
     }
 
     if (ret < 0)

+ 3 - 39
pro/src/switch_ctrl.c

@@ -1049,20 +1049,7 @@ int g_switch_set_all_single_threshold(void* manger,int ntype,int saddr,char chn,
     case AC_SINGLE_B_TYPE:
     {
         ret = g_switch_set_ac_single_threshold(manger, saddr, (chn - 1), _global_over_manager);
-            if (_global_over_manager->product_vol_upper_enable == 1)
-                sts |= ENABLE_V_UP;
-            if (_global_over_manager->product_vol_lower_enable == 1)
-                sts |= ENABLE_V_DOWN;
-            if (_global_over_manager->product_cur_upper_enable == 1)
-                sts |= ENABLE_A_UP;
-            if (_global_over_manager->product_pwr_upper_enable == 1)
-                sts |= ENABLE_W_UP;
-            if (_global_over_manager->product_pwrcon_upper_enable == 1)
-                sts |= ENABLE_P_UP;
-        ret = g_switch_set_ac_alarm_ctrl(manger, saddr, (chn - 1), _global_over_manager);
-        if(setCh) {
-            ret = g_switch_set_ac_single_s_chn_ctrl(manger, saddr, (chn - 1), sts);
-        }
+        if(setCh)  ret = g_switch_set_ac_alarm_ctrl(manger, saddr, (chn - 1), _global_over_manager);
     }
     break;
     case DC_OUT_TYPE:
@@ -1078,9 +1065,8 @@ int g_switch_set_all_single_threshold(void* manger,int ntype,int saddr,char chn,
         ret = g_switch_set_dcpdu_max_power_threshold(manger, saddr, (chn - 1), _global_over_manager);
         ret = g_switch_set_dcpdu_max_pwrcon_threshold(manger, saddr, (chn - 1), _global_over_manager);
 
-        if(setCh) {
-            ret = g_switch_set_dcpdu_alarm_ctrl(manger, saddr, (chn - 1), _global_over_manager);
-        }
+        if(setCh)  ret = g_switch_set_dcpdu_alarm_ctrl(manger, saddr, (chn - 1), _global_over_manager);
+        
     }
     break;
     case TREE_AC_TYPE:
@@ -1131,28 +1117,6 @@ int g_switch_set_all_single_threshold(void* manger,int ntype,int saddr,char chn,
                     log_e("Threshold AlarmCtrl Set Error=%s", modbus_strerror(errno));
                 }
             }
-
-            if (_global_over_manager->product_vol_upper_enable == 1)
-                sts |= ENABLE_TAC_V_UP;
-            if (_global_over_manager->product_vol_lower_enable == 1)
-                sts |= ENABLE_TAC_V_DOWN;
-            if (_global_over_manager->product_cur_upper_enable == 1)
-                sts |= ENABLE_TAC_A_UP;
-            if (_global_over_manager->product_pwr_upper_enable == 1)
-                sts |= ENABLE_TAC_W_UP;
-            if (_global_over_manager->product_pwrcon_upper_enable == 1)
-                sts |= ENABLE_TAC_P_UP;
-
-            if(setCh) {
-                if (__globalDeviceManage._globalDevInfo.product.pwr_type == SmartPDU_Tree_AC_One)
-                {
-                    ret = g_switch_set_t_ac_phchn_ctrl(manger, saddr, (chn - 1), sts);
-                }
-                else
-                {
-                    ret = g_switch_set_t_ac_chn_ctrl(manger, saddr, (chn - 1), sts);
-                }
-            }
         }
     }
     break;

+ 87 - 8
pro/ui/beep.c

@@ -1,4 +1,5 @@
 #include "gpio.h"
+#include "timer.h"
 #include "elog.h"
 #include "beep.h"
 
@@ -10,38 +11,116 @@
     #define LOGE  printf
 #endif
 
-#define BEEP_LEVEL          0
+#define BEEP_GPIO               103     //PD7=96+7
+#define BEEP_ON_LEVEL           1
+#define BEEP_OFF_LEVEL          0
 
 static beep_para_t beep_para[BEEP_MODE_MAX]={
-    //{},
-    //{},
-    //{},
-    //{},
+    {50, 100, 10},      //BEEP_MODE_WARN
+    {50, 100, 10},      //BEEP_MODE_ERROR
+    {50, 100, 10},      //BEEP_MODE_EMERG
+    {50, 100, 10},      //BEEP_MODE_FATAL
 };
+typedef struct {
+    int             io;
+    int             tmr;
+    uint32_t        cnt;
+    beep_para_t     para;
+}beep_handle_t;
+static beep_handle_t bpHandle={0};
 
+static void tmr_handler(void *arg, int last)
+{
+    beep_handle_t *h=(beep_handle_t*)arg;
+    
+    h->cnt++;
+    if(h->cnt%2) {
+        if(h->para.off_ms) {
+            gpio_set(h->io, BEEP_ON_LEVEL);
+            timer_setup(h->tmr, h->para.off_ms, 0);
+        }
+    }
+    else {
+        if(h->para.on_ms) {
+            gpio_set(h->io, BEEP_OFF_LEVEL);
+            timer_setup(h->tmr, h->para.on_ms, 0);
+        }
+    }
+    
+    if(last) {
+        timer_stop(h->tmr);
+    }
+}
+/////////////////////////////////////////////
 
 
 int beep_init(void)
 {
+    beep_handle_t *h=&bpHandle;
+    
+    h->io = gpio_init(BEEP_GPIO, GPIO_OUT);
+    gpio_set(h->io, BEEP_OFF_LEVEL);
+    h->tmr = -1;
+
+    //beep_para_t para={300, 300, 10};
+    //beep_set_ex(&para);
+
     return 0;
 }
 
 
-int beep_start(int mode)
+int beep_deinit(void)
 {
+    beep_handle_t *h=&bpHandle;
+    
+    gpio_deinit(h->io);
+    timer_stop(h->tmr);
+    h->io = -1;
+    h->tmr = -1;
+    
     return 0;
 }
 
 
-int beep_start_ex(beep_para_t *para)
+int beep_set(int mode)
 {
+    beep_handle_t *h=&bpHandle;
+    
+    if(h->tmr!=-1) {
+        timer_stop(h->tmr);
+    }
+    h->cnt = 0;
+    h->para = beep_para[mode];
+    if(h->para.on_ms>0 && h->para.off_ms>0) {
+        h->para.times *=2;
+    }
+    h->tmr = timer_start(h->para.on_ms, 0, h->para.times, tmr_handler, h);
+    
     return 0;
 }
 
 
-int beep_stop(void)
+int beep_set_ex(beep_para_t *para)
 {
+    beep_handle_t *h=&bpHandle;
+    
+    if(!para) {
+        return -1;
+    }
+    
+    if(h->tmr!=-1) {
+        timer_stop(h->tmr);
+    }
+    h->cnt = 0;
+    h->para = *para;
+    if(h->para.on_ms>0 && h->para.off_ms>0) {
+        h->para.times *=2;
+    }
+    h->tmr = timer_start(h->para.on_ms, 0, h->para.times, tmr_handler, h);
+    
     return 0;
 }
 
 
+
+

+ 4 - 3
pro/ui/beep.h

@@ -17,8 +17,9 @@ typedef struct {
 }beep_para_t;
 
 int beep_init(void);
-int beep_start(int mode);
-int beep_start_ex(beep_para_t *para);
-int beep_stop(void);
+int beep_deinit(void);
+
+int beep_set(int mode);
+int beep_set_ex(beep_para_t *para);
 
 #endif

+ 114 - 4
pro/ui/led.c

@@ -1,4 +1,5 @@
 #include "led.h"
+#include "timer.h"
 #include "gpio.h"
 #include "elog.h"
 #include "common.h"
@@ -11,26 +12,135 @@
     #define LOGE  printf
 #endif
 
+#define LEDR_GPIO  106      //PD10=96+10
+#define LEDG_GPIO  105      //PD9=96+9
+
 
 typedef struct {
-             //0: release  1: press
-    uint64_t ms;
+    int         gpio;
+    int         on_level;
+    int         off_level;
 }led_info_t;
+static led_info_t led_info[LED_ID_MAX]={
+    {LEDR_GPIO, 0, 1},
+    {LEDG_GPIO, 0, 1},
+};
 
 
+typedef struct {
+    int         io;
+    int         tmr;
+    led_para_t  para;
+    led_info_t  *info;
+    uint32_t    cnt;
+    int         id;
+}led_data_t;
 
+typedef struct {
+    led_data_t  data[LED_ID_MAX];
+}led_handle_t;
+static led_handle_t ledHandle={0};
+
+static void tmr_handler(void *arg, int last)
+{
+    int level;
+    led_data_t *h=(led_data_t*)arg;
+    
+    h->cnt++;
+    if(h->cnt%2) {
+        if(h->para.off_ms>0) {
+            gpio_set(h->io, h->info->on_level);
+            timer_setup(h->tmr, h->para.off_ms, 0);
+        }
+    }
+    else {
+        if(h->para.on_ms>0) {
+            gpio_set(h->io, h->info->off_level);
+            timer_setup(h->tmr, h->para.on_ms, 0);
+        }
+    }
+    
+    if(last) {
+        timer_stop(h->tmr);
+    } 
+}
+//////////////////////////////////////////////////
 int led_init(void)
 {
+    int i;
+    led_handle_t *h=&ledHandle;
+    
+    for(i=0; i<LED_ID_MAX; i++) {
+        h->data[i].info = &led_info[i];
+        h->data[i].io = gpio_init(led_info[i].gpio, GPIO_OUT);
+        gpio_set(h->data[i].io, led_info[i].off_level);
+        h->data[i].tmr = -1;
+        h->data[i].cnt = 0;
+    }
+    
+    //led_para_t para={1000, 1000, -1};
+    //led_set_ex(LED_ID_RED, &para);
+    
     return 0;
 }
 
 
 int led_deinit(void)
 {
+    int i;
+    led_handle_t *h=&ledHandle;
+    
+    for(i=0; i<LED_ID_MAX; i++) {
+        gpio_deinit(h->data[i].io);
+        timer_stop(h->data[i].tmr);
+        
+        h->data[i].io = -1;
+        h->data[i].tmr = -1;
+    }
     return 0;
 }
 
-int led_set(led_para_t *red, led_para_t *green)
+
+int led_set(int mode)
 {
     return 0;
-}
+}
+
+
+int led_set_ex(int led_id, led_para_t *para)
+{
+    led_handle_t *h=&ledHandle;
+    
+    if(!para || para->times==0) {
+        return -1;
+    }
+
+    led_data_t *ld=&h->data[led_id];
+    if(ld->tmr!=-1) {
+        timer_stop(ld->tmr);
+    }
+    
+    ld->cnt = 0;
+    ld->para = *para;
+    if(ld->para.on_ms>0 && ld->para.off_ms>0) {
+        ld->para.times *= 2;
+    }
+    ld->tmr = timer_start(ld->para.on_ms, 0, ld->para.times, tmr_handler, ld);
+    
+    return ld->tmr;
+}
+
+
+int led_stop(int h)
+{
+    led_data_t *ld=(led_data_t*)h;
+    
+    if(h==-1) {
+        return -1;
+    }
+    
+    timer_stop(ld->tmr);
+    ld->tmr = -1;
+    return 0;
+}
+

+ 10 - 3
pro/ui/led.h

@@ -1,6 +1,14 @@
 #ifndef __LED_Hx__
 #define __LED_Hx__
 
+
+enum {
+    LED_ID_RED=0,
+    LED_ID_GREEN,
+    
+    LED_ID_MAX
+};
+
 typedef struct {
     int on_ms;
     int off_ms;
@@ -10,8 +18,7 @@ typedef struct {
 
 int led_init(void);
 int led_deinit(void);
-
-int led_set(led_para_t *red, led_para_t *green);
-
+int led_set(int mode);
+int led_set_ex(int led_id, led_para_t *para);
 
 #endif

+ 14 - 4
pro/ui/menu.c

@@ -2,6 +2,7 @@
 #include <unistd.h>
 #include "menu.h"
 #include "lcd.h"
+#include "led.h"
 #include "beep.h"
 #include "paras.h"
 #include "cascade.h"
@@ -65,22 +66,27 @@ static inline GlobalDeviceManager* get_dm(void)
     return &__globalDeviceManage;
 }
 
-static void tmr_handler(void *arg)
+static void tmr_handler(void *arg, int last)
 {
     menu_handle_t *h=(menu_handle_t*)arg;
     h->uflag = 1;
+    
+    if(last) {
+        timer_stop(h->tmr);
+    }
 }
 static void tmr_start(menu_handle_t *h, int ms)
 {
     if(h->tmr!=-1) {
         timer_stop(h->tmr);
     }
-    h->tmr = timer_start(0, ms, 1, tmr_handler, h);
+    h->tmr = timer_start(0, ms, -1, tmr_handler, h);
 }
 static void tmr_stop(menu_handle_t *h)
 {
     timer_stop(h->tmr);
     h->tmr = -1;
+    h->uflag = 0;
 }
 
 static void menu_system_paint(menu_handle_t *h, int font1, int font2, int item_h)
@@ -208,7 +214,7 @@ static int menu_modbus_handle(menu_handle_t *h, ModbusInfo_t *pmb, key_val_t *kv
                     h->item_id = MODBUS_ITEM_ADDR;
                 }
             }
-            else {      //鑒令긍서
+            else {      //占쏙옙令占썅서
                 if(h->item_id==MODBUS_ITEM_ADDR) {         //addr
                     if(pmb->addr) {
                         pmb->addr--;
@@ -300,6 +306,8 @@ int menu_init(void)
     h->tmr = -1;
     
     key_init();
+    led_init();
+    beep_init();
     lcd_init(LCD_WIDTH,LCD_HEIGHT,LCD_COLOR);
     
     return 0;
@@ -309,8 +317,10 @@ int menu_deinit(void)
 {
     menu_handle_t *h=&mnHandle;
     
-    key_deinit();
     lcd_deinit();
+    key_deinit();
+    led_deinit();
+    beep_deinit();
     
     return 0;
 }

+ 45 - 14
pro/ui/timer.c

@@ -16,35 +16,57 @@ typedef struct {
 
 static void timer_callback(sigval_t sv)
 {
+    
     timer_handle_t *h=(timer_handle_t*)sv.sival_ptr;
     if(h->fn) {
+        int last=0;
         if(h->times_max>0) {
             if(h->times<h->times_max) {
-                h->fn(h->arg);
                 h->times++;
             }
-            else {
-                timer_stop((int)h);
+            
+            if(h->times==h->times_max) {
+                last = 1;
             }
+            
+            h->fn(h->arg, last);
+        }
+        else {
+            h->fn(h->arg, 0);
         }
     }
 }
+static int set_time(timer_handle_t *h, int t1, int t2)
+{
+    int r;
+    struct itimerspec it;
+
+    it.it_value.tv_sec  = t1/1000;                 //锟斤拷时锟斤拷锟斤拷始锟斤拷锟斤拷时锟斤拷
+    it.it_value.tv_nsec = (t1%1000)*1000;          
+    it.it_interval.tv_sec  = t2/1000;              //��ʱ�����Ϊ0�룬��ʾֻ����һ��
+    it.it_interval.tv_nsec = (t2%1000)*1000;
+    r = timer_settime(h->tid, 0, &it, NULL);
+    if(r<0) {
+        return -1;
+    }
+    return 0;
+}
+
 
 int timer_start(int t1, int t2, int times, timer_fn_t fn, void *arg)
 {
     int r;
     struct sigevent sev;
-    struct itimerspec it;
     timer_handle_t *h=(timer_handle_t*)malloc(sizeof(timer_handle_t));
     
     if(!h) {
         return -1;
     }
     
-    sev.sigev_notify = SIGEV_THREAD; // 通知类型为线程
-    sev.sigev_notify_function = timer_callback; // 回调函数
+    sev.sigev_notify = SIGEV_THREAD; // 通知锟斤拷锟斤拷为锟竭筹拷
+    sev.sigev_notify_function = timer_callback; // 锟截碉拷锟斤拷锟斤拷
     sev.sigev_notify_attributes = NULL;
-    sev.sigev_value.sival_ptr = h; // 传递给回调函数的数据
+    sev.sigev_value.sival_ptr = h; // 锟斤拷锟捷革拷锟截碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
     r = timer_create(CLOCK_REALTIME, &sev, &h->tid);
     if(r<0) {
         free(h); return -1;
@@ -53,22 +75,31 @@ int timer_start(int t1, int t2, int times, timer_fn_t fn, void *arg)
     h->times_max = times;
     h->fn  = fn;
     h->arg = arg;
+    h->inited = 1;
     
-    it.it_value.tv_sec  = t1/1000;                 //定时器初始触发时间为5秒
-    it.it_value.tv_nsec = (t1%1000)*1000;          
-    it.it_interval.tv_sec  = t2/1000;              //定时器间隔为0秒,表示只触发一次
-    it.it_interval.tv_nsec = (t2%1000)*1000;
-    r = timer_settime(h->tid, 0, &it, NULL);
+    r = set_time(h, t1, t2);
     if(r<0) {
         timer_delete(h->tid);
         free(h); return -1;
     }
-    h->inited = 1;
-    
     return (int)h;
 }
 
 
+int timer_setup(int h, int t1, int t2)
+{
+    int r;
+    timer_handle_t *th=(timer_handle_t*)h;
+    
+    if(!th || !th->inited) {
+        return -1;
+    }
+    
+    return set_time(th, t1, t2);
+}
+
+
+
 int timer_stop(int h)
 {
     int r;

+ 2 - 2
pro/ui/timer.h

@@ -2,11 +2,11 @@
 #define __TIMER_Hx__
 
 
-typedef void (*timer_fn_t)(void *arg);
+typedef void (*timer_fn_t)(void *arg, int last);
 
 int timer_start(int t1, int t2, int times, timer_fn_t fn, void *arg);
 int timer_stop(int h);
-
+int timer_setup(int h, int t1, int t2);
 
 #endif