Skip to content

Commit

Permalink
Add Skydimo "support"
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Nov 1, 2024
1 parent af160dc commit 247b359
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
22 changes: 22 additions & 0 deletions include/led-drivers/serial/DriverSerialSkydimo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "ProviderSerial.h"

class DriverSerialSkydimo : public ProviderSerial
{
Q_OBJECT

public:
explicit DriverSerialSkydimo(const QJsonObject& deviceConfig);
static LedDevice* construct(const QJsonObject& deviceConfig);

private:
bool init(const QJsonObject& deviceConfig) override;
void CreateHeader();
int write(const std::vector<ColorRgb>& ledValues) override;

const short _headerSize;


static bool isRegistered;
};
1 change: 1 addition & 0 deletions sources/led-drivers/LedDeviceSchemas.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<file alias="schema-sk6812spi">schemas/schema-sk6812spi.json</file>
<file alias="schema-sk6822spi">schemas/schema-sk6822spi.json</file>
<file alias="schema-sk9822">schemas/schema-sk9822.json</file>
<file alias="schema-skydimo">schemas/schema-skydimo.json</file>
<file alias="schema-hd108">schemas/schema-hd108.json</file>
<file alias="schema-tinkerforge">schemas/schema-tinkerforge.json</file>
<file alias="schema-tpm2net">schemas/schema-tpm2net.json</file>
Expand Down
25 changes: 25 additions & 0 deletions sources/led-drivers/schemas/schema-skydimo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type":"object",
"required":true,
"properties":{
"output": {
"type": "string",
"title":"edt_dev_spec_outputPath_title",
"default":"ttyACM0",
"propertyOrder" : 1
},
"rate": {
"type": "integer",
"title":"edt_dev_spec_baudrate_title",
"default": 1000000,
"propertyOrder" : 2
},
"delayAfterConnect": {
"type": "integer",
"title":"edt_dev_spec_delayAfterConnect_title",
"default": 250,
"propertyOrder" : 3
}
},
"additionalProperties": true
}
76 changes: 76 additions & 0 deletions sources/led-drivers/serial/DriverSerialSkydimo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <led-drivers/serial/DriverSerialSkydimo.h>
#include <QtEndian>

#include <cassert>

DriverSerialSkydimo::DriverSerialSkydimo(const QJsonObject& deviceConfig)
: ProviderSerial(deviceConfig)
, _headerSize(6)
{
}

LedDevice* DriverSerialSkydimo::construct(const QJsonObject& deviceConfig)
{
return new DriverSerialSkydimo(deviceConfig);
}

bool DriverSerialSkydimo::init(const QJsonObject& deviceConfig)
{
bool isInitOK = false;

// Initialise sub-class
if (ProviderSerial::init(deviceConfig))
{
CreateHeader();

isInitOK = true;
}
return isInitOK;
}

void DriverSerialSkydimo::CreateHeader()
{
auto finalSize = (uint64_t)_headerSize + _ledRGBCount;
_ledBuffer.resize(finalSize, 0x00);

_ledBuffer[0] = 'A';
_ledBuffer[1] = 'd';
_ledBuffer[2] = 'a';
_ledBuffer[3] = 0;
_ledBuffer[4] = 0;
_ledBuffer[5] = std::min(_ledCount, 255u);

Debug(_log, "Skydimo header for %d leds: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x", _ledCount,
_ledBuffer[0], _ledBuffer[1], _ledBuffer[2], _ledBuffer[3], _ledBuffer[4], _ledBuffer[5]);
}

int DriverSerialSkydimo::write(const std::vector<ColorRgb>& ledValues)
{
if (_ledCount != ledValues.size())
{
Warning(_log, "Skydimo led count has changed (old: %d, new: %d). Rebuilding header.", _ledCount, ledValues.size());
_ledCount = (uint)ledValues.size();
_ledRGBCount = _ledCount * 3;
CreateHeader();
}

auto bufferLength = _headerSize + ledValues.size() * sizeof(ColorRgb);

if (bufferLength > _ledBuffer.size())
{
Warning(_log, "Skydimo buffer's size has changed. Skipping refresh.");
return 0;
}

uint8_t* writer = _ledBuffer.data() + _headerSize;

memcpy(writer, ledValues.data(), ledValues.size() * sizeof(ColorRgb));
writer += ledValues.size() * sizeof(ColorRgb);

bufferLength = writer - _ledBuffer.data();

return writeBytes(bufferLength, _ledBuffer.data());
}


bool DriverSerialSkydimo::isRegistered = hyperhdr::leds::REGISTER_LED_DEVICE("skydimo", "leds_group_3_serial", DriverSerialSkydimo::construct);
4 changes: 2 additions & 2 deletions www/js/light_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ $(document).ready(function()
const wizardFn = 'startWizard' + ledType.charAt(0).toUpperCase() + ledType.slice(1);
changeWizard(data, wizardTitle, window[wizardFn]);
}
else if (ledType == "wled" || selectedLedGroup == "leds_group_0_SPI" || selectedLedGroup == "leds_group_4_serial")
else if (ledType == "wled" || selectedLedGroup == "leds_group_0_SPI" || selectedLedGroup == "leds_group_3_serial")
{
let selectorControl = $("<select id=\"deviceListInstances\" />");
let targetControl = 'output';
Expand All @@ -880,7 +880,7 @@ $(document).ready(function()
requestLedDeviceDiscovery(ledType).then( (result) => deviceListRefresh(ledType, result, 'root.specificOptions.host','select_wled_intro','select_wled_rescan'));
targetControl = 'host';
}
else if (selectedLedGroup == "leds_group_4_serial")
else if (selectedLedGroup == "leds_group_3_serial")
requestLedDeviceDiscovery(ledType).then( (result) => deviceListRefresh(ledType, result, 'root.specificOptions.output','edt_dev_spec_outputPath_title'));
else if (selectedLedGroup == "leds_group_0_SPI")
requestLedDeviceDiscovery(ledType).then( (result) => deviceListRefresh(ledType, result, 'root.specificOptions.output', 'edt_dev_spec_spipath_title'));
Expand Down

0 comments on commit 247b359

Please sign in to comment.