Skip to content

Commit e3ea08d

Browse files
committed
Massive commit with far too many changes
Main changes: Mostly update to the latest UD3 version (with time syncing), make most things tslint-clean
1 parent c1e5dfd commit e3ea08d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1866
-1584
lines changed

js/gui/constants.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
hterm.defaultStorage = new lib.Storage.Memory();
2+
3+
export let terminal = new hterm.Terminal();
4+
export const MEAS_SPACE = 20;
5+
export const INFO_SPACE = 150;
6+
export const TOP_SPACE = 20;
7+
export const TRIGGER_SPACE = 10;
8+
export const CONTROL_SPACE = 15;
9+
export const MEAS_POSITION = 4;

js/gui/gauges.ts

+31-29
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,67 @@
1-
import 'justgage';
2-
import {terminal} from "./gui";
1+
import "justgage";
2+
import {terminal} from "./constants";
33

44
export class Meter {
5-
meter_buf_old: number;
6-
meter_buf: number;
7-
gauge: JustGage;
5+
private meter_buf_old: number;
6+
private meter_buf: number;
7+
private gauge: JustGage;
88

9-
constructor(id:number){
10-
this.meter_buf_old=255;
11-
this.meter_buf=0;
12-
// @ts-ignore TODO figure out how to properly fix this
13-
this.gauge= new JustGage({
14-
id: ("gauge"+id),
15-
value: 0,
16-
min: 0,
17-
max: 255,
18-
title: ("Gauge"+id)
19-
});
9+
constructor(id: number) {
10+
this.meter_buf_old = 255;
11+
this.meter_buf = 0;
12+
// @ts-ignore TODO figure out how to properly fix this
13+
this.gauge = new JustGage({
14+
id: ("gauge" + id),
15+
value: 0,
16+
// tslint:disable-next-line:object-literal-sort-keys
17+
min: 0,
18+
max: 255,
19+
title: ("Gauge" + id),
20+
});
2021
}
2122

22-
refresh(): void {
23-
if(this.meter_buf!=this.meter_buf_old){
23+
public refresh(): void {
24+
if (this.meter_buf !== this.meter_buf_old) {
2425
this.gauge.refresh(this.meter_buf);
2526
console.log("Updating value from ", this.meter_buf_old, " to ", this.meter_buf);
2627
this.meter_buf_old = this.meter_buf;
2728
}
2829
}
2930

30-
value(value: number): void {
31+
public value(value: number): void {
3132
this.meter_buf = value;
3233
}
3334

34-
text(text: string): void {
35-
this.gauge.txtLabel.attr({"text": text});
35+
public text(new_text: string): void {
36+
this.gauge.txtLabel.attr({text: new_text});
3637
}
3738

38-
range(min: number, max: number){
39-
//TODO does this work?
40-
this.gauge.refresh(min,max);
39+
public range(min: number, max: number) {
40+
// TODO does this work?
41+
this.gauge.refresh(min, max);
4142
}
4243
}
4344

4445
export const NUM_GAUGES = 7;
4546

4647

47-
export let meters:Meter[] = [];
48+
export let meters: Meter[] = [];
49+
4850
export function init(): void {
4951
for (let i = 0; i < NUM_GAUGES; ++i) {
5052
meters[i] = new Meter(i);
5153
}
5254
}
5355

5456
export function refresh_all(): void {
55-
for (let meter of meters) {
57+
for (const meter of meters) {
5658
meter.refresh();
5759
}
5860
}
5961

60-
export function getMeter(id:number): Meter {
61-
if (id>=NUM_GAUGES || id<0) {
62-
terminal.io.println("Meter "+id+" not found");
62+
export function getMeter(id: number): Meter {
63+
if (id >= NUM_GAUGES || id < 0) {
64+
terminal.io.println("Meter " + id + " not found");
6365
return undefined;
6466
}
6567
return meters[id];

js/gui/gui.ts

+24-26
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import 'electron';
2-
import * as cmd from '../network/commands';
3-
import * as scripting from '../scripting';
4-
import {setScript} from "./menu";
5-
import * as gauges from './gauges';
6-
import * as media_player from '../media/media_player';
1+
import "electron";
2+
import * as media_player from "../media/media_player";
3+
import {BootloadableConnection} from "../network/bootloadable_connection";
4+
import {loadCyacd} from "../network/bootloader/bootloader_handler";
5+
import * as cmd from "../network/commands";
6+
import {connection} from "../network/connection";
7+
import * as scripting from "../scripting";
78
import {loadSidFile} from "../sid/sid";
8-
import {loadCyacd} from "../network/bootloader";
9+
import {terminal} from "./constants";
10+
import * as gauges from "./gauges";
11+
import {setScript} from "./menu";
912

1013
export function init(): void {
11-
document.getElementById('layout').addEventListener("drop", ondrop);
12-
document.getElementById('layout').addEventListener("dragover", ondragover);
14+
document.getElementById("layout").addEventListener("drop", ondrop);
15+
document.getElementById("layout").addEventListener("dragover", ondragover);
1316

14-
terminal.onTerminalReady = function() {
17+
terminal.onTerminalReady = () => {
1518
const io = terminal.io.push();
1619

1720
terminal.processInput = cmd.sendCommand;
@@ -22,35 +25,30 @@ export function init(): void {
2225
gauges.init();
2326
}
2427

25-
hterm.defaultStorage = new lib.Storage.Memory();
26-
27-
export let terminal = new hterm.Terminal();
28-
export const MEAS_SPACE = 20;
29-
export const INFO_SPACE = 150;
30-
export const TOP_SPACE = 20;
31-
export const TRIGGER_SPACE = 10;
32-
export const CONTROL_SPACE = 15;
33-
export const MEAS_POSITION = 4;
3428

3529
async function ondrop(e: DragEvent): Promise<void> {
3630
e.stopPropagation();
3731
e.preventDefault();
38-
if (e.dataTransfer.items.length == 1) {//only one file
32+
if (e.dataTransfer.items.length === 1) {// only one file
3933
const file = e.dataTransfer.files[0];
4034
const extension = file.name.substring(file.name.lastIndexOf(".") + 1);
41-
if (extension == "js") {
35+
if (extension === "js") {
4236
scripting.loadScript(file.path)
4337
.then((script) => {
4438
setScript(script);
45-
w2ui['toolbar'].get('mnu_script').text = 'Script: ' + file.name;
46-
w2ui['toolbar'].refresh();
39+
w2ui.toolbar.get("mnu_script").text = "Script: " + file.name;
40+
w2ui.toolbar.refresh();
4741
})
4842
.catch((err) => {
4943
terminal.io.println("Failed to load script: " + err);
5044
console.log(err);
5145
});
52-
} else if (extension=="cyacd") {
53-
loadCyacd(file);
46+
} else if (extension === "cyacd") {
47+
if (connection instanceof BootloadableConnection) {
48+
await loadCyacd(file, connection);
49+
} else {
50+
terminal.io.println("Connection does not support bootloading");
51+
}
5452
} else {
5553
await media_player.loadMediaFile(file.path);
5654
}
@@ -60,5 +58,5 @@ async function ondrop(e: DragEvent): Promise<void> {
6058
function ondragover(e: DragEvent): void {
6159
e.stopPropagation();
6260
e.preventDefault();
63-
e.dataTransfer.dropEffect = 'copy';
61+
e.dataTransfer.dropEffect = "copy";
6462
}

js/gui/menu.ts

+46-46
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,102 @@
1-
import {terminal} from "./gui";
2-
import {busActive, busControllable, ConnectionState, transientActive} from "../network/telemetry";
3-
import * as commands from '../network/commands';
4-
import * as connection from '../network/connection';
5-
import * as helper from '../helper';
6-
import * as sliders from './sliders';
7-
import * as scripting from '../scripting';
8-
import * as midiServer from '../midi/midi_server';
9-
import * as ui_helper from './ui_helper';
1+
import * as helper from "../helper";
102
import * as media_player from "../media/media_player";
3+
import * as midiServer from "../midi/midi_server";
4+
import * as commands from "../network/commands";
5+
import * as connection from "../network/connection";
6+
import {busActive, busControllable, transientActive} from "../network/telemetry";
7+
import * as scripting from "../scripting";
8+
import {terminal} from "./constants";
9+
import * as sliders from "./sliders";
10+
import * as ui_helper from "./ui_helper";
1111

1212
export function init() {
13-
const port = $('#toolbar #tb_toolbar_item_port');
13+
const port = $("#toolbar #tb_toolbar_item_port");
1414
port.on("keypress", (e) => {
1515
console.log(e);
16-
if (e.originalEvent.key == "Enter") {
17-
w2ui.toolbar.set('port', {value: this.value});
16+
if (e.originalEvent.key === "Enter") {
17+
w2ui.toolbar.set("port", {value: this.value});
1818
w2ui.toolbar.refresh();
19-
w2ui['toolbar'].click('connect');
19+
w2ui.toolbar.click("connect");
2020
}
2121
});
2222
}
2323

2424
export function onConnected() {
2525
terminal.io.println("connected");
26-
w2ui['toolbar'].get('connect').text = 'Disconnect';
27-
w2ui['toolbar'].refresh();
26+
w2ui.toolbar.get("connect").text = "Disconnect";
27+
w2ui.toolbar.refresh();
2828
console.log("Updated menu");
2929
}
3030

3131
export function onDisconnect() {
32-
w2ui['toolbar'].get('connect').text = 'Connect';
33-
w2ui['toolbar'].refresh();
32+
w2ui.toolbar.get("connect").text = "Connect";
33+
w2ui.toolbar.refresh();
3434
}
3535

36-
let currentScript: (() => Promise<any>)[] = null;
36+
let currentScript: Array<() => Promise<any>> = null;
3737

38-
export function setScript(script: (() => Promise<any>)[]) {
38+
export function setScript(script: Array<() => Promise<any>>) {
3939
currentScript = script;
4040
}
4141

4242
export function onCtrlMenuClick(event) {
4343
switch (event.target) {
44-
case 'connect':
44+
case "connect":
4545
connect();
4646
break;
47-
case 'cls':
47+
case "cls":
4848
commands.clear();
4949
break;
50-
case 'mnu_command:bus':
50+
case "mnu_command:bus":
5151
if (busActive) {
5252
commands.busOff();
5353
} else {
54-
helper.warn('WARNING!<br>The coil will be energized.', commands.busOn);
54+
helper.warn("WARNING!<br>The coil will be energized.", commands.busOn);
5555
}
5656
break;
57-
case 'mnu_command:transient':
57+
case "mnu_command:transient":
5858
commands.setTransientEnabled(!transientActive);
5959
break;
60-
case 'mnu_command:settings':
61-
commands.sendCommand('config_get\r');
60+
case "mnu_command:settings":
61+
commands.sendCommand("config_get\r");
6262
break;
63-
case 'mnu_command:startStopMidi':
63+
case "mnu_command:startStopMidi":
6464
if (midiServer.active) {
6565
midiServer.close();
6666
} else {
6767
midiServer.requestName()
6868
.then(() =>
6969
ui_helper.inputPort("Please enter the port for the local MIDI server", "MIDI over IP Server",
70-
midiServer.port)
71-
).then(port=> {
70+
midiServer.port),
71+
).then((port) => {
7272
midiServer.setPort(port);
7373
midiServer.start();
7474
});
7575
}
7676
break;
77-
case 'mnu_command:Load EEPROM-Config':
78-
helper.warn('WARNING!<br>Are you sure to load the configuration from EEPROM?',
77+
case "mnu_command:Load EEPROM-Config":
78+
helper.warn("WARNING!<br>Are you sure to load the configuration from EEPROM?",
7979
commands.eepromSave);
8080
break;
81-
case 'mnu_command:Save EEPROM-Config':
82-
helper.warn('WARNING!<br>Are you sure to save the configuration to EEPROM?',
81+
case "mnu_command:Save EEPROM-Config":
82+
helper.warn("WARNING!<br>Are you sure to save the configuration to EEPROM?",
8383
commands.eepromSave);
8484
break;
85-
case 'mnu_midi:Play':
85+
case "mnu_midi:Play":
8686
media_player.startPlaying();
8787
break;
88-
case 'mnu_midi:Stop':
88+
case "mnu_midi:Stop":
8989
media_player.stopPlaying();
9090
break;
91-
case 'mnu_script:Start':
92-
if (currentScript==null) {
91+
case "mnu_script:Start":
92+
if (currentScript === null) {
9393
terminal.io.println("Please select a script file using drag&drop first");
9494
break;
9595
}
9696
scripting.startScript(currentScript);
9797
break;
98-
case 'mnu_script:Stop':
99-
if (currentScript==null) {
98+
case "mnu_script:Stop":
99+
if (currentScript === null) {
100100
terminal.io.println("Please select a script file using drag&drop first");
101101
break;
102102
}
@@ -106,40 +106,40 @@ export function onCtrlMenuClick(event) {
106106
}
107107
scripting.cancel();
108108
break;
109-
case 'kill_set':
109+
case "kill_set":
110110
commands.setKill();
111111
break;
112-
case 'kill_reset':
112+
case "kill_reset":
113113
commands.resetKill();
114114
break;
115115
}
116116
}
117117

118118

119-
function connect(){
119+
function connect() {
120120
if (connection.connection) {
121121
connection.disconnect();
122122
} else {
123-
const port = w2ui['toolbar'].get('port');
123+
const port = w2ui.toolbar.get("port");
124124
connection.connect(port.value);
125125
}
126126
}
127127

128128
export function updateBusActive() {
129129
if (busControllable) {
130-
helper.changeMenuEntry("mnu_command", "bus", "Bus "+(busActive?"OFF":"ON"));
130+
helper.changeMenuEntry("mnu_command", "bus", "Bus " + (busActive ? "OFF" : "ON"));
131131
}
132132
sliders.updateSliderAvailability();
133133
}
134134

135135
export function updateTransientActive() {
136-
helper.changeMenuEntry("mnu_command", "transient", "TR "+(transientActive?"Stop":"Start"));
136+
helper.changeMenuEntry("mnu_command", "transient", "TR " + (transientActive ? "Stop" : "Start"));
137137
sliders.updateSliderAvailability();
138138
}
139139

140140
export function updateBusControllable() {
141141
if (busControllable) {
142-
helper.addFirstMenuEntry("mnu_command", "bus", "Bus "+(busActive?"OFF":"ON"), 'fa fa-bolt');
142+
helper.addFirstMenuEntry("mnu_command", "bus", "Bus " + (busActive ? "OFF" : "ON"), "fa fa-bolt");
143143
} else {
144144
helper.removeMenuEntry("mnu_command", "bus");
145145
}

0 commit comments

Comments
 (0)