{"id":537,"date":"2022-04-25T13:36:06","date_gmt":"2022-04-25T12:36:06","guid":{"rendered":"https:\/\/ibex.tech\/csharp\/?p=537"},"modified":"2022-04-25T13:51:20","modified_gmt":"2022-04-25T12:51:20","slug":"state-machine","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/c-sharp\/general-c-things\/state-machine","title":{"rendered":"State Machine"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">A Mode State Machine<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\t\/\/----- PRIVATE DEFINES -----\r\n\tprivate const int UM_STARTUP = 0;\r\n\tprivate const int UM_IDLE = 1;\n\n\t\/\/----- PRIVATE OBJECTS -----\r\n\tprivate int CurrentMode = -1;\r\n\tprivate int CurrentModeLast = -1;\n\n\n\n\t\/\/------------------------------\r\n\t\/\/----- CHECK FOR NEW MODE -----\r\n\t\/\/------------------------------\r\n\tThisIsNewState = false;\r\n\tif (CurrentModeLast != CurrentMode)\r\n\t{\r\n\t\tCurrentModeLast = CurrentMode;\r\n\t\tThisIsNewState = true;\r\n\t}\r\n\r\n\r\n\t\/\/------------------------------------\r\n\t\/\/------------------------------------\r\n\t\/\/----- PROCESS THE CURRENT MODE -----\r\n\t\/\/------------------------------------\r\n\t\/\/------------------------------------\r\n\tswitch (CurrentMode)\r\n\t{\r\n\tcase UM_STARTUP:\r\n\t\t\/\/-------------------\r\n\t\t\/\/-------------------\r\n\t\t\/\/----- STARTUP -----\r\n\t\t\/\/-------------------\r\n\t\t\/\/-------------------\r\n\t\tif (ThisIsNewState)\r\n\t\t{\r\n\t\t\t\/\/----- JUST ENTERED THIS MODE -----\r\n\r\n\r\n\t\t}\r\n\t\t\/\/------------------------\r\n\t\t\/\/----- PROCESS MODE -----\r\n\t\t\/\/------------------------\r\n\r\n\r\n\t\tbreak;\r\n\r\n\r\n\tcase UM_IDLE:\r\n\t\t\/\/-------------------------------\r\n\t\t\/\/-------------------------------\r\n\t\t\/\/----- IDLE - DEFAULT MODE -----\r\n\t\t\/\/-------------------------------\r\n\t\t\/\/-------------------------------\r\n\t\tif (ThisIsNewState)\r\n\t\t{\r\n\t\t\t\/\/----- JUST ENTERED THIS MODE -----\r\n\r\n\r\n\t\t}\r\n\t\t\/\/------------------------\r\n\t\t\/\/----- PROCESS MODE -----\r\n\t\t\/\/------------------------\r\n\r\n\r\n\t\tbreak;\r\n\r\n\r\n\t} \/\/switch (CurrentMode)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A Mode State Machine<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[],"class_list":["post-537","post","type-post","status-publish","format-standard","hentry","category-general-c-things"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=537"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/537\/revisions"}],"predecessor-version":[{"id":540,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/537\/revisions\/540"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}