Skip to content

Commit

Permalink
Added timeout to device sync.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunflowr committed Nov 20, 2019
1 parent 28ed69a commit 31b203f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
49 changes: 37 additions & 12 deletions src/components/DeviceInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
<v-card-title class="headline">
<div>RE-CPU info</div>
<v-spacer />
<v-btn color="secondary" x-small :loading="syncing" @click="syncDeviceInfo">
<v-btn
color="secondary"
x-small
:disabled="syncing"
:loading="syncing"
@click="syncDeviceInfo"
>
<v-icon left>mdi-refresh</v-icon>Sync
</v-btn>
</v-card-title>
<v-card-subtitle></v-card-subtitle>
<v-card-text>
<p>Sorry this will work properly in next version</p>
<div>{{ receiveStatus }}</div>
<div>{{ uploadStatus }}</div>
<div v-if="receiveStatus != null && receiveStatus.length > 0">{{ receiveStatus }}</div>
<div v-if="uploadStatus != null && uploadStatus.length > 0">{{ uploadStatus }}</div>
<div v-if="deviceInfo2">
<ul>
<li>Hardware id: {{ deviceInfo2.version.hwid }}</li>
<li>App Version: {{ deviceInfo2.version.major }}.{{ deviceInfo2.version.minor }}.{{ deviceInfo2.version.patch }}</li>
<li>App Name: {{ deviceInfo2.version.name }}</li>
</ul>
Expand All @@ -29,7 +33,8 @@ import { sysExUtil } from "@/plugins/sysexutil";
export default {
name: "DeviceInfo",
props: {
deviceInfo: Object
deviceInfo: Object,
info: Number
},
data() {
return {
Expand Down Expand Up @@ -73,27 +78,39 @@ export default {
syncDeviceInfo() {
this.syncing = true;
this.uploadSysEx([new Uint8Array([0x03, 0x03, 0x7c, 0x01])]);
this.uploadSysEx([
new Uint8Array([0x03, 0x03, 0x7c, (this.info & 0xff) >>> 0])
]);
const that = this;
setTimeout(() => {
if (that.syncing) {
that.receiveStatus =
"No RE-CPU detected, plesae check MIDI device settings and connection.";
that.syncing = false;
}
}, 1000);
},
uploadSysEx(sysExDataTracks) {
this.delayUploadSysEx(this.settings.uploadDelay, sysExDataTracks, 0);
},
delayUploadSysEx(delayMs, tracks, currentTrack) {
let that = this;
if (this.midiOutDevice && currentTrack < tracks.length) {
this.midiOutDevice.sendSysex(0x7d, Array.from(tracks[currentTrack]));
setTimeout(() => {
this.delayUploadSysEx(delayMs, tracks, currentTrack + 1);
that.delayUploadSysEx(delayMs, tracks, currentTrack + 1);
}, delayMs);
} else {
if (!this.midiOutDevice) {
this.uploadStatus = "No active midi output device, aborting!";
} else {
this.uploadStatus = "";
}
this.syncing = false;
}
},
onSysExReceive(e) {
this.syncing = false;
const sdata = e.data.slice(7, e.data.length - 1);
if (sdata.length % 2 != 0) {
this.receiveStatus =
Expand All @@ -115,14 +132,22 @@ export default {
this.receiveStatus = "Error when reciving, data is corrupt.";
}
this.uploadStatus = data;
//this.uploadStatus = data;
let i = 0;
const ver = {};
ver.magic =
(data[i++] << 24) | (data[i++] << 16) | (data[i++] << 8) | data[i++]; // UInt32
(data[i++] |
(data[i++] << 8) |
(data[i++] << 16) |
(data[i++] << 24)) >>>
0; // UInt32
ver.hwid =
(data[i++] << 24) | (data[i++] << 16) | (data[i++] << 8) | data[i++]; // UInt32
(data[i++] |
(data[i++] << 8) |
(data[i++] << 16) |
(data[i++] << 24)) >>>
0; // UInt32
ver.name = new TextDecoder("utf-8").decode(data.slice(i, i + 24)); // char[24]
i += 24;
ver.major = data[i++]; // UInt8
Expand Down
2 changes: 1 addition & 1 deletion src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default {
<v-container fluid>
<v-row>
<v-col cols="12">
<DeviceInfo :data="deviceInfo" />
<DeviceInfo :data="deviceInfo" :info="1" />
</v-col>
</v-row>
<v-row>
Expand Down

0 comments on commit 31b203f

Please sign in to comment.