Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Open-Cube FW
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Cube
Open-Cube FW
Commits
5b8a4791
Commit
5b8a4791
authored
1 week ago
by
Václav Jelínek
Browse files
Options
Downloads
Patches
Plain Diff
Add option to set callback for esp bt message receive
parent
2bb77acc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/cube/esp_config.py
+23
-1
23 additions, 1 deletion
lib/cube/esp_config.py
with
23 additions
and
1 deletion
lib/cube/esp_config.py
+
23
−
1
View file @
5b8a4791
...
...
@@ -78,6 +78,7 @@ class Esp:
self
.
data_size
=
0
self
.
data_idx
=
0
self
.
new_message
=
False
self
.
bt_callback
=
None
# WIFI
self
.
wifi_indicators
=
tuple
([
False
]
*
Esp
.
NUM_INDICATORS
)
self
.
wifi_buttons
=
tuple
([
False
]
*
Esp
.
NUM_BUTTONS
)
...
...
@@ -131,6 +132,14 @@ class Esp:
else
:
self
.
binary_mode
=
False
def
bt_set_callback
(
self
,
callback
=
None
):
self
.
bt_callback
=
callback
def
bt_reset
(
self
):
self
.
bt_set_callback
(
callback
=
None
)
self
.
bt_set_binary
(
header
=
None
)
self
.
new_message
=
False
# --------------- ESP WIFI ---------------
def
make_bytes_from_bools
(
self
,
byte_len
:
int
,
bools
:
list
):
bytes_t
=
bytes
()
...
...
@@ -219,6 +228,7 @@ class Esp:
# -------------- ESP CONFIG --------------
def
reset
(
self
,
timeout
=
2000
):
self
.
bt_reset
()
self
.
cmd_start
()
self
.
esp_mode_prev
=
Esp
.
MODE_BT
self
.
flush
()
...
...
@@ -235,6 +245,7 @@ class Esp:
return
False
def
reset_non_blocking
(
self
):
self
.
bt_reset
()
self
.
cmd_start
()
self
.
esp_mode_prev
=
Esp
.
MODE_BT
self
.
flush
()
...
...
@@ -255,6 +266,7 @@ class Esp:
def
wifi
(
self
):
response
=
None
if
self
.
esp_mode
==
Esp
.
MODE_BT
:
self
.
bt_reset
()
self
.
esp_mode
=
Esp
.
MODE_WIFI
self
.
cmd_start
()
response
=
self
.
repeat_cmd
(
Esp
.
COM_WIFI
,
50
)
...
...
@@ -289,7 +301,7 @@ class Esp:
# ********** INTERNAL FUNCTIONS **********
def
deinit
(
self
):
self
.
uart_timer
.
deinit
()
self
.
bt_callback
=
None
self
.
uart
.
deinit
()
def
cmd_start
(
self
):
...
...
@@ -436,6 +448,14 @@ class Esp:
message
+=
self
.
i2b
(
csum
)
self
.
uart
.
write
(
message
)
def
bt_call
(
self
):
if
callable
(
self
.
bt_callback
):
try
:
self
.
bt_callback
(
self
)
except
Exception
as
e
:
print
(
"
Error in BT callback
"
)
print
(
e
)
# ************ UART HANDLER ************
def
config_message_receive
(
self
,
b_ch
):
#print(chr(struct.unpack('<B', b_ch)[0]), end="")
...
...
@@ -474,6 +494,7 @@ class Esp:
self
.
new_message
=
True
self
.
header_read
=
False
self
.
data_idx
=
0
self
.
bt_call
()
else
:
u_ch
=
struct
.
unpack
(
'
<B
'
,
b_ch
)[
0
]
if
u_ch
==
self
.
header
[
self
.
header_idx
]:
...
...
@@ -491,6 +512,7 @@ class Esp:
self
.
message
=
self
.
messageTmp
self
.
messageTmp
=
""
self
.
new_message
=
True
self
.
bt_call
()
else
:
self
.
messageTmp
=
self
.
messageTmp
+
character
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment