forked from LairdCP/BL600-Applications
-
Notifications
You must be signed in to change notification settings - Fork 0
/
btn.button.led.test.sb
129 lines (113 loc) · 6.74 KB
/
btn.button.led.test.sb
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (c) 2013, Laird
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// SPDX-License-Identifier:ISC
//
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++ ++
// +++++ When UwTerminal downloads the app it will store it as a filenname ++
// +++++ which consists of all characters up to the first . and excluding it ++
// +++++ ++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//
// Simple development board button and LED test
// Tests the functionality of button 0, button 1, LED 0 and LED 1 on the development board
// DVK-BL600-V01
//
// 24/01/2013 Initial version
//
//******************************************************************************
//******************************************************************************
// Definitions
//******************************************************************************
//******************************************************************************
// Library Import
//******************************************************************************
// "$.lib.ble.sb"
//******************************************************************************
// Global Variable Declarations
//******************************************************************************
dim rc //Declare rc as integer variable
//******************************************************************************
// Function and Subroutine definitions
//******************************************************************************
//==============================================================================
//==============================================================================
sub AssertResCode(byval rc as integer,byval tag as integer)
if (rc!=0) then
print "Failed with ";integer.h' rc;" at tag ";tag;"\n"
endif
endsub
//==============================================================================
//==============================================================================
function button0release() //This function is called when the button 0 is released"
gpiowrite(18,0) //Turns LED 0 off
print "Button 0 has been released \n" //These lines are printed to the UART when the button is released
print "LED 0 should now go out \n\n"
endfunc 1
//==============================================================================
//==============================================================================
function button0press() //This function is called when the button 0 is pressed"
gpiowrite(18,1) //Turns LED 0 on
print "Button 0 has been pressed \n" //These lines are printed to the UART when the button is pressed
print "LED 0 will light while the button is pressed \n"
endfunc 1
//==============================================================================
//==============================================================================
function button1release() //This function is called when the button 1 is released"
gpiowrite(19,0) //Turns LED 1 off
print "Button 1 has been released \n" //These lines are printed to the UART when the button is released
print "LED 1 should now go out \n\n"
endfunc 1
//==============================================================================
//==============================================================================
function button1press() //This function is called when the button 1 is pressed"
gpiowrite(19,1) //Turns LED 1 on
print "Button 1 has been pressed \n" //These lines are printed to the UART when the button is pressed
print "LED 1 will light while the button is pressed \n"
endfunc 1
//******************************************************************************
// Handler definitions
//******************************************************************************
//******************************************************************************
// Equivalent to main() in C
//******************************************************************************
rc = gpiosetfunc(16,1,2) //Sets sio16 (Button 0) as a digital in with a weak pull up resistor
AssertResCode(rc,1000)
rc = gpiosetfunc(17,1,2) //Sets sio17 (Button 1) as a digital in with a weak pull up resistor
AssertResCode(rc,1010)
rc = gpiosetfunc(18,2,0) //Sets sio18 (LED0) as a digital out
AssertResCode(rc,1020)
rc = gpiosetfunc(19,2,0) //Sets sio19 (LED1) as a digital out
AssertResCode(rc,1030)
rc = gpiobindevent(0,16,0) //Binds a gpio transition high to an event. sio16 (button 0)
AssertResCode(rc,1040)
rc = gpiobindevent(1,16,1) //Binds a gpio transition low to an event. sio16 (button 0)
AssertResCode(rc,1050)
rc = gpiobindevent(2,17,0) //Binds a gpio transition high to an event. sio17 (button 1)
AssertResCode(rc,1060)
rc = gpiobindevent(3,17,1) //Binds a gpio transition low to an event. sio17 (button 1)
AssertResCode(rc,1070)
onevent evgpiochan0 call button0release //Detects when button 0 is released and calls the function
onevent evgpiochan1 call button0press //Detects when button 0 is pressed and calls the function
onevent evgpiochan2 call button1release //Detects when button 1 is released and calls the function
onevent evgpiochan3 call button1press //Detects when button 1 is pressed and calls the function
print "Ready to begin button and LED test \n" //These lines are printed to the UART when the program is run
print "Please press button 0 or button 1 \n\n"
//------------------------------------------------------------------------------
// Wait for a synchronous event.
// An application can have multiple <WaitEvent> statements
//------------------------------------------------------------------------------
waitevent //When program is run it waits here until an event is detected