Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Dec 19, 2024
1 parent 0ec6efd commit 17ac2fe
Showing 1 changed file with 44 additions and 29 deletions.
73 changes: 44 additions & 29 deletions js/ChromalinkPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,52 +88,67 @@ export default class ChromalinkPanel extends Panel {

async connect() {
try {
// Use the connect function from VortexPort
this.duoHeader = await this.vortexPort.connectChromalink(this.editor.vortexLib);
if (!this.duoHeader) {
throw new Error('Failed to read Duo save header');
}

this.isConnected = true;
this.updateUIAfterConnect();
Notification.success(`Successfully Chromalinked Duo v${this.duoHeader.version}`);
await this.editor.checkVersion('Duo', this.duoHeader.version);
const connectButton = document.getElementById('chromalinkConnect');
connectButton.innerHTML = 'Disconnect Duo'
this.oldModes = new this.editor.vortexLib.ByteStream();
if (!this.editor.lightshow.vortex.getModes(this.oldModes)) {
throw new Error('Failed to backup old modes');
}
this.editor.lightshow.vortex.clearModes();
this.editor.lightshow.setLedCount(2);
this.modesPanel.updateSelectedDevice('Duo', true);
//this.modesPanel.renderLedIndicators('Duo');
this.modesPanel.selectAllLeds();
// update ui
document.getElementById('duoIcon').style.display = 'block';
document.getElementById('duoInfo').style.display = 'block';
document.getElementById('duoVersion').textContent = this.duoHeader.version;
document.getElementById('duoModes').textContent = this.duoHeader.numModes;
const flashButton = document.getElementById('chromalinkFlash');
const updateButton = document.getElementById('chromalinkUpdate');
flashButton.disabled = false;
updateButton.disabled = false;
// give a notification
Notification.success('Successfully Chromalinked Duo v' + this.duoHeader.version);
} catch (error) {
Notification.failure('Failed to connect: ' + error.message);
}
}

async disconnect() {
try {
// Use the connect function from VortexPort
const connectButton = document.getElementById('chromalinkConnect');
connectButton.innerHTML = 'Connect Duo'
this.isConnected = false;
this.updateUIAfterDisconnect();
this.editor.lightshow.vortex.clearModes();
this.editor.lightshow.setLedCount(20);
if (!this.editor.lightshow.vortex.setModes(this.oldModes, false)) {
throw new Error('Failed to restore old modes');
}
this.oldModes = null;
this.modesPanel.updateSelectedDevice('Chromadeck', true);
this.modesPanel.renderLedIndicators('Chromadeck');
this.modesPanel.selectAllLeds();
const flashButton = document.getElementById('chromalinkFlash');
const updateButton = document.getElementById('chromalinkUpdate');
flashButton.disabled = true;
updateButton.disabled = true;
document.getElementById('duoIcon').style.display = 'none';
document.getElementById('duoInfo').style.display = 'none';
Notification.success('Successfully Disconnected Chromalink');
} catch (error) {
Notification.failure('Failed to disconnect: ' + error.message);
Notification.failure('Failed to connect: ' + error.message);
}
}

updateUIAfterConnect() {
const connectButton = document.getElementById('chromalinkConnect');
const chromalinkDetails = document.getElementById('chromalinkDetails');
connectButton.textContent = 'Disconnect Duo';

document.getElementById('duoVersion').textContent = this.duoHeader.version;
document.getElementById('duoModes').textContent = this.duoHeader.numModes;

chromalinkDetails.style.display = 'block';
document.getElementById('chromalinkFlash').disabled = false;
document.getElementById('chromalinkUpdate').disabled = false;
}

updateUIAfterDisconnect() {
const connectButton = document.getElementById('chromalinkConnect');
const chromalinkDetails = document.getElementById('chromalinkDetails');
connectButton.textContent = 'Connect Duo';

chromalinkDetails.style.display = 'none';
document.getElementById('chromalinkFlash').disabled = true;
document.getElementById('chromalinkUpdate').disabled = true;
}

async updateFirmware() {
const progressBar = document.getElementById('firmwareProgressBar');
try {
Expand Down

0 comments on commit 17ac2fe

Please sign in to comment.