root/core/gui_batt.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. get_batt_average
  2. get_batt_perc
  3. gui_batt_draw_icon
  4. gui_batt_draw_charge
  5. gui_batt_draw_volts
  6. gui_batt_draw_osd

   1 #include "camera_info.h"
   2 #include "keyboard.h"
   3 #include "battery.h"
   4 #include "conf.h"
   5 #include "gui_draw.h"
   6 #include "gui_batt.h"
   7 //-------------------------------------------------------------------
   8 
   9 static char osd_buf[32];
  10 
  11 //-------------------------------------------------------------------
  12 static long get_batt_average() {
  13     #define VOLTS_N         100
  14     static unsigned short   volts[VOLTS_N] = {0};
  15     static unsigned int     n = 0, rn = 0;
  16     static unsigned long    volt_aver = 0;
  17 
  18     volt_aver-=volts[n];
  19     volts[n]=(unsigned short)stat_get_vbatt();
  20     volt_aver+=volts[n];
  21     if (++n>rn) rn=n;
  22     if (n>=VOLTS_N) n=0;
  23     return volt_aver/rn;
  24 }
  25 
  26 //-------------------------------------------------------------------
  27 unsigned long get_batt_perc() {
  28     long v;
  29 
  30     v = get_batt_average();
  31     if (v>conf.batt_volts_max) v=conf.batt_volts_max;
  32     if (v<conf.batt_volts_min) v=conf.batt_volts_min;
  33     return (v-conf.batt_volts_min)*100/(conf.batt_volts_max-conf.batt_volts_min);
  34 }
  35 
  36 //-------------------------------------------------------------------
  37 static icon_cmd batt_icon[] =
  38 {
  39         { IA_ROUND_RECT,   0,  3,  3,  9, IDX_COLOR_GREY,        IDX_COLOR_GREY        },
  40         { IA_RECT,         3,  0, 31, 12, IDX_COLOR_GREY,        IDX_COLOR_GREY        },
  41         { IA_FILLED_RECT,  1,  4,  2,  8, IDX_COLOR_YELLOW_DK,   IDX_COLOR_YELLOW_DK   },
  42         { IA_FILLED_RECT,  4,  6, 30, 11, IDX_COLOR_GREY_DK,     IDX_COLOR_GREY_DK     },
  43         { IA_FILLED_RECT,  4,  1, 30,  5, IDX_COLOR_GREY_LT,     IDX_COLOR_GREY_LT     },
  44         { IA_RECT,         4,  2, 30, 10, 0,                     0                     },
  45         { IA_FILLED_RECT, 29,  6, 29,  9, 0,                     0                     },
  46         { IA_FILLED_RECT, 29,  3, 29,  5, 0,                     0                     },
  47         { IA_END }
  48 };
  49 
  50 static void gui_batt_draw_icon ()
  51 {
  52     int perc = get_batt_perc();
  53 
  54     // set bar color depending percent
  55     color cl1 = (perc>50) ? IDX_COLOR_GREEN_DK :(perc<=20) ? IDX_COLOR_RED_DK : IDX_COLOR_YELLOW_DK;
  56     color cl2 = (perc>50) ? IDX_COLOR_GREEN    :(perc<=20) ? IDX_COLOR_RED    : IDX_COLOR_YELLOW;
  57     color cl3 = (perc>50) ? IDX_COLOR_GREEN_LT :(perc<=20) ? IDX_COLOR_RED_LT : IDX_COLOR_YELLOW_LT;
  58 
  59     // Set dynamic properties for battery level
  60     batt_icon[5].cb = cl1;
  61     batt_icon[6].x1 = batt_icon[7].x1 = 29 - (25 * perc / 100);
  62     batt_icon[6].cb = batt_icon[6].cf = cl2;
  63     batt_icon[7].cb = batt_icon[7].cf = cl3;
  64 
  65     // Draw icon
  66     draw_icon_cmds(conf.batt_icon_pos.x, conf.batt_icon_pos.y, batt_icon);
  67 }
  68 
  69 //-------------------------------------------------------------------
  70 static void gui_batt_draw_charge(){
  71     int perc = get_batt_perc();
  72     twoColors cl = user_color((perc<=20) ? conf.osd_color_warn : conf.osd_color);
  73     sprintf(osd_buf, "%3d%%", perc);
  74     osd_buf[5]=0;
  75     draw_osd_string(conf.batt_txt_pos, 0, 0, osd_buf, cl, conf.batt_txt_scale);
  76 }
  77 
  78 //-------------------------------------------------------------------
  79 static void gui_batt_draw_volts() {
  80     unsigned long v;
  81 
  82     v = get_batt_average();
  83     sprintf(osd_buf, "%ld.%03ld", v/1000, v%1000);
  84     osd_buf[5]=0;
  85     draw_osd_string(conf.batt_txt_pos, 0, 0, osd_buf, user_color(conf.osd_color), conf.batt_txt_scale);
  86 }
  87 
  88 //-------------------------------------------------------------------
  89 void gui_batt_draw_osd(int is_osd_edit)
  90 {
  91     if (conf.batt_perc_show || is_osd_edit)
  92         gui_batt_draw_charge();
  93 
  94     if (conf.batt_volts_show || is_osd_edit)
  95         gui_batt_draw_volts();
  96     
  97     if (conf.batt_icon_show || is_osd_edit)
  98         gui_batt_draw_icon();
  99 }
 100 
 101 //-------------------------------------------------------------------

/* [<][>][^][v][top][bottom][index][help] */