Example #1
0
        public Alarm(Microphone microphone, Buzzer buzzer)
        {
            _microphone = microphone;
            _buzzer     = buzzer;

            State = "disarmed";

            When("disarmed", allow: "arm");
            When("armed", allow: "disarm");

            Map("arm", async() => {
                State = "armed";

                await Done();
            });

            Map("disarm", async() => {
                State = "disarmed";

                if (_buzzer.IsAvailable("stop"))
                {
                    await _buzzer.Call("stop");
                }

                await Done();
            });
        }
Example #2
0
        public Alarm(Microphone microphone, Buzzer buzzer) {
            _microphone = microphone;
            _buzzer = buzzer;

            State = "disarmed";

            When("disarmed", allow: "arm");
            When("armed", allow: "disarm");

            Map("arm", async () => {
                State = "armed";

                await Done();
            });

            Map("disarm", async () => {
                State = "disarmed";

                if (_buzzer.IsAvailable("stop")) {
                    await _buzzer.Call("stop");
                }

                await Done();
            });
        }
Example #3
0
        public async Task Initialize()
        {
            var stream = await _microphone.CreateReadStream("volume");

            stream.Subscribe(async(obj) => {
                if (State == "disarmed")
                {
                    return;
                }

                var data = (double)obj.Data;

                if (data > 1.0d && _buzzer.IsAvailable("start"))
                {
                    await _buzzer.Call("start");
                }
            });

            await Done();
        }