www/js/global.js

Wed, 01 May 2024 14:38:37 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 01 May 2024 14:38:37 +0200
changeset 715
f5d85af156ab
parent 714
24749c296a50
permissions
-rw-r--r--

Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.


var DeviceTypeData = [
 { id: 0, mno: 'NA', en: 'Unknown' },
 { id: 1, mno: 'W1', en: 'One-wire' },
 { id: 2, mno: 'GPIO', en: 'GPIO' },
 { id: 3, mno: 'RC433', en: 'RC-433' },
 { id: 4, mno: 'DHT', en: 'DHT11' },
 { id: 5, mno: 'I2C', en: 'I2C bus' },
 { id: 6, mno: 'SPI', en: 'SPI bus' },
 { id: 7, mno: 'SIM', en: 'Simulator' }
],
DeviceTypeSource = {
 localdata: DeviceTypeData,
 datatype: 'array',
 datafields: [{ name: 'id' }, { name: 'mno' }, { name: 'en' }]
},
DeviceTypeAdapter = new $.jqx.dataAdapter(DeviceTypeSource),

DevicePresentData = [
 { id: 0, mno: 'UNDEF', en: 'Unknown' },
 { id: 1, mno: 'NO', en: 'No' },
 { id: 2, mno: 'YES', en: 'Yes' },
 { id: 3, mno: 'ERROR', en: 'Error' }
],
DevicePresentSource = {
 localdata: DevicePresentData,
 datatype: 'array',
 datafields: [{ name: 'id' }, { name: 'mno' }, { name: 'en' }]
},
DevicePresentAdapter = new $.jqx.dataAdapter(DevicePresentSource),

DeviceDirectionData = [
 { id: 0, mno: 'UNDEF', en: 'Unknown' },
 { id: 1, mno: 'IN_BIN', en: 'Binary input' },
 { id: 2, mno: 'OUT_BIN', en: 'Binary output' },
 { id: 3, mno: 'IN_ANALOG', en: 'Analog input' },
 { id: 4, mno: 'OUT_ANALOG', en: 'Analog output' },
 { id: 5, mno: 'OUT_PWM', en: 'PWM output' },
 { id: 6, mno: 'INTERN', en: 'Intern' }
],
DeviceDirectionSource = {
 localdata: DeviceDirectionData,
 datatype: 'array',
 datafields: [{ name: 'id' }, { name: 'mno' }, { name: 'en' }]
},
DeviceDirectionAdapter = new $.jqx.dataAdapter(DeviceDirectionSource),

// Temp sensors droptdown list
tempsensorSource = {
 datatype: 'json',
 datafields: [
  { name: 'uuid', type: 'string' },
  { name: 'name', type: 'string' }
 ],
 url: 'drop_tempsensors.php'
},
tempsensorlist = new $.jqx.dataAdapter(tempsensorSource),

// Switches dropdown list
switchesSource = {
 datatype: 'json',
 datafields: [
  { name: 'uuid', type: 'string' },
  { name: 'name', type: 'string' }
 ],
 url: 'drop_switches.php'
},
switcheslist = new $.jqx.dataAdapter(switchesSource),

// Contacts dropdown list
contactsSource = {
 datatype: 'json',
 datafields: [
  { name: 'uuid', type: 'string' },
  { name: 'name', type: 'string' }
 ], 
 url: 'drop_contacts.php'
},
contactslist = new $.jqx.dataAdapter(contactsSource),


// options for editors

Show0dec = { inputMode: 'simple', theme: theme, width: 90, height: 23, readOnly: true, decimalDigits: 0 },
Show1dec = { inputMode: 'simple', theme: theme, width: 90, height: 23, readOnly: true, decimalDigits: 1 },
Show2dec = { inputMode: 'simple', theme: theme, width: 90, height: 23, readOnly: true, decimalDigits: 2 },
Show3dec = { inputMode: 'simple', theme: theme, width: 90, height: 23, readOnly: true, decimalDigits: 3 },
Show4dec = { inputMode: 'simple', theme: theme, width: 90, height: 23, readOnly: true, decimalDigits: 4 },
Spin0dec = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, decimalDigits: 0, spinButtons: true },
Spin1dec = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, decimalDigits: 1, spinButtons: true },
Spin2dec = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, decimalDigits: 2, spinButtons: true },
Spin3dec = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, decimalDigits: 3, spinButtons: true },
Spin4dec = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, decimalDigits: 4, spinButtons: true },
  PosInt = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, decimalDigits: 0, spinButtons: true },
  SubInt = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, max: 63, decimalDigits: 0, spinButtons: true },
 GPIOInt = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: -1, max:31, decimalDigits: 0, spinButtons: true },
Perc1dec = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, max: 100, decimalDigits: 1, spinButtons: true },
   Perc0 = { inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, max: 100, decimalDigits: 0, spinButtons: true };


/* Websocket interface. Place "websocket.onmessage = function(evt) {}" in the user script. */
var websocket = new ReconnectingWebSocket('ws://'+location.hostname+'/ws');

websocket.onerror = function(event) {
 console.log('Websocket error: ' + event.data);
}



$(document).ready(function() {

 $('#jqxMenu').jqxMenu({
  width: 1280,
  height: '30px',
  autoOpen: false,
  clickToOpen: true,
  theme: theme
 });
 $('#jqxWidget').css('visibility', 'visible');
});

mercurial