Created
February 12, 2021 13:40
-
-
Save toomasv/4776c89704dbc88436b4db86f3bf3cc6 to your computer and use it in GitHub Desktop.
Harel's Citizen Quartz Multi-Alarm III statechart emulation for DiaGrammar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DiaGrammar [ | |
Options: [ | |
grammar-only?: false | |
ruleset: true | |
hovering: true | |
string-input: true | |
case-parsing: false | |
live-edit?: true | |
iterate-times: 1 | |
max-iterate: 5 | |
font-size: 11 | |
selected-rule: "clock" | |
latest-inputs: [] | |
]] | |
; SEMANTICS | |
; Rules represent states, tags represent events. | |
; On entering a state, vars are set (in parens), but events are not fired, | |
; i.e. states after events are not entered until corresponding event occurs. | |
; If there are consecutive states, all of these are entered, | |
; but if states are alternatives (separated by bar), | |
; they are entered either conditionally, | |
; or, if no condition, first state is entered. | |
clock: [dead | working] | |
dead: [<insert-battery> working] | |
working: [ | |
light | |
power | |
chime-status | |
alarm1-status | |
alarm2-status | |
main | |
<remove-battery> dead | |
] | |
; Setting vars corresponds to changes in physical structure | |
light: [(light?: off) [light-off | light-on]] | |
light-off: [(light?: off) <press-b> light-on] | |
light-on: [(light?: on) <release-b> light-off] | |
; Let's set battery life 1000 secs as in web-app | |
power: [(battery: 100%) [power-OK | blinking]] | |
power-OK: [<battery-weakens> blinking] | |
blinking: [<battery-dies> dead] | |
chime-status: [chime-disabled | chime-enabled] | |
chime-disabled: [(chime?: off) <press-d> chime-enabled] | |
chime-enabled: [(chime?: on) chime-quiet <press-d> chime-disabled] | |
chime-quiet: [<time is whole hour> chime-beeping] | |
chime-beeping: [<after 2 sec> chime-quiet] | |
alarm1-status: [alarm1-disabled | alarm1-enabled] | |
alarm1-disabled: [(alarm1?: off) <press-d> alarm1-enabled] | |
alarm1-enabled: [(alarm1?: on) <press-d> alarm1-disabled] | |
alarm2-status: [alarm2-disabled | alarm2-enabled] | |
alarm2-disabled: [(alarm2?: off) <press-d> alarm2-enabled] | |
alarm2-enabled: [(alarm2?: on) <press-d> alarm2-disabled] | |
main: [ | |
displays | alarms-beep | |
] | |
displays: [ | |
[regular | wait | stopwatch | out] | |
[<T hits T1 (P1)> alarm1-beeps | |
| <T hits T2 (P2)> alarm2-beeps | |
| <T hits T1 (P)> both-beep] | |
] | |
regular: [regular-proper beep-test] | |
regular-proper: [time | date | update] | |
time: [ | |
<press-d (b up)> date | |
| <press-c> wait | |
| <press a> alarm1 | |
] | |
date: [[<press-d> | <after 2 min>] time] | |
wait: [<release-c> time | <after 2 sec> update-sec] | |
alarms-beep: [ | |
[alarm1-beeps | alarm2-beeps | both-beep] | |
[<any button pressed> | <after 30 sec>] main-latest | |
] | |
update: [ | |
[update-sec | update-1min | update-10min | update-hour | update-month | update-date | update-day | update-year | update-mode] | |
[[<press-b> | <after 2 min>] time | <press-d> cycle-latest-up] | |
] | |
update-sec: [<press-c> update-1min ] | |
update-1min: [<press-c> update-10min] | |
update-10min: [<press-c> update-hour ] | |
update-hour: [<press-c> update-month] | |
update-month: [<press-c> update-date ] | |
update-date: [<press-c> update-day ] | |
update-day: [<press-c> update-year ] | |
update-year: [<press-c> update-mode ] | |
update-mode: [<press-c> time ] | |
beep-test: [b00 | b01 | b10 | beep] | |
b00: [<press-b> b10 | <press-d> b01 ] | |
b10: [<release-b> b00 | <press-d> beep] | |
b01: [<press-b> beep | <release-d> b00 ] | |
beep: [<release-b> b01 | <release-d> b10 ] | |
stopwatch: [[sw-zero | sw-run sw-display] <press-a> regular] | |
sw-zero: [<press-b> [sw-run sw-display]] | |
sw-run: [if (sw-run?) sw-run-on | sw-run-off] | |
sw-run-on: [(sw-run?: on) <press-b> sw-run-off] | |
sw-run-off: [(sw-run?: off) <press-b> sw-run-on] | |
sw-display: [sw-register | sw-lap] | |
sw-register: [<press-d> [if (sw-run?) sw-lap | sw-zero]] | |
sw-lap: [<press-d> sw-register] | |
out: [[alarm1 | update1 | alarm2 | update2 | chime] <after 2 min (no changes)> regular] | |
alarm1: [[if (alarm1?) alarm1-on | alarm1-off] [<press-c> update1-hour | <press-a> alarm2]] | |
alarm1-off: [(alarm1?: off) <press-d> alarm1-on] | |
alarm1-on: [(alarm1?: on) <press-d> alarm1-off] | |
update1: [ | |
[update1-hour | update1-10min | update1-1min] | |
[<press-b> alarm1 | <press-d> update1-cycle-latest-up] | |
] | |
update1-hour: [<press-c> update1-10min] | |
update1-10min: [<press-c> update1-1min] | |
update1-1min: [<press-c> alarm1] | |
alarm2: [[if (alarm2?) alarm2-on | alarm2-off] [<press-c> update2-hour | <press-a> chime]] | |
alarm2-off: [(alarm2?: off) <press-d> alarm2-on] | |
alarm2-on: [(alarm2?: on) <press-d> alarm2-off] | |
update2: [ | |
[update2-hour | update2-10min | update2-1min] | |
[<press-b> alarm2 | <press-d> update2-cycle-latest-up] | |
] | |
update2-hour: [<press-c> update2-10min] | |
update2-10min: [<press-c> update2-1min] | |
update2-1min: [<press-c> alarm2] | |
chime: [[if (chime?) chime-on | chime-off] <press-a> stopwatch-latest] | |
chime-on: [(chime?: on) <press-d> chime-off] | |
chime-off: [(chime?: off) <press-d> chime-on] | |
; EVENT DEFINITIONS | |
;insert-battery: [(clock/enabled?: yes)] | |
;remove-battery: [(clock/enabled?: no)] | |
;battery-weakens: [if (battery < 5%)] | |
;battery-dies: [if (battery = 0%)] | |
;press-a: [(a-btn/actors/on-down a-btn none)] | |
;press-b: [(b-btn/actors/on-down b-btn none)] | |
;release-b: [(b-btn/actors/on-up b-btn none)] | |
;press-c: [(c-btn/actors/on-down c-btn none)] | |
;release-c: [(c-btn/actors/on-up cb-btn none)] | |
;press-d: [(d-btn/actors/on-down d-btn none)] | |
;release-d: [(d-btn/actors/on-up d-btn none)] | |
;time-is-whole-hour: [if (all [clock/current-time/minute = 0 clock/current-time/second = 0])] | |
;timer: 0:0 | |
;after-2-sec: [if (timer > 0:0:2)] | |
;after 2 min: [if (timer > 0:02)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment