-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·94 lines (76 loc) · 1.98 KB
/
Copy pathmain.js
File metadata and controls
executable file
·94 lines (76 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"use strict";
var backgroundPage;
chrome.runtime.getBackgroundPage(function(result)
{
backgroundPage = result;
backgroundPage.app_window = window;
});
var TABS = {};
function UI_control()
{
this.serialDevice = null;
this.activeTabReference = false;
}
var UI = new UI_control();
// Called when the page had loaded
$(document).ready(function()
{
// Populate the serial devices list
chrome.serial.getDevices(function(ports)
{
buildPortPicker(ports);
});
// On clicking on the dropdown refresh the list
$("#buttonRefresh").click(function()
{
$("#port").empty().val("");
chrome.serial.getDevices(function(ports)
{
buildPortPicker(ports);
});
})
// Add listeners to tab links
$("#tabs a").click(function()
{
var name = $(this).parent().prop("class");
// Run the tab cleanup code
UI.activeTabReference.cleanup();
// When a tab switches remove all listeners
UI.serialDevice.purgeListeners();
// Reset motors, servomotors and turn all pins to input
UI.serialDevice.send("r");
// Remove contents
$('#content').empty();
// Remove highlighted style from all tabs
$("#tabs a").removeClass("active");
// Highlight the current tab
$(this).addClass("active");
TABS[name].initialize(UI.serialDevice);
});
// Add listener to the connect button
$("#buttonConnect").click(function()
{
if(UI.serialDevice.connectionId > 0)
{
// Already connected, so disconnect
UI.serialDevice.disconnect();
$(this).val("Connect");
}
else
{
// Try to connect to the device
var port = $("#port").val();
var bitrate = parseInt($("#bitrate").val());
if(UI.serialDevice.connect(port, {'bitrate': bitrate}))
{
$(this).val("Disconnect");
// Save the device so it's automatically selected the next time the user uses the application
chrome.storage.local.set({'port': port, 'bitrate': bitrate});
}
}
});
// Singleton serial device instance
UI.serialDevice = new Serial();
// Load default content of the page
TABS.home.initialize();
});