alarm.scm 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ;;; Guile-ZWave -- Guile talks with ZWave devices.
  2. ;;; Copyright © 2019, 2021 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of Guile-ZWave.
  5. ;;;
  6. ;;; Guile-ZWave is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; Guile-ZWave is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with Guile-ZWave. If not, see <http://www.gnu.org/licenses/>.
  18. ;; This is a simple example that watches notifications coming from ZWave
  19. ;; devices ("application command handler" messages).
  20. (use-modules (zwave)
  21. (srfi srfi-71)
  22. (ice-9 match))
  23. (define (run-alarm port)
  24. (let ((init (initialize-zwave-state port)))
  25. (write-serial-message (make-request (message-class get-initial-data))
  26. port)
  27. (let loop ((state init))
  28. (match (select (list port) '() '())
  29. ((() () ())
  30. (loop state))
  31. (_
  32. (let* ((state1 (handle-response (pk 'msg (read-serial-message port))
  33. state))
  34. (notification state2 (pop-zwave-state-notification state1)))
  35. (pk 'nodes (zwave-state-nodes state2))
  36. (when notification
  37. (pk 'alarm notification))
  38. (loop state2)))))))
  39. (run-alarm (open-zwave-serial-port (cadr (command-line))))