-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex_html.h
More file actions
143 lines (140 loc) · 5.94 KB
/
index_html.h
File metadata and controls
143 lines (140 loc) · 5.94 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
static const char PROGMEM INDEX_HTML[] = R"rawliteral(
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset="UTF-8">
<meta name = "viewport" content = "width = device-width, initial-scale = 1.0, maximum-scale = 5.0">
<title>Media Remote 0.11</title>
<style type="text/css">
table {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
border-collapse: collapse;
}
td {
border: 1px solid;
font-size: 200%;
text-align: center;
}
</style>
<script type="text/javascript">
var websock;
var connected = false;
function touch_start(event) {
event.preventDefault();
console.log('touch_start', this.id, this.innerHTML, event);
var json = JSON.stringify({event:'touch start', name:this.innerHTML, row:this.row, col:this.col});
document.getElementById(this.id).style.backgroundColor = "yellow";
if (!connected) {
setTimeout(function(json) {
websock.send(json);
}, 200);
window.location.reload();
}
else {
websock.send(json);
}
}
function touch_end(event) {
event.preventDefault();
console.log('touch_end', this.id, this.innerHTML, event);
document.getElementById(this.id).style.backgroundColor = "white";
websock.send(JSON.stringify({event:'touch end', name:this.innerHTML, row:this.row, col:this.col}));
}
function touch_move(event) {
event.preventDefault();
var json = JSON.stringify({event:'touch move', name:this.innerHTML, row:this.row, col:this.col});
if (!connected) {
setTimeout(function(json) {
websock.send(json);
}, 200);
window.location.reload();
}
else {
websock.send(json);
}
}
function touch_cancel(event) {
event.preventDefault();
console.log('touch_cancel', this.id, this.innerHTML, event);
document.getElementById(this.id).style.backgroundColor = "white";
websock.send(JSON.stringify({event:'touch cancel', name:this.innerHTML, row:this.row, col:this.col}));
}
function button_click(event) {
event.preventDefault()
}
function double_click(event) {
event.preventDefault();
}
function context_menu(event) {
event.preventDefault();
}
function generateGrid(cellData, id) {
let grid = document.getElementById(id);
let r = 0;
for (let rowElement of cellData) {
let aRow = grid.insertRow();
let c = 0;
for (let colElement of rowElement) {
let cell = aRow.insertCell();
cell.id = 'r' + r + 'c' + c;
cell['row'] = r;
cell['col'] = c;
cell.onclick = button_click;
cell.ondblclick = double_click;
cell.oncontextmenu = context_menu;
cell.ontouchstart = touch_start;
cell.onmousedown = touch_start;
cell.ontouchmove = touch_move;
cell.onmousemove = touch_move;
cell.ontouchend = touch_end;
cell.onmouseup = touch_end;
cell.onmouseout = touch_end;
cell.onmouseleave = touch_end;
cell.ontouchcancel = touch_cancel;
cell.innerHTML = colElement["cellLabel"];
if (colElement["colSpan"] > 1) {
cell.colSpan = colElement["colSpan"];
}
c++;
}
r++;
}
}
var FullPage = document.documentElement;
function openFullscreen() {
if (FullPage.requestFullscreen) {
FullPage.requestFullscreen();
} else if (FullPage.mozRequestFullScreen) { /* Firefox */
FullPage.mozRequestFullScreen();
} else if (FullPage.webkitRequestFullscreen) { /* Chrome, Safari & Opera */
FullPage.webkitRequestFullscreen();
} else if (FullPage.msRequestFullscreen) { /* IE/Edge */
FullPage.msRequestFullscreen();
}
}
function start() {
// sending a connect request to the server.
websock = new WebSocket('ws://' + window.location.hostname + ':81/');
websock.onopen = function(evt) { console.log('websock onopen', evt); connected = true; };
websock.onclose = function(evt) { console.log('websock onclose', evt); connected = false; };
websock.onerror = function(evt) { console.log('websock onerror', evt); };
websock.onmessage = function(evt) {
console.log(evt);
generateGrid(JSON.parse(evt.data), "my_table");
};
}
</script>
</head>
<body onload="javascript:start();" onresize="window.location.reload();">
<table id="my_table">
<!-- Grid goes here -->
</table>
</body>
</html>
)rawliteral";