diff options
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r-- | firmware/powermgmt.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index c80e711a16..8712d6c8f2 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -51,6 +51,9 @@ | |||
51 | #endif | 51 | #endif |
52 | #include "logf.h" | 52 | #include "logf.h" |
53 | #include "lcd-remote.h" | 53 | #include "lcd-remote.h" |
54 | #ifdef SIMULATOR | ||
55 | #include <time.h> | ||
56 | #endif | ||
54 | 57 | ||
55 | /* | 58 | /* |
56 | * Define DEBUG_FILE to create a csv (spreadsheet) with battery information | 59 | * Define DEBUG_FILE to create a csv (spreadsheet) with battery information |
@@ -73,19 +76,50 @@ static int shutdown_timeout = 0; | |||
73 | 76 | ||
74 | #ifdef SIMULATOR /***********************************************************/ | 77 | #ifdef SIMULATOR /***********************************************************/ |
75 | 78 | ||
79 | #define TIME2CHANGE 10 /* change levels every 10 seconds */ | ||
80 | #define BATT_MINCVOLT 250 /* minimum centivolts of battery */ | ||
81 | #define BATT_MAXCVOLT 450 /* maximum centivolts of battery */ | ||
82 | #define BATT_MAXRUNTIME (10 * 60) /* maximum runtime with full battery in minutes */ | ||
83 | |||
84 | static unsigned int batt_centivolts = (unsigned int)BATT_MAXCVOLT; | ||
85 | static int batt_level = 100; /* battery capacity level in percent */ | ||
86 | static int batt_time = BATT_MAXRUNTIME; /* estimated remaining time in minutes */ | ||
87 | static time_t last_change = 0; | ||
88 | |||
89 | static void battery_status_update(void) | ||
90 | { | ||
91 | time_t now; | ||
92 | |||
93 | time(&now); | ||
94 | if (last_change < (now - TIME2CHANGE)) { | ||
95 | last_change = now; | ||
96 | |||
97 | /* change the values: */ | ||
98 | batt_centivolts -= (unsigned int)(BATT_MAXCVOLT - BATT_MINCVOLT) / 11; | ||
99 | if (batt_centivolts < (unsigned int)BATT_MINCVOLT) | ||
100 | batt_centivolts = (unsigned int)BATT_MAXCVOLT; | ||
101 | |||
102 | batt_level = 100 * (batt_centivolts - BATT_MINCVOLT) / (BATT_MAXCVOLT - BATT_MINCVOLT); | ||
103 | batt_time = batt_level * BATT_MAXRUNTIME / 100; | ||
104 | } | ||
105 | } | ||
106 | |||
76 | unsigned int battery_voltage(void) | 107 | unsigned int battery_voltage(void) |
77 | { | 108 | { |
78 | return 400; | 109 | battery_status_update(); |
110 | return batt_centivolts; | ||
79 | } | 111 | } |
80 | 112 | ||
81 | int battery_level(void) | 113 | int battery_level(void) |
82 | { | 114 | { |
83 | return 75; | 115 | battery_status_update(); |
116 | return batt_level; | ||
84 | } | 117 | } |
85 | 118 | ||
86 | int battery_time(void) | 119 | int battery_time(void) |
87 | { | 120 | { |
88 | return 500; | 121 | battery_status_update(); |
122 | return batt_time; | ||
89 | } | 123 | } |
90 | 124 | ||
91 | bool battery_level_safe(void) | 125 | bool battery_level_safe(void) |