#include "toolbox.h"
#include "portable.h"

#include "rc5wimp.h"
#include "task.h"
#include "power.h"

enum power_state
{
    Unknown,
    Battery,
    Mains
} power;

void check_mains_power()
{
    enum power_state old_power = power;
    portable_bmu_flags flags;

    if (xportable_read_bmu_variable(portable_BMU_VARIABLE_FLAGS, (int *) &flags))
    	return;

    power = flags & portable_BMU_CHARGER_CONNECTED ? Mains : Battery;

    if (power != old_power)
    {
        if (power == Mains)
            client_unpause();
        else
            client_pause();
    }
}
