PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
buttons.c
1 // io control
2 // =================================================================================================
3 //
4 //
5 // =================================================================================================
6 #include <propeller.h>
7 #include "badgewxtools.h"
8 
9 char touchpad_sensitivity = 4;
10 
11 // ------ Buttons function ------
12 unsigned char buttons() {
13 
14  // [L touch][L NAV left][L NAV ctr][L NAV right][R NAV left][R NAV ctr][R NAV right][R touch]
15  int btns = 0b00000000;
16  long tDecay[2]; // Declare tDecay variable
17 
18  input(NAV_COM_L); // Set common lines to inputs
19  input(NAV_COM_R);
20 
21  input(NAV_C); // Set pins to inputs
22  input(NAV_R);
23 
24  high(NAV_L); // Set pin high
25 
26  btns |= (input(NAV_COM_L) << 6);
27  btns |= (input(NAV_COM_R) << 3);
28 
29  input(NAV_L);
30  high(NAV_C);
31 
32  btns |= (input(NAV_COM_L) << 5);
33  btns |= (input(NAV_COM_R) << 2);
34 
35  input(NAV_C);
36  high(NAV_R);
37 
38  btns |= (input(NAV_COM_L) << 4);
39  btns |= (input(NAV_COM_R) << 1);
40 
41  input(NAV_R);
42 
43  high(NAV_TOUCH_L);
44  pause(1);
45  tDecay[1] = rc_time(NAV_TOUCH_L,1);
46 
47  high(NAV_TOUCH_R);
48  pause(1);
49  tDecay[0] = rc_time(NAV_TOUCH_R,1);
50 
51  btns |= ((tDecay[0] > touchpad_sensitivity ? 1 : 0) << 7);
52  btns |= ((tDecay[1] > touchpad_sensitivity ? 1 : 0) << 0);
53 
54  return btns;
55 }
56 
57 char button(char b) {
58  // Make sure b is 0-8
59  b = (b < 0 ? 0 : b);
60  b = (b > 7 ? 7 : b);
61 
62  int m = 1 << b;
63  return (buttons() & m) >> b;
64 }
65 
66 void touch_sensitivity_set (char sens) {
67  sens = (sens < 0 ? 0 : sens);
68  sens = (sens > 15 ? 15 : sens);
69  sens = 16 - sens;
70 
71 
72  touchpad_sensitivity = sens;
73 }
74 
75 
76 /*
77  Terms of Use: MIT License
78 
79  Permission is hereby granted, free of charge, to any person obtaining a copy of this
80  software and associated documentation files (the "Software"), to deal in the Software
81  without restriction, including without limitation the rights to use, copy, modify,
82  merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
83  permit persons to whom the Software is furnished to do so, subject to the following
84  conditions:
85 
86  The above copyright notice and this permission notice shall be included in all copies
87  or substantial portions of the Software.
88 
89  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
90  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
91  PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
92  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
93  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
94  OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
95 
96  */
badgewxtools.h
This library provides convenient functions for a variety of Parallax eBadge operations.
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition: libws2812.c:125
buttons
int buttons(void)
Gets the states of all seven touch buttons, and returns them in a value with 1s and 0s that correspon...
Definition: jm_touchpads.c:90
touch_sensitivity_set
void touch_sensitivity_set(char sens)
Used to set the RC time threshold used to detect a button press on the A and B touchpads on the back ...
Definition: buttons.c:66
rc_time
long rc_time(int pin, int state)
Set I/O pin to input and measure the time it takes a signal to transition from a start state to the o...
Definition: rcTime.c:19
input
int input(int pin)
Set an I/O pin to input and return 1 if pin detects a high signal, or 0 if it detects low.
Definition: input.c:19
high
void high(int pin)
Set an I/O pin to output-high.
Definition: high.c:19
button
int button(int pad)
Gets the state of a touch button (1) pressed, (0) not pressed. Numbering {6, 5, 4,...
Definition: jm_touchpads.c:70