{"id":13338128,"url":"https://github.com/mk590901/door_simulation_on_toit","last_synced_at":"2026-01-18T17:32:56.237Z","repository":{"id":191680635,"uuid":"685172880","full_name":"mk590901/door_simulation_on_toit","owner":"mk590901","description":"The repository contains the source files for the automatic door modeling application in the toit language for the ESP32 controller.","archived":false,"fork":false,"pushed_at":"2023-09-01T10:54:54.000Z","size":55,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T15:12:00.751Z","etag":null,"topics":["simulation","state","state-machine","toit","toit-language"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mk590901.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-30T17:01:59.000Z","updated_at":"2023-11-06T18:06:18.000Z","dependencies_parsed_at":"2023-08-31T04:45:57.421Z","dependency_job_id":"74bb6f60-a940-4c4b-8b24-01cb5c42e86a","html_url":"https://github.com/mk590901/door_simulation_on_toit","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"b95de896d376819590427dcafe2f605fbbb8974e"},"previous_names":["mk590901/doot_simulation_toit"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mk590901/door_simulation_on_toit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk590901%2Fdoor_simulation_on_toit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk590901%2Fdoor_simulation_on_toit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk590901%2Fdoor_simulation_on_toit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk590901%2Fdoor_simulation_on_toit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mk590901","download_url":"https://codeload.github.com/mk590901/door_simulation_on_toit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk590901%2Fdoor_simulation_on_toit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28544808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T14:59:57.589Z","status":"ssl_error","status_checked_at":"2026-01-18T14:59:46.540Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["simulation","state","state-machine","toit","toit-language"],"created_at":"2024-07-29T19:15:31.653Z","updated_at":"2026-01-18T17:32:56.222Z","avatar_url":"https://github.com/mk590901.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Door simulation on toit\n![hiletgo_esp32_mini](https://github.com/mk590901/door_simulation_on_toit/assets/125393245/1f8acbf2-a3f9-483f-9b73-47edb84f994c)\n# Introduction\nThe reason for writing this application was to try to show how can create managed code app uses object-oriented approach and that will run on a controller with more than limited resources.\n\nAn application written in the ***toit*** language (https://toit.io/) is a simulator of an automatically opening/closing door. The principle of operation is described by state machine, presented below:\n\n![door](https://github.com/mk590901/door_simulation_on_toit/assets/125393245/9e25e66b-e0e5-4d98-bc1b-510ae96672b5)\n\nI.e. the door can be opened, closed and attempted to be opened at the moment it closes, because opening and closing  take time.\n\n# Application structure\nAn application is a set of classes that implement the idea outlined above in the Introduction.\n\n## Class State        *(state.toit)*\nThe class contains a container of objects of type ***Transition***. Each state corresponds to a set of transitions from this state to other states under the influence of events.\n\n## Class Transition        *(transition.toit)*\nThe object of the ***Transition*** class contains a pair: state to which to transition, and an object with the ***ITransition*** interface, the 'execute'' method to be called on the transition.\n\n## Class Trans        *(trans.toit)*\nThis class describes the transition of the state machine from the current state to another under the influence of some event. In fact, this class is a wrapper for describing the transfer. In the constructor of the ***State*** class, the elements of the ***Trans*** object are converted into container of transitions.\n\n## Interface ITransition        *(i_transition.toit)*\nThe ***execute*** function without parameters. Parameters or additional attributes for ***execute*** an be in the class that implements the interface.\n\n## Class BasicStateMachine        *(basic_state_machine.toit)*\nThis abstract class implements the transition of the state machine from one state to another under the influence of the given event. If the transition is valid, then the transition's function is called when. The basic class also delegates to the inheritance class to implement several additional functions: ***create***, ***publish***, ***getStateName*** and ***getEventName***. In this case, inheritance class is the ***DoorStateMachine*** class.\n\n## Class DoorStateMachine        *(door_state_machine.toit)*\nThis class inherited from basic class ***BasicStateMachine***, implements the logic described in the __Introduction__. Pay attention to the ***create*** method: in fact, this is the description of __state machine__. The class also contains an instance of object of type ***TimersEngine***. This class allows to create several timers that are used by the application to simulate time delays when opening and closing a door.\n\n## Interface INotifier        *(timersEngineImpl.toit)*\nDescribes the behavior of an object with ***start*** and ***final*** functions. In this case, object is used in a timer. The start of the timer is accompanied by a call to the start method, the stop leads to the call of the final method.\n\n## Class Timer        *(timersEngineImpl.toit)*\nContains identifier and notifier. The latter implements the ***start*** and ***final*** commands of the timer.\n\n## Class TimersEngine        *(timersEngineImpl.toit)*\nContains a container of timers, Allows to add, remove or start a named timer, as well as reset it by marking it as inactivated. The class contains a __task__ (https://docs.toit.io/language/tasks) in terms of __toit__, which runs when there are no active timers and exits automatically when all running timers become inactive. Pay attention to two functions: ***run_periodically*** and ***run_periodically_in_task***. They are what make the class work. These seven lines of code are not for the weak-minded the mournful-minded like me. The secret of using these functions was shared with me by ***Florian Loitsch*** (https://github.com/floitsch), one of the creators of the language, for which I am especially grateful to him.\n\n## main        *(door_runner.toit)*\nAnd finally the main module, which creates the ***DoorStateMachine***, initiates it and runs the simulation.\n\n# Application launch \nThere are several options for performing this operation. he site ***toit.io*** ((https://toit.io/)) suggests installing and using the ***jag*** app, but I'm still using ***toit***, which I installed two years ago. Judging by the documentation, both applications are similar.  The application can be run on a **computer** and/or on **ESP32**.  The result is identical.\n\nBelow are the results of running the application: command line and result.\n\n## Run on computer\n```\nmicrcx@micrcx-desktop:~/toit_apps/door_simulation_short$ toit execute door_runner.toit\n(17:08:19.637) @Closing  - start\n(17:08:19.637) [Start timer tC]\n(17:08:19.637) [Closing] @start\n(17:08:19.638) [State]-\u003eDOOR IS CLOSING\n******* AFTER SLEEP 1200 *******\n? Failed to get transition for event [close door] and state [DOOR IS CLOSING]\n(17:08:20.838) @Opening  - start\n(17:08:20.839) [Opening] @start\n(17:08:20.839) [State]-\u003eDOOR IS OPENING\n(17:08:23.842) [Opening] @final\n(17:08:23.842) @Opened   - final\n(17:08:23.843) [AutoClosing] @start\n(17:08:23.843) [State]-\u003eDOOR IS OPENED\n(17:08:26.352) [AutoClosing] @final\n(17:08:26.353) @Closing  - start\n(17:08:26.353) [Closing] @start\n(17:08:26.353) [State]-\u003eDOOR IS CLOSING\n(17:08:28.357) [Closing] @final\n(17:08:28.357) @Closed   - final\n(17:08:28.358) [State]-\u003eDOOR IS CLOSED\n(17:08:28.358) [Final timer : close engine]\nmicrcx@micrcx-desktop:~/toit_apps/door_simulation_short$ \n```\n\n## Run on ESP32\n```\nmicrcx@micrcx-desktop:~/toit_apps/door_simulation_short$ toit run -d=nuc door_runner.toit\n2023-08-30T17:05:43.619668Z: \u003cprocess initiated\u003e\n(19:05:43.471) @Closing  - start\n(19:05:43.516) [Start timer tC]\n(19:05:43.545) [Closing] @start\n(19:05:43.559) [State]-\u003eDOOR IS CLOSING\n******* AFTER SLEEP 1200 *******\n? Failed to get transition for event [close door] and state [DOOR IS CLOSING]\n(19:05:44.836) @Opening  - start\n(19:05:44.871) [Opening] @start\n(19:05:44.900) [State]-\u003eDOOR IS OPENING\n(19:05:47.890) [Opening] @final\n(19:05:47.907) @Opened   - final\n(19:05:47.938) [AutoClosing] @start\n(19:05:47.969) [State]-\u003eDOOR IS OPENED\n(19:05:50.450) [AutoClosing] @final\n(19:05:50.476) @Closing  - start\n(19:05:50.507) [Closing] @start\n(19:05:50.539) [State]-\u003eDOOR IS CLOSING\n(19:05:52.510) [Closing] @final\n(19:05:52.526) @Closed   - final\n(19:05:52.555) [State]-\u003eDOOR IS CLOSED\n(19:05:52.590) [Final timer : close engine]\n2023-08-30T17:05:53.096294Z: \u003cprocess terminated - exit code: 0\u003e\n```\n# Movie\nhttps://github.com/mk590901/door_simulation_on_toit/assets/125393245/83ad87b8-8244-40e1-8cbe-ccecddd944e3\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmk590901%2Fdoor_simulation_on_toit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmk590901%2Fdoor_simulation_on_toit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmk590901%2Fdoor_simulation_on_toit/lists"}