added battery interface
This commit is contained in:
parent
3206f285ba
commit
dc8ad5c03a
@ -32,8 +32,7 @@ DevicePluginSenic::DevicePluginSenic()
|
|||||||
|
|
||||||
void DevicePluginSenic::init()
|
void DevicePluginSenic::init()
|
||||||
{
|
{
|
||||||
m_reconnectTimer = hardwareManager()->pluginTimerManager()->registerTimer(10);
|
|
||||||
connect(m_reconnectTimer, &PluginTimer::timeout, this, &DevicePluginSenic::onReconnectTimeout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::DeviceError DevicePluginSenic::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
Device::DeviceError DevicePluginSenic::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||||
@ -57,11 +56,15 @@ Device::DeviceError DevicePluginSenic::discoverDevices(const DeviceClassId &devi
|
|||||||
|
|
||||||
Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device)
|
Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device)
|
||||||
{
|
{
|
||||||
|
if (!m_reconnectTimer) {
|
||||||
|
m_reconnectTimer = hardwareManager()->pluginTimerManager()->registerTimer(10);
|
||||||
|
connect(m_reconnectTimer, &PluginTimer::timeout, this, &DevicePluginSenic::onReconnectTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
qCDebug(dcSenic()) << "Setup device" << device->name() << device->params();
|
qCDebug(dcSenic()) << "Setup device" << device->name() << device->params();
|
||||||
|
|
||||||
QString name = device->paramValue(nuimoDeviceNameParamTypeId).toString();
|
|
||||||
QBluetoothAddress address = QBluetoothAddress(device->paramValue(nuimoDeviceMacParamTypeId).toString());
|
QBluetoothAddress address = QBluetoothAddress(device->paramValue(nuimoDeviceMacParamTypeId).toString());
|
||||||
QBluetoothDeviceInfo deviceInfo = QBluetoothDeviceInfo(address, name, 0);
|
QBluetoothDeviceInfo deviceInfo = QBluetoothDeviceInfo(address, device->name(), 0);
|
||||||
|
|
||||||
BluetoothLowEnergyDevice *bluetoothDevice = hardwareManager()->bluetoothLowEnergyManager()->registerDevice(deviceInfo, QLowEnergyController::RandomAddress);
|
BluetoothLowEnergyDevice *bluetoothDevice = hardwareManager()->bluetoothLowEnergyManager()->registerDevice(deviceInfo, QLowEnergyController::RandomAddress);
|
||||||
|
|
||||||
@ -104,7 +107,7 @@ Device::DeviceError DevicePluginSenic::executeAction(Device *device, const Actio
|
|||||||
if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Stop")
|
if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Stop")
|
||||||
nuimo->showImage(Nuimo::MatrixTypeStop);
|
nuimo->showImage(Nuimo::MatrixTypeStop);
|
||||||
if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Music")
|
if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Music")
|
||||||
nuimo->showImage(Nuimo::MatrixTypeStop);
|
nuimo->showImage(Nuimo::MatrixTypeMusic);
|
||||||
if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Heart")
|
if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Heart")
|
||||||
nuimo->showImage(Nuimo::MatrixTypeHeart);
|
nuimo->showImage(Nuimo::MatrixTypeHeart);
|
||||||
|
|
||||||
@ -122,6 +125,11 @@ void DevicePluginSenic::deviceRemoved(Device *device)
|
|||||||
Nuimo *nuimo = m_nuimos.key(device);
|
Nuimo *nuimo = m_nuimos.key(device);
|
||||||
m_nuimos.take(nuimo);
|
m_nuimos.take(nuimo);
|
||||||
delete nuimo;
|
delete nuimo;
|
||||||
|
|
||||||
|
if (myDevices().isEmpty()) {
|
||||||
|
hardwareManager()->pluginTimerManager()->unregisterTimer(m_reconnectTimer);
|
||||||
|
m_reconnectTimer = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicePluginSenic::verifyExistingDevices(const QBluetoothDeviceInfo &deviceInfo)
|
bool DevicePluginSenic::verifyExistingDevices(const QBluetoothDeviceInfo &deviceInfo)
|
||||||
@ -158,9 +166,8 @@ void DevicePluginSenic::onBluetoothDiscoveryFinished()
|
|||||||
foreach (const QBluetoothDeviceInfo &deviceInfo, reply->discoveredDevices()) {
|
foreach (const QBluetoothDeviceInfo &deviceInfo, reply->discoveredDevices()) {
|
||||||
if (deviceInfo.name().contains("Nuimo")) {
|
if (deviceInfo.name().contains("Nuimo")) {
|
||||||
if (!verifyExistingDevices(deviceInfo)) {
|
if (!verifyExistingDevices(deviceInfo)) {
|
||||||
DeviceDescriptor descriptor(nuimoDeviceClassId, "Nuimo", deviceInfo.address().toString());
|
DeviceDescriptor descriptor(nuimoDeviceClassId, "Nuimo", deviceInfo.name() + " (" + deviceInfo.address().toString() + ")");
|
||||||
ParamList params;
|
ParamList params;
|
||||||
params.append(Param(nuimoDeviceNameParamTypeId, deviceInfo.name()));
|
|
||||||
params.append(Param(nuimoDeviceMacParamTypeId, deviceInfo.address().toString()));
|
params.append(Param(nuimoDeviceMacParamTypeId, deviceInfo.address().toString()));
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
deviceDescriptors.append(descriptor);
|
deviceDescriptors.append(descriptor);
|
||||||
@ -212,5 +219,3 @@ void DevicePluginSenic::onRotationValueChanged(const uint &value)
|
|||||||
Device *device = m_nuimos.value(nuimo);
|
Device *device = m_nuimos.value(nuimo);
|
||||||
device->setStateValue(nuimoRotationStateTypeId, value);
|
device->setStateValue(nuimoRotationStateTypeId, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -13,15 +13,8 @@
|
|||||||
"name": "nuimo",
|
"name": "nuimo",
|
||||||
"displayName": "Nuimo",
|
"displayName": "Nuimo",
|
||||||
"createMethods": ["discovery"],
|
"createMethods": ["discovery"],
|
||||||
"interfaces": [ "simplemultibutton", "connectable"],
|
"interfaces": ["batterylevel", "simplemultibutton", "connectable"],
|
||||||
"paramTypes": [
|
"paramTypes": [
|
||||||
{
|
|
||||||
"id": "db67d1e6-26fa-44ed-ad55-c6aef45ea2ea",
|
|
||||||
"name": "name",
|
|
||||||
"displayName": "name",
|
|
||||||
"type": "QString",
|
|
||||||
"inputType": "TextLine"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"id": "71553f6a-2ed4-4896-bb7b-52e7dca948b2",
|
"id": "71553f6a-2ed4-4896-bb7b-52e7dca948b2",
|
||||||
"name": "mac",
|
"name": "mac",
|
||||||
@ -63,11 +56,19 @@
|
|||||||
"type": "QString",
|
"type": "QString",
|
||||||
"defaultValue": "-"
|
"defaultValue": "-"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "aabd660f-b0c5-49f6-b7b0-6ba8e0a8cfcd",
|
||||||
|
"name": "batteryCritical",
|
||||||
|
"displayName": "Battery critical",
|
||||||
|
"displayNameEvent": "Battery critical changed",
|
||||||
|
"type": "bool",
|
||||||
|
"defaultValue": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "b5ee2465-7fa1-450b-8073-f115537d3409",
|
"id": "b5ee2465-7fa1-450b-8073-f115537d3409",
|
||||||
"name": "battery",
|
"name": "batteryLevel",
|
||||||
"displayName": "battery",
|
"displayName": "Battery",
|
||||||
"displayNameEvent": "battery changed",
|
"displayNameEvent": "Battery changed",
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"minValue": 0,
|
"minValue": 0,
|
||||||
"maxValue": 100,
|
"maxValue": 100,
|
||||||
|
|||||||
@ -224,7 +224,12 @@ void Nuimo::setBatteryValue(const QByteArray &data)
|
|||||||
int batteryPercentage = data.toHex().toUInt(0, 16);
|
int batteryPercentage = data.toHex().toUInt(0, 16);
|
||||||
qCDebug(dcSenic()) << "Battery:" << batteryPercentage << "%";
|
qCDebug(dcSenic()) << "Battery:" << batteryPercentage << "%";
|
||||||
|
|
||||||
device()->setStateValue(nuimoBatteryStateTypeId, batteryPercentage);
|
device()->setStateValue(nuimoBatteryLevelStateTypeId, batteryPercentage);
|
||||||
|
if (batteryPercentage < 20) {
|
||||||
|
device()->setStateValue(nuimoBatteryCriticalStateTypeId, true);
|
||||||
|
} else {
|
||||||
|
device()->setStateValue(nuimoBatteryCriticalStateTypeId, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Nuimo::onConnectedChanged(const bool &connected)
|
void Nuimo::onConnectedChanged(const bool &connected)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user