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

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