Touch screen cleaning script for LogicMachine visualization
Example: Touch screen cleaning script for LogicMachine visualization
Task
There needs some cleaning to be done on touch screens which are mounted, for example, on the wall and not always you can clean the screen without activating some button on visualization. The below script allows to send 1 to specific KNX group address (in this example 0/0/1) and during Screen_Clean_Time the visualization and all objects will be inactive, including right mouse clicks. After cleaning time is over, the visualization returns to its normal state.
Resident script
The following script needs to be added in Resident scripts, it will disable itself automatically after run once.
- -- ************ Screen cleaning module version 1.0 created by Erwin van der Zwart ************** --
- -- ******* This script perform automaticly all needed actions to support screen cleaning ******* --
- -- After running script once refresh browser and write object to trigger the screen clean page --
- -- ****************************************** SET PARAMETERS *********************************** --
-
- --!!! Important !!! Set 1 pc/visu page to use as template to 'Show, make default', if no page is set to 'Show, make default' the script exits without creation of page !!
- --!!! Important !!! Works only on iOS/Android after enabling javascript)
-
- --Give a (not already excisting) name for the plan thats holds the screen clean page module (if already exist then script exit the creation)
- Screen_Clean_Page_Name = 'homeLYnk Screen Cleaning Module'
-
- -- Group address to trigger the screen cleaning page
- Screen_Clean_Trigger_Group_Address = '0/0/1' -- !! MUST BE A BIT OBJECT !! false = STOP AND BACK TO ORIGIN, true = ACTIVATE
-
- -- Set screen clean time (in seconds)
- Screen_Clean_Time = 60
-
- -- Set translation for screen cleaning duration (user message)
- Cleaning_Message = 'You can clean the screen now'
- Cleaning_Time_Prefix = 'Within'
- Cleaning_Time_Suffix = 'seconds this screen will be closed'
-
- -- ****************************************** END PARAMETERS ************************************ --
- -- ***************************** DON'T CHANGE ANYTHING UNDER THIS LINE ************************** --
-
- -- Get default startpage
- query = 'SELECT id, building, layout, name, usermode_param, width, height FROM visfloors'
- for _, floor in ipairs(db:getall(query)) do
- if floor.usermode_param == "D" then
- default_startpage = floor.id
- screen_clean_page_building = floor.building
- screen_clean_width = floor.width
- screen_clean_height = floor.height
- end
- if floor.name == Screen_Clean_Page_Name then
- name_already_excist = true
- end
- end
-
- -- Check if default page excists else exit script
- if default_startpage == nil then
- alert("Default page does not excists, exit screen clean page creation")
- -- Disable script
- script.disable(_SCRIPTNAME)
- --Exit script
- return
- end
-
- -- Enable page adding
- Page_Adding = true
-
- -- Check alert page already excists else exit script
- if name_already_excist == true then
- alert("Screen clean page already excist or name is already used, only HTML will be rewritten")
- -- Disable page adding
- Page_Adding = false
- end
-
- -- Set sortorder to default sortorder value for counting
- highest_sortorder = 1
-
- -- Get highest sortorder inside building part where default startpage is located
- query = 'SELECT sortorder FROM visfloors WHERE building == ' .. screen_clean_page_building .. ' ORDER BY sortorder DESC'
- for _, floor in ipairs(db:getall(query)) do
- if highest_sortorder <= floor.sortorder then
- highest_sortorder = floor.sortorder + 1
- end
- end
-
- if Page_Adding == true then
- -- Create alert page if screen clean page doesn't exist
- db:insert('visfloors', {building = screen_clean_page_building, layout = 0, sortorder = highest_sortorder, name = Screen_Clean_Page_Name, bgrepeat = 0, bgfixed = 0, adminonly = 0, width = screen_clean_page_width, height = screen_clean_page_height,})
- end
-
- -- Get page number of new created screen clean page
- screen_clean_page_number = db:getone('SELECT id FROM visfloors WHERE name=?', Screen_Clean_Page_Name)
-
- -- Check if screen clean time (in seconds) is at least 1 second
- if Screen_Clean_Time < 1 then
- Screen_Clean_Time = 1
- end
-
- -- Create HTML content
- page = [[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>homeLYnk Screen Clean Page</title>
- <style type="text/css">
- html, body {
- background-color: transparent;
- height: 100%;
- margin: 0px; background: #ffffff;
- opacity: 0.7;
- }
- .fullscreen {
- height: 100%;
- background-color: transparent;
- }
- </style>
- </head>
- <body>
- <div class="fullscreen" id="Wrapper" style="width:100%; margin-bottom: 0px; text-align: center; padding-bottom: 0px; min-height: 100%;">
- <div id="holder" style="height:20px; width:100%; resize:none; text-align: center; padding-top: 5px; font-family: Verdana, Geneva, sans-serif; font-weight: bold;">
- <label id="title">Screen Cleaner</label>
- </div>
- <div id="holder" style="height:20px; width:100%; resize:none; text-align: center; padding-top: 20px; font-family: Verdana, Geneva, sans-serif;">
- <label id="message"></label>
- </div>
- <div id="holder" style="height:20px; width:100%; resize:none; text-align: center; padding-top: 10px; font-family: Verdana, Geneva, sans-serif;">
- <label id="counter">0</label>
- </div>
- </div>
- <script type="text/javascript">
-
- // ***** Make link to parent from iframe *****
- var p = window.parent, root, addr;
- var ip = location.host;
- var URL = "http://" + ip + "/scada/resources/img/";
- var Screen_Clean_Page_Name = "]] .. Screen_Clean_Page_Name .. [[";
- var Cleaning_Message = "]] .. Cleaning_Message .. [[";
- var Screen_Clean_Time = "]] .. Screen_Clean_Time .. [[";
- var Cleaning_Time_Prefix = "]] .. Cleaning_Time_Prefix .. [[";
- var Cleaning_Time_Suffix = "]] .. Cleaning_Time_Suffix .. [[";
- var Current_Plan = p.currentPlanId;
- var Screen_Clean_Time_Counter = Screen_Clean_Time
-
- if (p && p.objectStore) {
-
- document.getElementById('title').innerHTML = Screen_Clean_Page_Name;
- document.getElementById('message').innerHTML = Cleaning_Message;
- document.getElementById('counter').innerHTML = Cleaning_Time_Prefix + " " + Screen_Clean_Time_Counter + " " + Cleaning_Time_Suffix;
-
- // Declare functions to disable mouseclicks on parent
- function pclickIE() {
- if (p.document.all) {
- return false;
- }
- }
-
- function pclickNS(e) {
- if (p.document.layers||(p.document.getElementById &&! p.document.all)) {
- if (e.which==2||e.which==3) {
- return false;
- }
- }
- }
-
- if (p.document.layers) {
- p.document.captureEvents(Event.MOUSEDOWN);
- p.document.onmousedown = pclickNS;
- } else {
- p.document.onmouseup = pclickNS;
- p.document.oncontextmenu = pclickIE;
- }
-
- // Declare functions to disable mouseclicks on current document
- function clickIE() {
- if (document.all) {
- return false;
- }
- }
-
- function clickNS(e) {
- if (document.layers||(document.getElementById&&!document.all)) {
- if (e.which==2||e.which==3) {
- return false;
- }
- }
- }
-
- if (document.layers) {
- document.captureEvents(Event.MOUSEDOWN);
- document.onmousedown = clickNS;
- } else {
- document.onmouseup = clickNS;
- document.oncontextmenu = clickIE;
- }
-
- // Create empty variable for loop countdown
- var countdown = "";
-
- // Set user message to init value
- document.getElementById('counter').innerHTML = Cleaning_Time_Prefix + " " + Screen_Clean_Time_Counter + " " + Cleaning_Time_Suffix;
-
- function countdowntimer() {
-
- Screen_Clean_Time_Counter = Screen_Clean_Time_Counter -1 ;
-
- if ( Screen_Clean_Time_Counter <= 0 ) {
- if ( countdown != "" ) {
- window.clearInterval(countdown);
- countdown = "";
- }
-
- // Enable mouseclicks on parent and current document
- p.document.oncontextmenu=null;
- document.oncontextmenu=null;
-
- Screen_Clean_Time_Counter = Screen_Clean_Time;
- p.setObjectValue({ address: ']] .. Screen_Clean_Trigger_Group_Address .. [[', rawdatatype: 1 }, 0, 'text');
- p.showPlan( Current_Plan );
-
- // Set user message back to init value
- document.getElementById('counter').innerHTML = Cleaning_Time_Prefix + " " + Screen_Clean_Time_Counter + " " + Cleaning_Time_Suffix;
- }
-
- if ( p.currentPlanId != ]] .. screen_clean_page_number .. [[ ) {
- Screen_Clean_Time_Counter = 0
- }
-
- document.getElementById('counter').innerHTML = Cleaning_Time_Prefix + " " + Screen_Clean_Time_Counter + " " + Cleaning_Time_Suffix;
- }
-
- // Add event listener on KNX addres for trigger screen clean function
- addr = p.Scada.encodeGroupAddress(']] .. Screen_Clean_Trigger_Group_Address .. [[');
- p.objectStore.addListener(addr, function(obj, type) {
-
- // to avoid trigger on opening page */
- if (type == 'init') {
- // Make sure object value = false after init
- if ( obj.value == 1) {
- p.setObjectValue({ address: ']] .. Screen_Clean_Trigger_Group_Address .. [[', rawdatatype: 1 }, 0, 'text');
- }
- return;
- }
-
- // close page
- if ( obj.value == 0) {
- if ( countdown != "" ) {
- window.clearInterval(countdown);
- countdown = "";
- }
-
- // Enable mouseclicks on parent and current document
- p.document.oncontextmenu=null;
- document.oncontextmenu=null;
-
- Screen_Clean_Time_Counter = Screen_Clean_Time;
- p.showPlan( Current_Plan );
-
- // Set user message back to init value
- document.getElementById('counter').innerHTML = Cleaning_Time_Prefix + " " + Screen_Clean_Time_Counter + " " + Cleaning_Time_Suffix;
- }
-
- // open page
- if ( obj.value == 1 ) {
-
- // Jump to screen clean page (only if other page is showed)
- if ( p.currentPlanId != ]] .. screen_clean_page_number .. [[ ) {
- Current_Plan = p.currentPlanId;
- p.showPlan(]] .. screen_clean_page_number .. [[);
- }
-
- // Disable mousclicks on parent and current document
- p.document.oncontextmenu = new Function("return false");
- document.oncontextmenu = new Function("return false");
-
- // Create countdown loop
- if( countdown == "" ){
- countdown = window.setInterval("countdowntimer()",1000);
- }
- }
-
- });
-
- }
-
- </script>
- </body>
- </html>
- ]]
-
- -- Create temp HTML file to write to controller
- file = io.open("scada/resources/img/screenclean.html", "w")
- -- Write HTML file to controller
- file:write(page)
- -- Close temp HTML file
- file:close()
-
- -- Check if HTML object already exist
- object_exists = false
- query = 'SELECT floor, type, name, params FROM visobjects'
- for _, visobject in ipairs(db:getall(query)) do
- if visobject.floor == screen_clean_page_number and (visobject.type == 9 or visobject.type == "9") and visobject.name == "screenclean" then
- object_exists = true
- end
- end
-
- if Page_Adding == true then
- -- Create html object on alertpage
- db:insert('visobjects', {floor = screen_clean_page_number, type = 9, params = '{"source":"url","url":"/scada/resources/img/screenclean.html","width":' .. screen_clean_width .. ',"height":' .. screen_clean_height .. '}', locx = 0 , locy = 0 , name = "screenclean", notouch = 1, nobg = 1,})
- log ("Screen clean page is added")
- elseif object_exists == false then
- -- Create html object on excisiting alertpage
- db:insert('visobjects', {floor = screen_clean_page_number, type = 9, params = '{"source":"url","url":"/scada/resources/img/screenclean.html","width":' .. Alert_Frame_Width .. ',"height":' .. Alert_Frame_Height .. '}', locx = 0 , locy = 0 , name = "screenclean", notouch = 1, nobg = 1,})
- log ("HTML is added to excisiting screen clean page")
- else
- log ("HTML on screen clean page is updated")
- end
-
- -- Disable script when done automaticly
- script.disable(_SCRIPTNAME)
Created by Erwin van der Zwart from Schneider Electric