-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsevenseg.html
206 lines (189 loc) · 6.83 KB
/
sevenseg.html
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="sevenseg.css">
<link rel="stylesheet" href="krt2panel.css">
<style>
.cont {
display: flex;
}
.leftCol {
flex: 1;
}
.rightCol {
flex: 1;
}
.frequence {
height: 25px;
width: 200px;
}
#stationsCont {
height: 290px; /* die bildschirmhoehe von meinem ASUSPRO5IJC ist NICHT ausreichend */
overflow-y: scroll;
}
</style>
<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!-- http://knockoutjs.com/index.html -->
<script src="//ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js"></script>
<script src="persist.js"></script>
<script src="sevenSeg.js"></script>
<script>
$(document).ready(function () {
/*
* wir definieren nFrequence als number und speichern NUR (fixed length) int (KEINE floats)
* - wir speichern in der string repeaesentation IMMER 6 stellen (fuehrende nullen)
* - somit ist die einheit kHZ.
*
* trigger fuer diese umstellung war der IE, der fuer das <li value=""> keine floats, strings akzeptieren wollte.
* - mit der einheit MHZ und der resultierenden notwendigkeit floats zu speichen gibt es unnoetige schwierigkeiten beim verstaendniss
* - in der Anzeige wollen wir nach wie vor die einheit MHZ bzw. den daraus resultierenden dezimalpunkt
*/
var rgStations = [
{ nFrequence: 123500, sName: "Geratshf" },
{ nFrequence: 123995, sName: "BadWoer" },
{ nFrequence: 120100, sName: "KemptenD" },
{ nFrequence: 126025, sName: "Agathazl" },
{ nFrequence: 118500, sName: "Memmingn" },
{ nFrequence: 122500, sName: "Paterzel" },
{ nFrequence: 126900, sName: "PETER" }
];
rgStations.forEach(function (curVal) {
var sFrequence = curVal.nFrequence,
sLI = '<li value="' + sFrequence + '"class="ui-widget-content">' + curVal.sName + '</li>';
$('#stations').append(sLI);
});
$( '#stations' ).selectable({
stop: function () {
var resultText = $('.ui-selected').text(),
sAttrValue = $('.ui-selected').attr("value"),
fAttrValue = parseFloat(sAttrValue, 10) / 1000,
sMHZ = sAttrValue.substring(0, 3),
sKHZ = sAttrValue.substring(3),
nMHZ = parseInt(sMHZ),
nKHZ = parseInt(sKHZ) / 5,
nChkSum = nMHZ ^ nKHZ,
/*
* wir bauen ein Array (most generic)
* 1.3.3 Set passive frequency (MHz,KHz) & name
*/
rgCommand = [2, "R".charCodeAt(0), nMHZ, nKHZ],
nIndex = 0,
sCommand = "";
for (nIndex; nIndex < resultText.length; nIndex++)
rgCommand.push(resultText.charCodeAt(nIndex));
/*
* ensure TextLength is 8 Byte
* String.prototype.padEnd(), https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd
* sorry not for Internet Explorer
*/
for (nIndex = resultText.length; nIndex <= 7 ;nIndex++)
rgCommand.push(" ".charCodeAt(0));
rgCommand.push(nChkSum);
// einen string fuer die anzeige, hex codiert, space delemitted
rgCommand.forEach(function (curVal) {
sCommand += "0x";
sCommand += 15 < curVal ? curVal.toString(16) : "0" + curVal.toString(16); // ensure 2 Digits
sCommand += " ";
});
$('#command').text(sCommand);
window.external.sendCommand(sCommand, function () { });
ko.applyBindings({ station: ko.observable(fAttrValue) });
}
});
$('#file-input').on('change', PersistModul.readSingleFile);
});
function uploadToKRT2() {
var nIndex = 0,
rgCommands = PersistModul.rgStations.map(function (station, nStationIndex) {
var sFrequence = station.nFrequence,
nMHZ = Math.floor(station.nFrequence / 1000),
nKHZ = (station.nFrequence - nMHZ * 1000) / 5,
nChkSum = nMHZ ^ nKHZ,
/*
* 1.3.5 Set a single record & name to database with address
*/
rgCommand = [2, "Z".charCodeAt(0), nMHZ, nKHZ],
nIndex = 0,
sCommand = "";
for (nIndex; nIndex < station.sName.length; nIndex++)
rgCommand.push(station.sName.charCodeAt(nIndex));
/*
* ensure TextLength is 8 Byte
* String.prototype.padEnd(), https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd
* sorry not for Internet Explorer
*/
for (nIndex = station.sName.length; nIndex <= 7 ; nIndex++)
rgCommand.push(" ".charCodeAt(0));
rgCommand.push(nStationIndex);
rgCommand.push(nChkSum);
// einen string fuer die anzeige, hex codiert, space delemitted
rgCommand.forEach(function (digit) {
sCommand += "0x";
sCommand += 15 < digit ? digit.toString(16) : "0" + digit.toString(16); // ensure 2 Digits
sCommand += " ";
});
return sCommand;
});
console.log("rgCommands.length: ", rgCommands.length);
(function fnSendCommand() {
window.external.sendCommand(rgCommands[nIndex], function (error, result) {
if (error) {
document.getElementById('command').innerText = 'transmit failed with: ' + error + ', STOP at: ' + nIndex;
} else {
document.getElementById('command').innerText = 'transmit completed';
if (rgCommands.length > ++nIndex)
fnSendCommand(); // continue thru recursion
}
});
// progress
// document.getElementById('command').innerText = ' wait for complete: ' + nIndex;
})();
}
var g_bDUALMode = false;
function toggleDUALMode() {
var sDualModeOn = "0x02 0x4f", // Interface_Ext_V18.pdf(5), 1.3.7 DUAL-mode on
sDualModeOff = "0x02 0x6f", // Interface_Ext_V18.pdf(5), 1.3.8 DUAL-mode off
lAccept;
g_bDUALMode = !g_bDUALMode;
lAccept = window.external.fireAndForget(g_bDUALMode ? sDualModeOn : sDualModeOff);
if (lAccept)
document.getElementById('command').innerText = 'command rejected, buffer full/busy';
}
</script>
</head>
<body>
<div class="cont">
<div class="leftCol">
<!--
wenn ich eine map nutze darf ich das bild nicht scalieren
ImageMap Generator, http://imagemap-generator.dariodomi.de/
-->
<img id="KRT2Panel" src="krt2old.png" usemap="#buttonmap">
<map name="buttonmap">
<area title="Power-On/Off" onclick="uploadToKRT2()" shape="rect" coords="86,30,142,82" />
<area title="toggle DUALMode" onclick="toggleDUALMode()" shape="rect" coords="153,34,202,81" />
<area title="AUD" shape="rect" coords="218,35,264,81" />
<area title="Memory" shape="rect" coords="97,275,144,323" />
<area title="switch" shape="rect" coords="162,276,202,318" />
<area title="Frequence" shape="rect" coords="221,275,264,320" />
</map>
</div>
<div class="rightCol">
<input id="frequence" type="hidden" data-bind="value: station, valueUpdate: 'afterkeydown'">
<p>
<span id="command"></span>
<button id="btnSoft1">undefined</button>
<button id="btnSoft2">undefined</button>
</p>
<div id="stationsCont">
<ol id="stations"></ol>
</div>
</div>
</div>
<hr />
<div class="frequence" data-bind="sevenSeg: { digits: 6, value: station, allowInput: true, step: 0.025, decimalPlaces: 3 }"></div>
<input type="file" id="file-input" />
</body>
</html>