diff options
Diffstat (limited to 'uisimulator/common')
-rw-r--r-- | uisimulator/common/filesystem-sim.c | 2 | ||||
-rw-r--r-- | uisimulator/common/powermgmt-sim.c | 56 | ||||
-rw-r--r-- | uisimulator/common/sim_tasks.c | 11 |
3 files changed, 51 insertions, 18 deletions
diff --git a/uisimulator/common/filesystem-sim.c b/uisimulator/common/filesystem-sim.c index 8d7fb14931..0a5df0c742 100644 --- a/uisimulator/common/filesystem-sim.c +++ b/uisimulator/common/filesystem-sim.c @@ -309,6 +309,8 @@ int sim_get_os_path(char *buffer, const char *path, size_t bufsize) const char *next; volume = path_strip_volume(p, &next, true); + if (volume == ROOT_VOLUME) + volume = 0; /* FIXME: root no longer implies volume 0 */ if (next > p) { diff --git a/uisimulator/common/powermgmt-sim.c b/uisimulator/common/powermgmt-sim.c index 511648bc9d..1535971e29 100644 --- a/uisimulator/common/powermgmt-sim.c +++ b/uisimulator/common/powermgmt-sim.c @@ -39,9 +39,11 @@ #define POWER_AFTER_CHARGE_TICKS (8 * HZ) #endif -extern int battery_percent; static bool charging = false; -static unsigned int battery_millivolts = BATT_MAXMVOLT; +static unsigned int batt_millivolts = BATT_MAXMVOLT; +static unsigned int batt_percent = 100; +static unsigned int batt_runtime = BATT_MAXRUNTIME; +static unsigned int batt_current = 0; void powermgmt_init_target(void) {} @@ -54,7 +56,7 @@ static void battery_status_update(void) static unsigned int ext_power_until_tick = 0; #endif - if TIME_BEFORE(current_tick, update_after_tick) + if(TIME_BEFORE(current_tick, update_after_tick)) return; update_after_tick = current_tick + HZ; @@ -72,10 +74,9 @@ static void battery_status_update(void) #endif if (charging) { - battery_millivolts += BATT_CHARGE_STEP; - if (battery_millivolts >= BATT_MAXMVOLT) { + batt_millivolts += BATT_CHARGE_STEP; + if (batt_millivolts >= BATT_MAXMVOLT) { charging = false; - battery_percent = 100; #if CONFIG_CHARGING >= CHARGING_MONITOR /* Keep external power until tick */ ext_power_until_tick = current_tick + POWER_AFTER_CHARGE_TICKS; @@ -83,23 +84,22 @@ static void battery_status_update(void) /* Pretend the charger was disconnected */ charger_input_state = CHARGER_UNPLUGGED; #endif - return; } } else { - battery_millivolts -= BATT_DISCHARGE_STEP; - if (battery_millivolts <= BATT_MINMVOLT) { + batt_millivolts -= BATT_DISCHARGE_STEP; + if (batt_millivolts <= BATT_MINMVOLT) { charging = true; - battery_percent = 0; #if CONFIG_CHARGING /* Pretend the charger was connected */ charger_input_state = CHARGER_PLUGGED; #endif - return; } } - battery_percent = 100 * (battery_millivolts - BATT_MINMVOLT) / - (BATT_MAXMVOLT - BATT_MINMVOLT); + batt_percent = (batt_millivolts - BATT_MINMVOLT) / (BATT_MAXMVOLT - BATT_MINMVOLT); + batt_runtime = batt_percent * BATT_MAXRUNTIME; + /* current is completely bogus... */ + batt_current = charging ? BATT_CHARGE_STEP : BATT_DISCHARGE_STEP; } const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = { 3200 }; @@ -111,15 +111,36 @@ const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = const unsigned short percent_to_volt_charge[11] = { 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300 }; +#if CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE int _battery_voltage(void) { battery_status_update(); - return battery_millivolts; + return batt_millivolts; } +#endif + +#if CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE +int _battery_level(void) +{ + battery_status_update(); + return batt_percent; +} +#endif #if (CONFIG_BATTERY_MEASURE & TIME_MEASURE) -static int powermgmt_est_runningtime_min; -int _battery_time(void) { return powermgmt_est_runningtime_min; } +int _battery_time(void) +{ + battery_status_update(); + return batt_runtime; +} +#endif + +#if (CONFIG_BATTERY_MEASURE & CURRENT_MEASURE) +int _battery_current(void) +{ + battery_status_update(); + return batt_current; +} #endif #if CONFIG_CHARGING @@ -169,6 +190,7 @@ unsigned int input_millivolts(void) /* Just return a safe value if battery isn't connected */ return 4050; } - return battery_voltage();; + + return battery_voltage(); } #endif diff --git a/uisimulator/common/sim_tasks.c b/uisimulator/common/sim_tasks.c index c862d4d909..c53b9990fd 100644 --- a/uisimulator/common/sim_tasks.c +++ b/uisimulator/common/sim_tasks.c @@ -92,7 +92,9 @@ void sim_thread(void) last_broadcast_tick = current_tick; } - num_acks_to_expect += queue_broadcast(SYS_USB_CONNECTED, 0) - 1; + /* NOTE: Unlike the USB code, we do not subtract one here + * because the sim_queue is not registered for broadcasts! */ + num_acks_to_expect += queue_broadcast(SYS_USB_CONNECTED, 0); DEBUGF("USB inserted. Waiting for %d acks...\n", num_acks_to_expect); break; @@ -145,10 +147,17 @@ void sim_trigger_screendump(void) static bool is_usb_inserted; void sim_trigger_usb(bool inserted) { + int usbmode = -1; if (inserted) + { + send_event(SYS_EVENT_USB_INSERTED, &usbmode); queue_post(&sim_queue, SIM_USB_INSERTED, 0); + } else + { + send_event(SYS_EVENT_USB_EXTRACTED, NULL); queue_post(&sim_queue, SIM_USB_EXTRACTED, 0); + } is_usb_inserted = inserted; } |