Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
card10
firmware
Commits
83b0e5ea
Commit
83b0e5ea
authored
Jan 26, 2021
by
schneider
Browse files
feat(micropython): Print exceptions to the screen
parent
b0e3d24c
Pipeline
#5288
passed with stages
in 1 minute and 48 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pycardium/mphalport.c
View file @
83b0e5ea
...
...
@@ -17,6 +17,7 @@
#include "py/mpprint.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
...
...
@@ -86,6 +87,41 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len)
epic_uart_write_str
(
str
,
len
);
}
static
char
exception_lines
[
2
][
80
];
static
bool
exception
;
static
size_t
exception_line_index
;
static
void
exception_feed
(
char
c
)
{
if
(
c
==
'\n'
)
{
exception_lines
[
1
][
exception_line_index
]
=
0
;
if
(
exception_lines
[
1
][
0
]
==
' '
)
{
memcpy
(
exception_lines
[
0
],
exception_lines
[
1
],
sizeof
(
exception_lines
[
0
]));
exception_line_index
=
0
;
}
else
{
exception
=
false
;
epic_disp_open
();
epic_disp_clear
(
0
);
epic_disp_print_adv
(
1
,
0
,
0
,
"Exception:"
,
0xF800
,
0x0000
);
epic_disp_print_adv
(
1
,
0
,
12
,
exception_lines
[
0
],
0xFFFF
,
0x0000
);
epic_disp_print_adv
(
1
,
0
,
40
,
exception_lines
[
1
],
0xF800
,
0x0000
);
epic_disp_update
();
}
}
else
{
if
(
exception_line_index
<
sizeof
(
exception_lines
[
0
])
-
1
)
{
exception_lines
[
1
][
exception_line_index
++
]
=
c
;
}
}
}
/* Send a string, but replace \n with \n\r */
void
mp_hal_stdout_tx_strn_cooked
(
const
char
*
str
,
size_t
len
)
{
...
...
@@ -93,6 +129,16 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len)
* Only print one line at a time. Insert `\r` between lines so
* they are properly displayed on the serial console.
*/
if
(
strncmp
(
str
,
"Traceback (most recent call last):
\n
"
,
len
)
==
0
)
{
exception
=
true
;
exception_line_index
=
0
;
}
else
if
(
exception
)
{
for
(
size_t
i
=
0
;
i
<
len
;
i
++
)
{
exception_feed
(
str
[
i
]);
}
}
size_t
i
,
last
=
0
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
(
str
[
i
]
==
'\n'
)
{
...
...
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