/*
 * This function does the initialization and signal connection to QmBattery and
 * QmDeviceMode, and emits all the signals with the current values...
 *
 * FIXME: This function should be called realize() or something...
 */
void
BatteryBusinessLogic::requestValues ()
{
    DEBUG_CLOCK_START;
    if (m_initialized)
        return;

    m_initialized = true;

    #ifdef HAVE_QMSYSTEM
    SYS_DEBUG ("Connecting to the signals of the QmBattery class");
    connect (
        m_battery, SIGNAL(chargerEvent(MeeGo::QmBattery::ChargerType)),
        this, SLOT(batteryChargerEvent(MeeGo::QmBattery::ChargerType)));
    connect (
        m_battery, SIGNAL(chargingStateChanged(MeeGo::QmBattery::ChargingState)),
        this, SLOT(chargingStateChanged(MeeGo::QmBattery::ChargingState)));
    connect (
        m_battery, SIGNAL(batteryStateChanged(MeeGo::QmBattery::BatteryState)),
        this, SLOT (batteryStateChanged(MeeGo::QmBattery::BatteryState)));

    /*
     * We have two signals showing that the battery energy level has been
     * changed. We listen both of these signals.
     */
    SYS_DEBUG ("Connecting to the signals of the QmBattery class");
    connect (m_battery, SIGNAL (batteryRemainingCapacityChanged (int, int)),
            this, SLOT (batteryRemCapacityChanged (int, int)));


    // batteryBarValueReceived also emitted by chargingStateChanged ^^^
    // FIXME: Why?

    /*
     * Init the power-save-mode value, and connect to QmSystem2 signal
     */
    m_PowerSaveMode = (m_devicemode->getPSMState () ==
                       MeeGo::QmDeviceMode::PSMStateOn);
    connect (m_devicemode,
             SIGNAL (devicePSMStateChanged (MeeGo::QmDeviceMode::PSMState)),
             this, SLOT (PSMStateChanged (MeeGo::QmDeviceMode::PSMState)));
    #else
    /*
     * FIXME: To create an implementation without the QmSystem
     */
    #endif

    recalculateChargingInfo ();
    DEBUG_CLOCK_END("Data request");
}
/*
 * This function does the initialization and signal connection to QmBattery and
 * QmDeviceMode, and emits all the signals with the current values...
 *
 * FIXME: This function should be called realize() or something...
 */
void
BatteryBusinessLogic::requestValues ()
{
    if (m_initialized)
        return;

    m_initialized = true;

    #ifdef HAVE_QMSYSTEM
    SYS_DEBUG ("Connecting to the signals of the QmBattery class");
    connect (
        m_battery, SIGNAL(chargerEvent(MeeGo::QmBattery::ChargerType)),
        this, SLOT(batteryChargerEvent(MeeGo::QmBattery::ChargerType)));
    connect (
        m_battery, SIGNAL(chargingStateChanged(MeeGo::QmBattery::ChargingState)),
        this, SLOT(chargingStateChanged(MeeGo::QmBattery::ChargingState)));
    connect (
        m_battery, SIGNAL(batteryStateChanged(MeeGo::QmBattery::BatteryState)),
        this, SLOT (batteryStateChanged(MeeGo::QmBattery::BatteryState)));

    // This will emit the batteryCharging signal,
    // and the remainingTimeValuesChanged signal
    chargingStateChanged (m_battery->getChargingState ());

    /*
     * We have two signals showing that the battery energy level has been
     * changed. We listen both of these signals.
     */
    SYS_DEBUG ("Connecting to the signals of the QmBattery class");
    connect (m_battery, SIGNAL (batteryRemainingCapacityChanged (int, int)),
            this, SLOT (batteryRemCapacityChanged (int, int)));


    // batteryBarValueReceived also emitted by chargingStateChanged ^^^
    // FIXME: Why?
    connect (m_devicemode,
             SIGNAL (devicePSMStateChanged (MeeGo::QmDeviceMode::PSMState)),
             this, SLOT (PSMStateChanged (MeeGo::QmDeviceMode::PSMState)));

    SYS_DEBUG ("Emitting PSMValueReceived(%s)",
            SYS_BOOL(m_devicemode->getPSMState () == QmDeviceMode::PSMStateOn));
    emit PSMValueReceived (m_devicemode->getPSMState () ==
                           QmDeviceMode::PSMStateOn);
    #else
    /*
     * FIXME: To create an implementation without the QmSystem
     */
    #endif
}
void FakeQWidgetWinAPI::prepareBatteryStateChange (PPOWERBROADCAST_SETTING setting)
{
    const int nPercentLeft =
        *reinterpret_cast<int*> (reinterpret_cast<DWORD_PTR> (setting->Data));

    emit batteryStateChanged (nPercentLeft);
}
//this function is called when a command has been received from the drone:
void commandReceived(eARCONTROLLER_DICTIONARY_KEY commandKey,
			ARCONTROLLER_DICTIONARY_ELEMENT_t *elementDictionary,
			void *customData)
{

		ARCONTROLLER_Device_t *deviceController = customData;
		eARCONTROLLER_ERROR error = ARCONTROLLER_OK;

		if (deviceController != NULL) {

			//if the command received is a battery state changed
			if (commandKey
					== ARCONTROLLER_DICTIONARY_KEY_COMMON_COMMONSTATE_BATTERYSTATECHANGED) {
				ARCONTROLLER_DICTIONARY_ARG_t *arg = NULL;
				ARCONTROLLER_DICTIONARY_ELEMENT_t *singleElement =
				NULL;

				if (elementDictionary != NULL) {
					//get the command received in the device controller
					HASH_FIND_STR(elementDictionary,
					ARCONTROLLER_DICTIONARY_SINGLE_KEY,
							singleElement);

					if (singleElement != NULL) {
						//get the value
						HASH_FIND_STR(singleElement->arguments,
								ARCONTROLLER_DICTIONARY_KEY_COMMON_COMMONSTATE_BATTERYSTATECHANGED_PERCENT,
								arg);

						if (arg != NULL) {
							//update UI
							batteryStateChanged(arg->value.U8);
						} else {
							ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG,
									"arg is NULL");
						}
					} else {
						ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG,
								"singleElement is NULL");
					}
				}
			} else {
				ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG,
						"elements is NULL");
			}
		}
}
Beispiel #5
0
BatteryNotifier::BatteryNotifier(QObject *parent) :
    QObject(parent), lowBatteryNotifier(0), notificationId(0), touchScreenLockActive(false)
    ,qmBattery(new MeeGo::QmBattery),
    qmDeviceMode(new MeeGo::QmDeviceMode),
    qmLed(new MeeGo::QmLED),
    chargerType(MeeGo::QmBattery::Unknown)
{
    connect(qmBattery, SIGNAL(batteryStateChanged(MeeGo::QmBattery::BatteryState)), this, SLOT(batteryStateChanged(MeeGo::QmBattery::BatteryState)));
    connect(qmBattery, SIGNAL(chargingStateChanged(MeeGo::QmBattery::ChargingState)), this, SLOT(chargingStateChanged(MeeGo::QmBattery::ChargingState)));
    connect(qmBattery, SIGNAL(chargerEvent(MeeGo::QmBattery::ChargerType)), this, SLOT(batteryChargerEvent(MeeGo::QmBattery::ChargerType)));

    connect(qmDeviceMode, SIGNAL(devicePSMStateChanged(MeeGo::QmDeviceMode::PSMState)), this, SLOT(devicePSMStateChanged(MeeGo::QmDeviceMode::PSMState)));

    // Init battery values delayed...
    initBattery();

    notificationTimer.setInterval(5000);
    notificationTimer.setSingleShot(true);
}
// called when a command has been received from the drone
void commandReceived (eARCONTROLLER_DICTIONARY_KEY commandKey, ARCONTROLLER_DICTIONARY_ELEMENT_t *elementDictionary, void *customData)
{
    ARCONTROLLER_Device_t *deviceController = customData;
    eARCONTROLLER_ERROR error = ARCONTROLLER_OK;
    
    if (deviceController != NULL)
    {
        // if the command received is a battery state changed
        if (commandKey == ARCONTROLLER_DICTIONARY_KEY_COMMON_COMMONSTATE_BATTERYSTATECHANGED)
        {
            ARCONTROLLER_DICTIONARY_ARG_t *arg = NULL;
            ARCONTROLLER_DICTIONARY_ELEMENT_t *singleElement = NULL;
            
            if (elementDictionary != NULL)
            {
                // get the command received in the device controller
                HASH_FIND_STR (elementDictionary, ARCONTROLLER_DICTIONARY_SINGLE_KEY, singleElement);
                
                if (singleElement != NULL)
                {
                    // get the value
                    HASH_FIND_STR (singleElement->arguments, ARCONTROLLER_DICTIONARY_KEY_COMMON_COMMONSTATE_BATTERYSTATECHANGED_PERCENT, arg);
                    
                    if (arg != NULL)
                    {
                        // update UI
                        batteryStateChanged (arg->value.U8);
                    }
                    else
                    {
                        ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "arg is NULL");
                    }
                }
                else
                {
                    ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "singleElement is NULL");
                }
            }
            else
            {
                ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "elements is NULL");
            }
        }
    }

    if (commandKey == ARCONTROLLER_DICTIONARY_KEY_COMMON_COMMONSTATE_SENSORSSTATESLISTCHANGED)
    {
        ARCONTROLLER_DICTIONARY_ARG_t *arg = NULL;
        
        if (elementDictionary != NULL)
        {
            ARCONTROLLER_DICTIONARY_ELEMENT_t *dictElement = NULL;
            ARCONTROLLER_DICTIONARY_ELEMENT_t *dictTmp = NULL;
            
            eARCOMMANDS_COMMON_COMMONSTATE_SENSORSSTATESLISTCHANGED_SENSORNAME sensorName = ARCOMMANDS_COMMON_COMMONSTATE_SENSORSSTATESLISTCHANGED_SENSORNAME_MAX;
            int sensorState = 0;
            
            HASH_ITER(hh, elementDictionary, dictElement, dictTmp)
            {
                // get the Name
                HASH_FIND_STR (dictElement->arguments, ARCONTROLLER_DICTIONARY_KEY_COMMON_COMMONSTATE_SENSORSSTATESLISTCHANGED_SENSORNAME, arg);
                if (arg != NULL)
                {
                    sensorName = arg->value.I32;
                }
                else
                {
                    ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "arg sensorName is NULL");
                }
                
                // get the state
                HASH_FIND_STR (dictElement->arguments, ARCONTROLLER_DICTIONARY_KEY_COMMON_COMMONSTATE_SENSORSSTATESLISTCHANGED_SENSORSTATE, arg);
                if (arg != NULL)
                {
                    sensorState = arg->value.U8;
                    
                    ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "sensorName %d ; sensorState: %d", sensorName, sensorState);
                }
                else
                {
                    ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "arg sensorState is NULL");
                }
            }
Beispiel #7
0
void BatteryNotifier::initBattery()
{
    chargingStateChanged(qmBattery->getChargingState());
    batteryStateChanged(qmBattery->getBatteryState());
}
void BackendInterface::setBatteryState(PowerDevil::BackendInterface::BatteryState state)
{
    d->batteryState = state;
    Q_EMIT batteryStateChanged(state);
}