summaryrefslogtreecommitdiff
path: root/wpd/WpdBasicHardwareDriver/firmware/piezo_wpd_enabled.bs2
blob: ff5a7b5518f857c39977201e7fda8637ca9ef993 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
' Piezo_wpd_enabled.bs2
'
' This program demonstrates using the LDT0 as a switch/trigger
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'
' Copyright (c) Microsoft Corporation. All rights reserved
'
' {$STAMP BS2}
' {$PBASIC 2.5}
' =========================================================================

SensorID  VAR   Byte  'Sensor identifier = 8 for piezo
ElementSize VAR Byte  'Size (in bytes) of each element
ElementCount  VAR   Byte  'Count of elements in packet
bVibration    VAR  Byte  'Vibration-detection variable (single element for PIR)
Padding VAR Byte      'Padding for the 8-byte element

SensorID = 8
ElementSize = 1
ElementCount = 1      '1-byte for motion data; 5 for interval

NewInterval VAR  Word  'New interval requested by user
Interval  VAR   Word  'Interval value utlized by firmware

Interval = 500
NewInterval = 500

LFD     CON $10        'Linefeed character


' -----[ Program Code ]----------------------------------------------------

Main:

  GOSUB PollSensor                  'Was motion detected?
  GOSUB RetrieveInterval            'Retrieve units data

Timeout:
  SEROUT 16, 16468, [DEC1 SensorID, DEC1 ElementSize, DEC1 ElementCount, DEC1 bVibration, DEC5 Interval, LFD]
 GOTO Main

PollSensor:
    bVibration = IN0 ' Assign status of P0 to bMotion
  RETURN

RetrieveInterval:
    SERIN 16, 16468, Interval, Timeout, [DEC NewInterval]   'Retrieve interval
    IF NewInterval >= 10 AND NewInterval <= 60000 THEN
      Interval = NewInterval
    ENDIF
  RETURN