{"id":3362,"date":"2025-04-18T05:38:16","date_gmt":"2025-04-18T05:38:16","guid":{"rendered":"https:\/\/webprojects.cloud\/wordpress\/splatco\/?post_type=spl_knowledgebase&#038;p=3362"},"modified":"2025-06-10T10:59:39","modified_gmt":"2025-06-10T10:59:39","slug":"simplehmi-introducing-events","status":"publish","type":"spl_knowledgebase","link":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/simplehmi-introducing-events\/","title":{"rendered":"SimpleHMI: Introducing Events"},"content":{"rendered":"\n<p>The first sample program above already handles one\u00a0<em>event<\/em>, namely the Connect event. What happens is that when you click the Connect button on the SPLat\/PC\u00a0<a href=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/glossary-of-terms\/#o5380\">SimpleHMI<\/a>\u00a0screen, a special message is sent to the SPLat via the serial port. The SPLat detects this and automatically does a\u00a0<code>GoSub<\/code>\u00a0to your event handler. The event handler is simply a subroutine that does whatever is required in response to that event. It must exit via a\u00a0<code>Return<\/code>\u00a0instruction.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table class=\"has-fixed-layout\"><tbody><tr><td>This event-based mechanism is carried through the whole set of\u00a0<a href=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/glossary-of-terms\/#o5243\">HMI<\/a>\u00a0hash functions. Events are also generated by button clicks and by user data entry.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Events provide a lot of the power of SimpleHMI programming. Every time your SPLat program defines an event and names an event handler, a new, totally unique event code is set up in the SimpleHMI. Thus every event is unique, and unambiguously tied to its own event handler. A program may contain up to 127 event handlers. You can reference an event handler multiple times.<\/p>\n\n\n\n<p>Consider this: SimpleHMI has a limited number of buttons, which can be re-used on different screens. On screen A button 1 may be the &#8220;Pump On&#8221; button. On screen B it may be the &#8220;Launch Missile&#8221; button. For each use you will have a separate handler subroutine. Now, it is only if screen B is actually showing that pressing that button will send back the event code for Launch_Missile. This means your program does not have to keep track of which screen it is showing in order to know how to respond to button 1.<\/p>\n\n\n\n<p>Here&#8217;s a program that illustrates this point (You will get best value from this if you have indicator lights on outputs 0, 1, and 2 of your controller). There is a detailed description of each segment after the program. In this example I am using specific buttons to illustrate a point. Since the original writing the need to explicitly nominate buttons is all but eliminated but the point remains to be made:<\/p>\n\n\n\n<p><a href=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/cutting-and-pasting-code-from-the-splat-knowledge-base\/\">(Click here<\/a>\u00a0for some tips for working around problems with copy and paste out of Internet Explorer and HTML-help\u00a0<code>(.chm)<\/code>\u00a0files)<\/p>\n\n\n\n<p>This code was originally written to run on SimpleHMI on Windows.&nbsp; However, SimpleHMI on Windows is no longer supported.&nbsp; This new version of the code is written to run on an HMI430 or HMI700.&nbsp; However,&nbsp;<strong>the controller will need to be power-cycled for the code to work.<\/strong><\/p>\n\n\n\n<p><code>;Demonstrate re-use of buttons, and unique event handlers for each use<\/code><br><code>;**** This example will require the HMI module to be restarted by a power cycle *******<\/code><br><code>HMIPort EQU 251 ;Define the port number we want to use.<\/code><br><code>#HMI ConnectEvent(HMI_Connect) ;Where to GoSub when the SimpleHMI connects<\/code><br><code>LaunchTask HeartBeat ;Show we are alive<\/code><br><code>RunTasksForever<\/code><br><br><code>;----- HeartBeat task, shows we are alive by flashing an output -----<\/code><br><code>HeartBeat:<\/code><br><code>On 0<\/code><br><code>Pause 2<\/code><br><code>Off 0<\/code><br><code>Pause 50<\/code><br><code>GoTo HeartBeat<\/code><br><code><\/code><br><code>;---- Event handler for the HMI Connected event generated by SimpleHMI -------<\/code><br><code>HMI_Connect:<\/code><br><code>GoSub HomeScreen ;Paint home screen<\/code><br><code>Return<\/code><br><br><code>;----- Event handler for Home button ------<\/code><br><code>HomeScreen:<\/code><br><code>#HMI Cls()<\/code><br><code>;#HMI HideAllButtons()<\/code><br><code>#HMI ButtonEvent2(id:1, y:4, x:9, h:3, w:20, t:\"Pump On\", ev:PumpOnEvent)<\/code><br><code>#HMI ButtonEvent2(id:2, y:9, x:9, h:3, w:20, t:\"Pump Off\", ev:PumpOffEvent)<\/code><br><code>#HMI ButtonEvent2(id:3, y:14, x:9, h:3, w:20, t:\"Launch Screen\", ev:LaunchScreen)<\/code><br><code>Return<\/code><br><br><code>;----- Event handler for Pump On button ------<\/code><br><code>PumpOnEvent:<\/code><br><code>On 1<\/code><br><code>Return<\/code><br><code><\/code><br><code>;----- Event handler for Pump Off button ------<\/code><br><code>PumpOffEvent:<\/code><br><code>Off 1<\/code><br><code>Return<\/code><br><code><\/code><br><code>;----- Event handler to paint Launch Screen ------<\/code><br><code>LaunchScreen:<\/code><br><code>#HMI SetColors(b:'HFF000000) Cls() ButtonEvent2(id:1, y:12, x:9, h:10, w:20, t:\"Launch Missile\", ev:Launch_Missile)<\/code><br><code>#HMI ButtonEvent2(id:2, y:21, x:0, h:3, w:8, t:\"Home\", ev:HomeScreen)<\/code><br><code>Return<\/code><br><code><\/code><br><code>****** Launch the missile *********<\/code><br><code>Launch_Missile:<\/code><br><code>LaunchTask MissileLaunch ;A new MultiTrack task<\/code><br><code>GoSub HomeScreen ;Display the home screen<\/code><br><code>Return<\/code><br><code>;==================================================================<\/code><br><code>;A separate MultiTrack task to create a \"spectacular\" launch display<\/code><br><code>bCount defBYTE<\/code><br><code>MissileLaunch:<\/code><br><code>SetMem bCount,150 ;150 flashes<\/code><br><code>#HMI ButtonEvent2(id:5, x:30, y:15, w:4, h:2, t:b(*bCount), m:\"d1m1\", ev:Return)<\/code><br><code>FLoop:<\/code><br><code>#HMI ButtonEvent2(id:5, t:b(*bCount) )<\/code><br><code>On 2<\/code><br><code>Pause 10<\/code><br><code>Off 2<\/code><br><code>Pause 90<\/code><br><code>DMGNZ bCount,Floop<\/code><br><code>Killtask<\/code><br><br><code>Return:<\/code><br><code>Return<\/code><\/p>\n\n\n\n<p>Here&#8217;s a blow by blow description of each segment of the program:<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Startup code<\/h6>\n\n\n\n<p>Defines the handler for the HMI ConnectEvent, launches the heartbeat task and gets MultiTrack running.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Heartbeat task<\/h6>\n\n\n\n<p>Trivial. I use this because it&#8217;s helpful to know during development that my program is actually running, especially as there&#8217;s a 10 second delay when initialising a serial protocol.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Connect event handler<\/h6>\n\n\n\n<p>Just calls the subroutine that paints the home screen. This is also called from elsewhere.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Handler for Home button<\/h6>\n\n\n\n<p><code>Cls()<\/code>&nbsp;clears the screen to the current background colour (more on that later).&nbsp;<code>HideAllButtons()<\/code>&nbsp;&#8230; I&#8217;ll let you work that out!<\/p>\n\n\n\n<p>Once the screen is returned to a blank state, we position and label buttons 1, 2, and 3, and define their event handler names.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Pump handlers<\/h6>\n\n\n\n<p>Trivial, but notice how little effort it has taken to tie the buttons to the physical actions.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Launch screen<\/h6>\n\n\n\n<p>This is the program&#8217;s second screen. It sets the background colour to red before clearing the screen. Then it defines a large, impressive &#8220;Launch Missile&#8221; button and a more modest Home button. Notice we are using button 1, which on the home screen is the Pump On button.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Launch button handler<\/h6>\n\n\n\n<p>This handler launches a fresh MultiTrack task whose job it is to manage the missile launch sequence.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">MissileLaunch task<\/h6>\n\n\n\n<p>Creates a light and sound show (minus sound!) consisting of 150 rapid flashes of an output, then kills itself.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">But there&#8217;s a problem, Housten!<\/h6>\n\n\n\n<p>When you test the program you will discover that on returning to the home screen from the launch screen, the red background colour persists. That was not the intention.<\/p>\n\n\n\n<p>Exercise: Study the program and fix it.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">A subtle hazard<\/h6>\n\n\n\n<p>I have positioned the Launch Screen button on the home screen, and the Launch Missile button on the launch screen, deliberately overlapping each other. If you click very rapidly on the overlapping buttons, you will be able to crash the program. The reason is that every time you launch the missile you also launch another copy of the&nbsp;<code>MissileLaunch<\/code>&nbsp;task. When you get to the limit of 32 running tasks, the controller crashes.<\/p>\n\n\n\n<p>Exercise: Find a solution.<\/p>\n\n\n\n<p>Hint: Use a\u00a0<a href=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/programming-reference\/instructions-arranged-by-function\/semaphore-instructions\/\">semaphore<\/a>\u00a0that is set when the launch missile task is launched, and reset when it completes. Use that semaphore to prevent it from being launched a second time when it is already running.<\/p>\n\n\n\n<p>This effect does not occur in Android, because Android and Windows have different way of rendering overlapping buttons. This example is intended only for the Windows versions of SimpleHMI.<\/p>\n\n\n\n<p>Note: It took me longer to write this page than to write the sample program.<\/p>\n\n\n\n<p>Exercise: Modify the program so it is impossible to launch while the pump is on.<\/p>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>The first sample program above already handles one\u00a0event, namely the Connect event. What happens is that when you click the Connect button on the SPLat\/PC\u00a0SimpleHMI\u00a0screen,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3355,"menu_order":4,"template":"","class_list":["post-3362","spl_knowledgebase","type-spl_knowledgebase","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SimpleHMI: Introducing Events - SPLat Controls<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SimpleHMI: Introducing Events - SPLat Controls\" \/>\n<meta property=\"og:description\" content=\"The first sample program above already handles one\u00a0event, namely the Connect event. What happens is that when you click the Connect button on the SPLat\/PC\u00a0SimpleHMI\u00a0screen,...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/simplehmi-introducing-events\/\" \/>\n<meta property=\"og:site_name\" content=\"SPLat Controls\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-10T10:59:39+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/simplehmi-introducing-events\/\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/simplehmi-introducing-events\/\",\"name\":\"SimpleHMI: Introducing Events - SPLat Controls\",\"isPartOf\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website\"},\"datePublished\":\"2025-04-18T05:38:16+00:00\",\"dateModified\":\"2025-06-10T10:59:39+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/simplehmi-introducing-events\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/simplehmi-introducing-events\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/simplehmi-introducing-events\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials, application notes and white papers\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Tutorial: SimpleHMI programming of SPLat controllers\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"SimpleHMI: Introducing Events\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/\",\"name\":\"SPLat Controls\",\"description\":\"OEM Embedded Machine Controllers\",\"publisher\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization\",\"name\":\"SPLat Controls\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg\",\"contentUrl\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg\",\"caption\":\"SPLat Controls\"},\"image\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SimpleHMI: Introducing Events - SPLat Controls","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"SimpleHMI: Introducing Events - SPLat Controls","og_description":"The first sample program above already handles one\u00a0event, namely the Connect event. What happens is that when you click the Connect button on the SPLat\/PC\u00a0SimpleHMI\u00a0screen,...","og_url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/simplehmi-introducing-events\/","og_site_name":"SPLat Controls","article_modified_time":"2025-06-10T10:59:39+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/simplehmi-introducing-events\/","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/simplehmi-introducing-events\/","name":"SimpleHMI: Introducing Events - SPLat Controls","isPartOf":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website"},"datePublished":"2025-04-18T05:38:16+00:00","dateModified":"2025-06-10T10:59:39+00:00","breadcrumb":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/simplehmi-introducing-events\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/simplehmi-introducing-events\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/simplehmi-introducing-events\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/"},{"@type":"ListItem","position":2,"name":"Tutorials, application notes and white papers","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/"},{"@type":"ListItem","position":3,"name":"Tutorial: SimpleHMI programming of SPLat controllers","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-simplehmi-programming-of-splat-controllers\/"},{"@type":"ListItem","position":4,"name":"SimpleHMI: Introducing Events"}]},{"@type":"WebSite","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/","name":"SPLat Controls","description":"OEM Embedded Machine Controllers","publisher":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webprojects.cloud\/wordpress\/splatco\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization","name":"SPLat Controls","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg","contentUrl":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg","caption":"SPLat Controls"},"image":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/spl_knowledgebase\/3362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/spl_knowledgebase"}],"about":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/types\/spl_knowledgebase"}],"author":[{"embeddable":true,"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/users\/1"}],"up":[{"embeddable":true,"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/spl_knowledgebase\/3355"}],"wp:attachment":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/media?parent=3362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}