Skip to content

Commit fa1dffb

Browse files
committed
Fix DMC code recognition
1 parent cda45b1 commit fa1dffb

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

scene_send_code.c

+21-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Right will go to the save code dialog for the new code (if there is one)
1818
// These need to persist between processInput calls as the serial data comes in at random points
1919
static char curcode = 0;
2020
static bool first = false;
21+
static bool assert_next_colon = false; // Necessary for managing state
2122

2223
void processInput(void* context)
2324
{
@@ -26,61 +27,76 @@ void processInput(void* context)
2627

2728
char out[64];
2829
size_t recieved = 1;
29-
memset(out, 0, 64);
3030

3131
while(recieved > 0)
3232
{
33+
memset(out, 0, 64);
3334
recieved = furi_stream_buffer_receive(
3435
app->dmcomm_output_stream,
3536
&out,
3637
63,
3738
5);
38-
39+
3940
if(app->state->waitForCode && recieved > 0)
4041
{
4142
FURI_LOG_I(TAG, "DMComm Sent Data: %d <%s>", recieved, out);
4243
//FURI_LOG_I(TAG, "reading code");
4344
int l = strlen(out);
4445
for(int i = 0; i < l; i++)
4546
{
46-
if(out[i] == 't')
47+
if(out[i] == 't' || (assert_next_colon && out[i] != ':'))
4748
{ // reset for timeout and continue :(
49+
//FURI_LOG_I(TAG, "reset codes");
4850
curcode = 0;
4951
first = true;
5052
app->state->spackets = 0;
5153
app->state->rpackets = 0;
5254
furi_string_reset(app->state->r_code);
5355
furi_string_reset(app->state->s_code);
5456
}
55-
else if(out[i] == 's')
57+
if(assert_next_colon)
58+
assert_next_colon = false;
59+
if(out[i] == 's')
5660
{ // Starts an s code block
5761
curcode = 's';
62+
assert_next_colon = true;
63+
//FURI_LOG_I(TAG, "read s");
5864
if(furi_string_empty(app->state->s_code))
5965
{
6066
furi_string_push_back(app->state->s_code, app->state->current_code[0]);
6167
if(first)
6268
{
69+
//FURI_LOG_I(TAG, "s first");
6370
first = false;
6471
furi_string_push_back(app->state->s_code, '1');
6572
}
6673
else
74+
{
75+
//FURI_LOG_I(TAG, "s second");
6776
furi_string_push_back(app->state->s_code, '2');
77+
}
6878
}
6979
furi_string_push_back(app->state->s_code, '-');
7080
}
7181
else if(out[i] == 'r')
7282
{ // Starts an r code block
7383
curcode = 'r';
84+
assert_next_colon = true;
85+
//FURI_LOG_I(TAG, "read r");
7486
if(furi_string_empty(app->state->r_code))
7587
{
7688
furi_string_push_back(app->state->r_code, app->state->current_code[0]);
7789
if(first)
7890
{
91+
//FURI_LOG_I(TAG, "r first");
7992
first = false;
8093
furi_string_push_back(app->state->r_code, '1');
8194
}
8295
else
96+
{
97+
//FURI_LOG_I(TAG, "r second");
8398
furi_string_push_back(app->state->r_code, '2');
99+
}
84100
}
85101
furi_string_push_back(app->state->r_code, '-');
86102
}
@@ -91,7 +107,7 @@ void processInput(void* context)
91107
if(curcode == 'r')
92108
furi_string_push_back(app->state->r_code, out[i]);
93109
}
94-
else if(curcode != 0 && out[i] == ' ')
110+
else if(curcode != 0 && (out[i] == ' ' || out[i] == '\n'))
95111
{ // If we're reading a code, a space ends it
96112
if(curcode == 's')
97113
app->state->spackets++;

0 commit comments

Comments
 (0)