Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython-simulator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython-simulator
Commits
01f14ca9
Commit
01f14ca9
authored
Aug 12, 2019
by
George Wort
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Take into account time passed when debouncing button.
parent
3cfba335
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
source/microbit/microbitbutton.cpp
source/microbit/microbitbutton.cpp
+9
-6
No files found.
source/microbit/microbitbutton.cpp
View file @
01f14ca9
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
extern
"C"
{
extern
"C"
{
#include "lib/ticker.h"
#include "nrf_gpio.h"
#include "nrf_gpio.h"
#include "py/runtime.h"
#include "py/runtime.h"
#include "microbit/modmicrobit.h"
#include "microbit/modmicrobit.h"
...
@@ -115,17 +116,19 @@ enum PinTransition
...
@@ -115,17 +116,19 @@ enum PinTransition
};
};
static
PinTransition
update
(
const
microbit_pin_obj_t
*
pin
)
{
static
PinTransition
update
(
const
microbit_pin_obj_t
*
pin
)
{
int32_t
sigma_delta
=
1
+
(
MILLISECONDS_PER_MACRO_TICK
/
6
);
int32_t
sigma
=
sigmas
[
pin
->
number
&
7
];
int32_t
sigma
=
sigmas
[
pin
->
number
&
7
];
PinTransition
result
;
PinTransition
result
;
if
(
nrf_gpio_pin_read
(
pin
->
name
))
if
(
nrf_gpio_pin_read
(
pin
->
name
))
sigma
++
;
sigma
+=
sigma_delta
;
else
else
sigma
--
;
sigma
-=
sigma_delta
;
if
(
sigma
<
3
)
{
if
(
sigma
<
3
)
{
if
(
sigma
<
0
)
{
if
(
sigma
<
0
)
{
sigma
=
0
;
sigma
=
0
;
result
=
LOW_LOW
;
}
}
else
if
(
debounced_high
[
pin
->
number
&
7
])
{
if
(
debounced_high
[
pin
->
number
&
7
])
{
result
=
HIGH_LOW
;
result
=
HIGH_LOW
;
debounced_high
[
pin
->
number
&
7
]
=
false
;
debounced_high
[
pin
->
number
&
7
]
=
false
;
}
else
{
}
else
{
...
@@ -134,8 +137,8 @@ static PinTransition update(const microbit_pin_obj_t *pin) {
...
@@ -134,8 +137,8 @@ static PinTransition update(const microbit_pin_obj_t *pin) {
}
else
if
(
sigma
>
7
)
{
}
else
if
(
sigma
>
7
)
{
if
(
sigma
>
12
)
{
if
(
sigma
>
12
)
{
sigma
=
12
;
sigma
=
12
;
result
=
HIGH_HIGH
;
}
}
else
if
(
debounced_high
[
pin
->
number
&
7
])
{
if
(
debounced_high
[
pin
->
number
&
7
])
{
result
=
HIGH_HIGH
;
result
=
HIGH_HIGH
;
}
else
{
}
else
{
result
=
LOW_HIGH
;
result
=
LOW_HIGH
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment