2021-08-09 00:49:36 +08:00
|
|
|
/*
|
2021-08-28 01:42:19 +08:00
|
|
|
|
|
|
|
mui.c
|
|
|
|
|
2021-08-28 16:10:38 +08:00
|
|
|
Monochrome minimal user interface: Core library.
|
2021-08-28 01:42:19 +08:00
|
|
|
|
|
|
|
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
|
|
|
|
2021-09-05 17:09:02 +08:00
|
|
|
Copyright (c) 2021, olikraus@gmail.com
|
2021-08-28 01:42:19 +08:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2021-08-28 16:10:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
"mui.c" is a graphical user interface, developed as part of u8g2.
|
|
|
|
However "mui.c" is independent of u8g2 and can be used without u8g2 code.
|
|
|
|
The glue code between "mui.c" and u8g2 is located in "mui_u8g2.c"
|
2021-08-28 01:42:19 +08:00
|
|
|
|
2021-08-18 05:18:10 +08:00
|
|
|
c: cmd
|
|
|
|
i: ID0
|
|
|
|
j: ID1
|
|
|
|
xy: Position (x and y)
|
|
|
|
/text/: some text. The text can start with any delimiter (except 0 and |), but also has to end with the same delimiter
|
|
|
|
a: Single char argument
|
|
|
|
u: Single char argument with the user interface form number
|
|
|
|
|
|
|
|
"Uu" the interface --> no ID
|
2021-08-10 23:59:11 +08:00
|
|
|
|
2021-08-18 05:18:10 +08:00
|
|
|
Manual ID:
|
|
|
|
"Fijxy" Generic field: Places field with id ii at x/y --> ID=ij
|
|
|
|
"Bijxy/text/" Generic field (Button) with Text --> ID=ij
|
2021-08-28 16:10:38 +08:00
|
|
|
"Tiixya/text/" Generic field with argument and text --> ID = ij
|
|
|
|
"Aiixya"
|
2021-08-18 05:18:10 +08:00
|
|
|
|
|
|
|
Fixed ID:
|
|
|
|
"Si" the style --> ID=@i
|
|
|
|
"Lxy/labeltext/" Places a text at the specified position, field with - -> ID=.L, .l
|
|
|
|
"Gxyu/menutext/" Go to the specified menu without placing the user interface form on the stack --> ID=.G, .g
|
|
|
|
|
|
|
|
|
|
|
|
cijxy
|
|
|
|
cijxy/text/
|
|
|
|
cijxya/text/
|
|
|
|
|
|
|
|
cxy/text/
|
|
|
|
cxya/text/
|
2021-08-10 23:59:11 +08:00
|
|
|
|
2021-08-09 00:49:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-08-28 15:50:28 +08:00
|
|
|
#include "mui.h"
|
2021-08-09 00:49:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-08-28 15:30:19 +08:00
|
|
|
//#define mui_get_fds_char(s) ((uint8_t)(*s))
|
2021-08-09 00:49:36 +08:00
|
|
|
|
2021-09-05 23:41:50 +08:00
|
|
|
//#include <stdio.h>
|
|
|
|
//#define MUI_DEBUG(...) printf(__VA_ARGS__)
|
|
|
|
#define MUI_DEBUG(...)
|
2021-08-29 16:50:01 +08:00
|
|
|
|
|
|
|
uint8_t mui_get_fds_char(fds_t *s)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-29 16:50:01 +08:00
|
|
|
//return (uint8_t)(*s);
|
|
|
|
return (uint8_t)mui_pgm_read(s);
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
s must point to a valid command within FDS
|
|
|
|
*/
|
2021-09-07 05:51:26 +08:00
|
|
|
static size_t mui_fds_get_cmd_size_without_text(fds_t *s) MUI_NOINLINE;
|
|
|
|
static size_t mui_fds_get_cmd_size_without_text(fds_t *s)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
uint8_t c = mui_get_fds_char(s);
|
2021-08-16 06:06:52 +08:00
|
|
|
c &= 0xdf; /* consider upper and lower case */
|
2021-08-09 00:49:36 +08:00
|
|
|
switch(c)
|
|
|
|
{
|
2021-09-26 21:32:45 +08:00
|
|
|
case 'U': return 2; // User Form: CMD (1 Byte), Form-Id (1 Byte)
|
|
|
|
case 'S': return 2; // Style: CMD (1 Byte), Style Id (1 Byte)
|
|
|
|
case 'D': return 3; // Data within Text: CMD (1 Byte), ID (2 Bytes), Text (does not count here)
|
2022-01-08 02:46:39 +08:00
|
|
|
case 'Z': return 3; // Zero field without x, y, arg & text: CMD (1 Byte), ID (2 Bytes)
|
2021-09-26 21:32:45 +08:00
|
|
|
case 'F': return 5; // Field without arg & text: CMD (1 Byte), ID (2 Bytes), X, Y
|
|
|
|
case 'B': return 5; // Field with text: CMD (1 Byte), ID (2 Bytes), X, Y, Text (does not count here)
|
|
|
|
case 'T': return 6; // Field with arg & text: CMD (1 Byte), ID (2 Bytes), X, Y, Arg, Text (does not count here)
|
|
|
|
case 'A': return 6; // Field with arg (no text): CMD (1 Byte), ID (2 Bytes), X, Y, Arg, Text
|
|
|
|
case 'L': return 3; // Text Label: CMD (1 Byte), X, Y (same as 'B' but with fixed ID '.L', MUIF_LABEL, MUI_LABEL)
|
|
|
|
case 'G': return 4; // Goto Btutton: CMD (1Byte), X, Y, Arg, Text (same as 'T' but with fixed ID '.G', MUIF_GOTO, MUI_GOTO)
|
2021-08-09 00:49:36 +08:00
|
|
|
case 0: return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-26 21:32:45 +08:00
|
|
|
|
2021-08-09 00:49:36 +08:00
|
|
|
/*
|
2021-08-10 18:11:34 +08:00
|
|
|
s must point to the string delimiter start: first '/' for "B00ab/ok/"
|
|
|
|
- '/' actually is 0xff
|
2021-08-09 00:49:36 +08:00
|
|
|
- return the total size of the string, including the delimiter
|
|
|
|
- copies the content of the string ("ok") to the ui text buffer
|
2021-08-28 16:10:38 +08:00
|
|
|
|
2021-08-09 00:49:36 +08:00
|
|
|
*/
|
2021-08-29 16:50:01 +08:00
|
|
|
static size_t mui_fds_parse_text(mui_t *ui, fds_t *s)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
|
|
|
uint8_t i = 0;
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->delimiter = mui_get_fds_char(s);
|
2021-08-09 00:49:36 +08:00
|
|
|
uint8_t c;
|
2021-08-29 16:50:01 +08:00
|
|
|
fds_t *t = s;
|
2021-08-09 00:49:36 +08:00
|
|
|
|
2021-08-28 15:30:19 +08:00
|
|
|
//printf("mui_fds_parse_text del=%d\n", delimiter);
|
2021-08-28 15:40:10 +08:00
|
|
|
#ifdef MUI_CHECK_EOFDS
|
2021-08-10 18:11:34 +08:00
|
|
|
if ( ui->delimiter == 0 )
|
2021-08-09 00:49:36 +08:00
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
t++;
|
|
|
|
for( ;; )
|
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
c = mui_get_fds_char(t);
|
|
|
|
//printf("mui_fds_parse_text i=%d, c=%c\n", i, c);
|
2021-08-28 15:40:10 +08:00
|
|
|
#ifdef MUI_CHECK_EOFDS
|
2021-08-09 00:49:36 +08:00
|
|
|
if ( c == 0 )
|
|
|
|
break;
|
|
|
|
#endif
|
2021-08-10 18:11:34 +08:00
|
|
|
if ( c == ui->delimiter )
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
|
|
|
t++;
|
|
|
|
break;
|
|
|
|
}
|
2021-08-28 15:40:10 +08:00
|
|
|
if ( i < MUI_MAX_TEXT_LEN )
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
|
|
|
ui->text[i++] = c;
|
|
|
|
}
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
ui->text[i] = '\0' ;
|
|
|
|
return t-s;
|
|
|
|
}
|
|
|
|
|
2021-08-10 18:11:34 +08:00
|
|
|
/*
|
|
|
|
get the first token within a text argument.
|
|
|
|
The text argument may look like this:
|
|
|
|
"B00ab/banana|apple|peach|cherry/"
|
|
|
|
The outer delimiter "/" is not fixed and can be any char except "|" and "\0"
|
|
|
|
The inner delimiter "|" is fixed. It must be the pipe symbol.
|
|
|
|
This function will place "banana" into ui->text if the result is not 0
|
|
|
|
|
2021-08-28 15:30:19 +08:00
|
|
|
if ( mui_fds_first_token(ui) )
|
2021-08-10 18:11:34 +08:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
// handle token in ui->text
|
2021-08-28 15:30:19 +08:00
|
|
|
} while ( mui_fds_next_token(ui) )
|
2021-08-10 18:11:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
2021-08-28 16:10:38 +08:00
|
|
|
|
2021-08-28 15:40:10 +08:00
|
|
|
uint8_t mui_fds_first_token(mui_t *ui)
|
2021-08-10 18:11:34 +08:00
|
|
|
{
|
2021-08-10 18:20:27 +08:00
|
|
|
ui->token = ui->fds;
|
2021-09-07 05:51:26 +08:00
|
|
|
ui->token += mui_fds_get_cmd_size_without_text(ui->fds);
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->delimiter = mui_get_fds_char(ui->token);
|
2021-08-10 23:59:11 +08:00
|
|
|
ui->token++; // place ui->token on the first char of the token
|
2021-08-28 15:30:19 +08:00
|
|
|
return mui_fds_next_token(ui);
|
2021-08-10 18:11:34 +08:00
|
|
|
}
|
|
|
|
|
2022-01-05 06:34:16 +08:00
|
|
|
/*
|
|
|
|
The inner token delimiter "|" is fixed. It must be the pipe symbol.
|
|
|
|
*/
|
2021-08-28 15:40:10 +08:00
|
|
|
uint8_t mui_fds_next_token(mui_t *ui)
|
2021-08-10 18:11:34 +08:00
|
|
|
{
|
|
|
|
uint8_t c;
|
|
|
|
uint8_t i = 0;
|
2021-08-28 15:30:19 +08:00
|
|
|
// printf("mui_fds_next_token: call, ui->token=%p\n", ui->token);
|
2021-08-10 18:11:34 +08:00
|
|
|
for( ;; )
|
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
c = mui_get_fds_char(ui->token);
|
|
|
|
// printf("mui_fds_next_token: i=%d c=%c\n", i, c);
|
2021-08-28 15:40:10 +08:00
|
|
|
#ifdef MUI_CHECK_EOFDS
|
2021-08-10 18:11:34 +08:00
|
|
|
if ( c == 0 )
|
|
|
|
break;
|
|
|
|
#endif
|
2021-08-10 23:59:11 +08:00
|
|
|
if ( c == ui->delimiter )
|
2021-08-10 18:11:34 +08:00
|
|
|
break;
|
2021-08-10 23:59:11 +08:00
|
|
|
if ( c == '|' )
|
|
|
|
{
|
|
|
|
ui->token++; // place ui->token on the first char of the next token
|
|
|
|
break;
|
|
|
|
}
|
2021-08-10 18:11:34 +08:00
|
|
|
|
2021-08-28 15:40:10 +08:00
|
|
|
if ( i < MUI_MAX_TEXT_LEN )
|
2021-08-10 18:11:34 +08:00
|
|
|
{
|
|
|
|
ui->text[i++] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->token++;
|
|
|
|
}
|
|
|
|
ui->text[i] = '\0' ;
|
|
|
|
if ( i == 0 )
|
|
|
|
return 0; // no further token found
|
|
|
|
return 1; // token placed in ui->text
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-01-05 06:34:16 +08:00
|
|
|
find nth token ('|' delimiter), return 0 if n exceeds the number of tokens, 1 otherwise
|
2021-08-10 18:11:34 +08:00
|
|
|
the result is stored in ui->text
|
|
|
|
*/
|
2021-08-28 15:40:10 +08:00
|
|
|
uint8_t mui_fds_get_nth_token(mui_t *ui, uint8_t n)
|
2021-08-10 18:11:34 +08:00
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
// printf("mui_fds_get_nth_token: call, n=%d\n", n);
|
|
|
|
if ( mui_fds_first_token(ui) )
|
2021-08-10 18:11:34 +08:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if ( n == 0 )
|
2021-08-10 23:59:11 +08:00
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
// printf("mui_fds_get_nth_token: found");
|
2021-08-10 18:20:27 +08:00
|
|
|
return 1;
|
2021-08-10 23:59:11 +08:00
|
|
|
}
|
2021-08-10 18:11:34 +08:00
|
|
|
n--;
|
2021-08-28 15:30:19 +08:00
|
|
|
} while ( mui_fds_next_token(ui) );
|
2021-08-10 18:11:34 +08:00
|
|
|
}
|
2021-08-28 15:30:19 +08:00
|
|
|
//printf("mui_fds_get_nth_token: NOT found\n");
|
2021-08-10 18:20:27 +08:00
|
|
|
return 0;
|
2021-08-10 18:11:34 +08:00
|
|
|
}
|
|
|
|
|
2021-08-28 15:40:10 +08:00
|
|
|
uint8_t mui_fds_get_token_cnt(mui_t *ui)
|
2021-08-10 18:11:34 +08:00
|
|
|
{
|
|
|
|
uint8_t n = 0;
|
2021-08-28 15:30:19 +08:00
|
|
|
if ( mui_fds_first_token(ui) )
|
2021-08-10 18:11:34 +08:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
n++;
|
2021-08-28 15:30:19 +08:00
|
|
|
} while ( mui_fds_next_token(ui) );
|
2021-08-10 18:11:34 +08:00
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-08 02:46:39 +08:00
|
|
|
#define mui_fds_is_text(c) ( (c) == 'U' || (c) == 'S' || (c) == 'F' || (c) == 'A' || (c) == 'Z' ? 0 : 1 )
|
2021-08-09 00:49:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
s must point to a valid command within FDS
|
|
|
|
return
|
|
|
|
The complete length of the command (including any text part)
|
|
|
|
sideeffect:
|
|
|
|
Any existing text part will be copied into ui->text
|
2021-08-23 00:22:25 +08:00
|
|
|
ui->text will be assigned to empty string if there is no text argument
|
2021-08-09 00:49:36 +08:00
|
|
|
*/
|
2021-08-29 16:50:01 +08:00
|
|
|
static size_t mui_fds_get_cmd_size(mui_t *ui, fds_t *s) MUI_NOINLINE;
|
|
|
|
static size_t mui_fds_get_cmd_size(mui_t *ui, fds_t *s)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-09-07 05:51:26 +08:00
|
|
|
size_t l = mui_fds_get_cmd_size_without_text(s);
|
2021-08-28 15:30:19 +08:00
|
|
|
uint8_t c = mui_get_fds_char(s);
|
2021-08-23 00:22:25 +08:00
|
|
|
ui->text[0] = '\0' ; /* always reset the text buffer */
|
2021-08-28 15:30:19 +08:00
|
|
|
if ( mui_fds_is_text(c) )
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
l += mui_fds_parse_text(ui, s+l);
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-29 18:32:43 +08:00
|
|
|
/*
|
|
|
|
mui_Init() will setup the menu system but will not activate or display anything.
|
|
|
|
Use mui_GotoForm() after this command, then use mui_Draw() to draw the menu on a display.
|
|
|
|
*/
|
2021-08-29 16:50:01 +08:00
|
|
|
void mui_Init(mui_t *ui, void *graphics_data, fds_t *fds, muif_t *muif_tlist, size_t muif_tcnt)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-28 15:40:10 +08:00
|
|
|
memset(ui, 0, sizeof(mui_t));
|
2021-08-09 00:49:36 +08:00
|
|
|
ui->root_fds = fds;
|
2021-08-29 18:32:43 +08:00
|
|
|
//ui->current_form_fds = NULL; // not required, because there was a memset before
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->muif_tlist = muif_tlist;
|
|
|
|
ui->muif_tcnt = muif_tcnt;
|
2021-08-22 01:32:56 +08:00
|
|
|
ui->graphics_data = graphics_data;
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
2024-04-02 12:31:24 +08:00
|
|
|
static int mui_find_uif(mui_t *ui, uint8_t id0, uint8_t id1)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-09-07 05:51:26 +08:00
|
|
|
size_t i;
|
2021-08-28 15:30:19 +08:00
|
|
|
for( i = 0; i < ui->muif_tcnt; i++ )
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-29 16:50:01 +08:00
|
|
|
/*
|
2021-08-28 15:30:19 +08:00
|
|
|
if ( ui->muif_tlist[i].id0 == id0 )
|
|
|
|
if ( ui->muif_tlist[i].id1 == id1 )
|
2021-08-09 00:49:36 +08:00
|
|
|
return i;
|
2021-08-29 16:50:01 +08:00
|
|
|
*/
|
|
|
|
if ( muif_get_id0(ui->muif_tlist+i) == id0 )
|
|
|
|
if ( muif_get_id1(ui->muif_tlist+i) == id1 )
|
|
|
|
return i;
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
assumes a valid position in ui->fds and calculates all the other variables
|
2022-03-07 03:50:26 +08:00
|
|
|
some fields are always calculated like the ui->cmd and ui->len field
|
2021-08-22 01:32:56 +08:00
|
|
|
other member vars are calculated only if the return value is 1
|
|
|
|
will return 1 if the field id was found.
|
|
|
|
will return 0 if the field id was not found in uif or if ui->fds points to something else than a field
|
2021-08-09 00:49:36 +08:00
|
|
|
*/
|
2021-09-07 05:51:26 +08:00
|
|
|
static uint8_t mui_prepare_current_field(mui_t *ui) MUI_NOINLINE;
|
|
|
|
static uint8_t mui_prepare_current_field(mui_t *ui)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-29 16:50:01 +08:00
|
|
|
int muif_tidx;
|
2021-08-16 06:06:52 +08:00
|
|
|
|
|
|
|
ui->uif = NULL;
|
|
|
|
ui->dflags = 0;
|
|
|
|
ui->id0 = 0;
|
|
|
|
ui->id1 = 0;
|
2021-08-18 05:18:10 +08:00
|
|
|
ui->arg = 0;
|
2021-08-16 06:06:52 +08:00
|
|
|
|
|
|
|
/* calculate the length of the command and copy the text argument */
|
2021-08-23 00:22:25 +08:00
|
|
|
/* this will also clear the text in cases where there is no text argument */
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->len = mui_fds_get_cmd_size(ui, ui->fds);
|
2021-08-28 18:44:34 +08:00
|
|
|
//printf("mui_prepare_current_field len=%d\n", ui->len);
|
2021-08-16 06:06:52 +08:00
|
|
|
|
2021-08-09 00:49:36 +08:00
|
|
|
/* get the command and check whether end of form is reached */
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->cmd = mui_get_fds_char(ui->fds);
|
2021-09-05 23:41:50 +08:00
|
|
|
//printf("mui_prepare_current_field cmd='%c' len=%d\n", ui->cmd, ui->len);
|
2021-08-16 06:06:52 +08:00
|
|
|
|
2021-08-22 01:32:56 +08:00
|
|
|
/* Copy the cmd also to second id value. This is required for some commands, others will overwrite this below */
|
2021-08-16 06:06:52 +08:00
|
|
|
ui->id1 = ui->cmd;
|
|
|
|
|
|
|
|
/* now make the command uppercase so that both, upper and lower case are considered */
|
|
|
|
ui->cmd &= 0xdf; /* consider upper and lower case */
|
|
|
|
|
|
|
|
if ( ui->cmd == 'U' || ui->cmd == 0 )
|
2021-08-22 01:32:56 +08:00
|
|
|
return 0;
|
2021-08-16 06:06:52 +08:00
|
|
|
|
|
|
|
/* calculate the dynamic flags */
|
|
|
|
if ( ui->fds == ui->cursor_focus_fds )
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->dflags |= MUIF_DFLAG_IS_CURSOR_FOCUS;
|
2021-08-16 06:06:52 +08:00
|
|
|
if ( ui->fds == ui->touch_focus_fds )
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->dflags |= MUIF_DFLAG_IS_TOUCH_FOCUS;
|
2021-08-16 06:06:52 +08:00
|
|
|
|
2021-08-09 00:49:36 +08:00
|
|
|
|
2021-08-16 06:06:52 +08:00
|
|
|
/* get the id0 and id1 values */
|
2021-08-27 16:09:34 +08:00
|
|
|
if ( ui->cmd == 'F' || ui->cmd == 'B' || ui->cmd == 'T' || ui->cmd == 'A' )
|
2021-08-16 06:06:52 +08:00
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->id0 = mui_get_fds_char(ui->fds+1);
|
|
|
|
ui->id1 = mui_get_fds_char(ui->fds+2);
|
|
|
|
ui->x = mui_get_fds_char(ui->fds+3);
|
|
|
|
ui->y = mui_get_fds_char(ui->fds+4);
|
2021-08-27 16:09:34 +08:00
|
|
|
if ( ui->cmd == 'A' || ui->cmd == 'T' )
|
2021-08-18 05:18:10 +08:00
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->arg = mui_get_fds_char(ui->fds+5);
|
2021-08-18 05:18:10 +08:00
|
|
|
}
|
2021-08-16 06:06:52 +08:00
|
|
|
}
|
2022-01-08 02:46:39 +08:00
|
|
|
else if ( ui->cmd == 'D' || ui->cmd == 'Z' )
|
2021-09-26 17:16:14 +08:00
|
|
|
{
|
|
|
|
ui->id0 = mui_get_fds_char(ui->fds+1);
|
|
|
|
ui->id1 = mui_get_fds_char(ui->fds+2);
|
|
|
|
}
|
2021-08-16 06:06:52 +08:00
|
|
|
else if ( ui->cmd == 'S' )
|
|
|
|
{
|
2021-08-28 18:44:34 +08:00
|
|
|
ui->id0 = 'S';
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->id1 = mui_get_fds_char(ui->fds+1);
|
2021-08-16 06:06:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-18 05:18:10 +08:00
|
|
|
ui->id0 = '.';
|
2021-08-16 06:06:52 +08:00
|
|
|
/* note that ui->id1 contains the original cmd value */
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->x = mui_get_fds_char(ui->fds+1);
|
|
|
|
ui->y = mui_get_fds_char(ui->fds+2);
|
2021-08-18 05:18:10 +08:00
|
|
|
if ( ui->cmd == 'G' || ui->cmd == 'M' ) /* this is also true for 'g' or 'm' */
|
2021-08-16 06:06:52 +08:00
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->arg = mui_get_fds_char(ui->fds+3);
|
2021-08-16 06:06:52 +08:00
|
|
|
}
|
|
|
|
}
|
2021-09-05 23:41:50 +08:00
|
|
|
|
|
|
|
//MUI_DEBUG("mui_prepare_current_field cmd='%c' len=%d arg=%d\n", ui->cmd, ui->len, ui->arg);
|
|
|
|
|
2021-08-16 06:06:52 +08:00
|
|
|
|
2021-08-22 01:32:56 +08:00
|
|
|
/* find the field */
|
2021-08-28 15:30:19 +08:00
|
|
|
muif_tidx = mui_find_uif(ui, ui->id0, ui->id1);
|
|
|
|
//printf("mui_prepare_current_field: muif_tidx=%d\n", muif_tidx);
|
|
|
|
if ( muif_tidx >= 0 )
|
2021-08-16 06:06:52 +08:00
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->uif = ui->muif_tlist + muif_tidx;
|
2021-08-22 01:32:56 +08:00
|
|
|
return 1;
|
2021-08-16 06:06:52 +08:00
|
|
|
}
|
2021-08-22 01:32:56 +08:00
|
|
|
return 0;
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
2021-08-27 16:09:34 +08:00
|
|
|
/*
|
|
|
|
assumes that ui->fds has been assigned correctly
|
|
|
|
and that ui->target_fds and ui->tmp_fds had been cleared if required
|
|
|
|
|
2021-08-28 15:30:19 +08:00
|
|
|
Usually do not call this function directly, instead use mui_loop_over_form
|
2021-08-27 16:09:34 +08:00
|
|
|
|
|
|
|
*/
|
2021-08-27 19:07:26 +08:00
|
|
|
|
2021-09-07 05:51:26 +08:00
|
|
|
static void mui_inner_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui)) MUI_NOINLINE;
|
|
|
|
static void mui_inner_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui))
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
|
|
|
uint8_t cmd;
|
2021-09-05 23:41:50 +08:00
|
|
|
|
|
|
|
//MUI_DEBUG("mui_inner_loop_over_form start %p\n", task);
|
2021-08-22 01:32:56 +08:00
|
|
|
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->fds += mui_fds_get_cmd_size(ui, ui->fds); // skip the first entry, it is U always
|
2021-08-09 00:49:36 +08:00
|
|
|
for(;;)
|
|
|
|
{
|
2021-08-28 18:44:34 +08:00
|
|
|
//printf("fds=%p *fds='%c'\n", ui->fds, ui->fds[0]);
|
2021-08-09 00:49:36 +08:00
|
|
|
/* get the command and check whether end of form is reached */
|
2021-08-28 15:30:19 +08:00
|
|
|
cmd = mui_get_fds_char(ui->fds);
|
2021-08-09 00:49:36 +08:00
|
|
|
if ( cmd == 'U' || cmd == 0 )
|
|
|
|
break;
|
2022-03-07 03:50:26 +08:00
|
|
|
if ( mui_prepare_current_field(ui) ) /* side effect: calculate ui->len */
|
2021-08-23 00:22:25 +08:00
|
|
|
if ( task(ui) ) /* call the task, which was provided as argument to this function */
|
2021-09-05 23:41:50 +08:00
|
|
|
{
|
|
|
|
//MUI_DEBUG("mui_inner_loop_over_form break by task\n");
|
2021-08-23 00:22:25 +08:00
|
|
|
break;
|
2021-09-05 23:41:50 +08:00
|
|
|
}
|
2021-08-09 00:49:36 +08:00
|
|
|
ui->fds += ui->len;
|
|
|
|
}
|
2021-09-05 23:41:50 +08:00
|
|
|
|
|
|
|
//MUI_DEBUG("mui_inner_loop_over_form end %p\n", task);
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
2021-09-07 05:51:26 +08:00
|
|
|
static void mui_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui)) MUI_NOINLINE;
|
|
|
|
static void mui_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui))
|
2021-08-27 16:09:34 +08:00
|
|
|
{
|
2021-08-29 18:32:43 +08:00
|
|
|
if ( mui_IsFormActive(ui) == 0 )
|
2021-08-27 16:09:34 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
ui->fds = ui->current_form_fds;
|
|
|
|
ui->target_fds = NULL;
|
|
|
|
ui->tmp_fds = NULL;
|
|
|
|
|
2021-08-28 15:30:19 +08:00
|
|
|
mui_inner_loop_over_form(ui, task);
|
2021-08-27 16:09:34 +08:00
|
|
|
}
|
|
|
|
|
2021-08-15 19:29:07 +08:00
|
|
|
/*
|
|
|
|
n is the form number
|
|
|
|
*/
|
2024-04-02 12:31:24 +08:00
|
|
|
static fds_t *mui_find_form(mui_t *ui, uint8_t n)
|
2021-08-15 19:29:07 +08:00
|
|
|
{
|
2021-08-29 16:50:01 +08:00
|
|
|
fds_t *fds = ui->root_fds;
|
2021-08-15 19:29:07 +08:00
|
|
|
uint8_t cmd;
|
|
|
|
|
|
|
|
for( ;; )
|
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
cmd = mui_get_fds_char(fds);
|
2021-08-15 19:29:07 +08:00
|
|
|
if ( cmd == 0 )
|
|
|
|
break;
|
|
|
|
if ( cmd == 'U' )
|
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
if ( mui_get_fds_char(fds+1) == n )
|
2021-08-15 22:23:17 +08:00
|
|
|
{
|
2021-08-15 19:29:07 +08:00
|
|
|
return fds;
|
2021-08-15 22:23:17 +08:00
|
|
|
}
|
2021-08-15 19:29:07 +08:00
|
|
|
/* not found, just coninue */
|
|
|
|
}
|
|
|
|
|
2021-08-28 15:30:19 +08:00
|
|
|
fds += mui_fds_get_cmd_size(ui, fds);
|
2021-08-15 19:29:07 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-08-28 15:30:19 +08:00
|
|
|
/* === task procedures (arguments for mui_loop_over_form) === */
|
2021-08-23 00:22:25 +08:00
|
|
|
/* ui->fds contains the current field */
|
2021-08-09 00:49:36 +08:00
|
|
|
|
2024-04-02 12:31:24 +08:00
|
|
|
static uint8_t mui_task_draw(mui_t *ui)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-28 15:40:10 +08:00
|
|
|
//printf("mui_task_draw fds=%p uif=%p text=%s\n", ui->fds, ui->uif, ui->text);
|
2021-08-28 16:43:44 +08:00
|
|
|
muif_get_cb(ui->uif)(ui, MUIF_MSG_DRAW);
|
2021-08-23 00:22:25 +08:00
|
|
|
return 0; /* continue with the loop */
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
2024-04-02 12:31:24 +08:00
|
|
|
static uint8_t mui_task_form_start(mui_t *ui)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-28 16:43:44 +08:00
|
|
|
muif_get_cb(ui->uif)(ui, MUIF_MSG_FORM_START);
|
2021-08-23 00:22:25 +08:00
|
|
|
return 0; /* continue with the loop */
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
2024-04-02 12:31:24 +08:00
|
|
|
static uint8_t mui_task_form_end(mui_t *ui)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-28 16:43:44 +08:00
|
|
|
muif_get_cb(ui->uif)(ui, MUIF_MSG_FORM_END);
|
2021-08-23 00:22:25 +08:00
|
|
|
return 0; /* continue with the loop */
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
2021-09-07 05:51:26 +08:00
|
|
|
static uint8_t mui_uif_is_cursor_selectable(mui_t *ui) MUI_NOINLINE;
|
|
|
|
static uint8_t mui_uif_is_cursor_selectable(mui_t *ui)
|
|
|
|
{
|
|
|
|
if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2021-08-09 00:49:36 +08:00
|
|
|
|
2024-04-02 12:31:24 +08:00
|
|
|
static uint8_t mui_task_find_prev_cursor_uif(mui_t *ui)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-09-07 05:51:26 +08:00
|
|
|
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
|
|
|
if ( mui_uif_is_cursor_selectable(ui) )
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
|
|
|
if ( ui->fds == ui->cursor_focus_fds )
|
|
|
|
{
|
|
|
|
ui->target_fds = ui->tmp_fds;
|
2021-08-23 00:22:25 +08:00
|
|
|
return 1; /* stop looping */
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
ui->tmp_fds = ui->fds;
|
|
|
|
}
|
2021-08-23 00:22:25 +08:00
|
|
|
return 0; /* continue with the loop */
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
2024-04-02 12:31:24 +08:00
|
|
|
static uint8_t mui_task_find_first_cursor_uif(mui_t *ui)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-09-07 05:51:26 +08:00
|
|
|
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
|
|
|
if ( mui_uif_is_cursor_selectable(ui) )
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-23 00:22:25 +08:00
|
|
|
// if ( ui->target_fds == NULL )
|
|
|
|
// {
|
2021-08-09 00:49:36 +08:00
|
|
|
ui->target_fds = ui->fds;
|
2021-08-23 00:22:25 +08:00
|
|
|
return 1; /* stop looping */
|
|
|
|
// }
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
2021-08-23 00:22:25 +08:00
|
|
|
return 0; /* continue with the loop */
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
2024-04-02 12:31:24 +08:00
|
|
|
static uint8_t mui_task_find_last_cursor_uif(mui_t *ui)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-09-07 05:51:26 +08:00
|
|
|
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
|
|
|
if ( mui_uif_is_cursor_selectable(ui) )
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-23 00:22:25 +08:00
|
|
|
//ui->cursor_focus_position++;
|
2021-08-09 00:49:36 +08:00
|
|
|
ui->target_fds = ui->fds;
|
|
|
|
}
|
2021-08-23 00:22:25 +08:00
|
|
|
return 0; /* continue with the loop */
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
2024-04-02 12:31:24 +08:00
|
|
|
static uint8_t mui_task_find_next_cursor_uif(mui_t *ui)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-09-07 05:51:26 +08:00
|
|
|
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
|
|
|
if ( mui_uif_is_cursor_selectable(ui) )
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
|
|
|
if ( ui->tmp_fds != NULL )
|
|
|
|
{
|
|
|
|
ui->target_fds = ui->fds;
|
|
|
|
ui->tmp_fds = NULL;
|
2021-08-23 00:22:25 +08:00
|
|
|
return 1; /* stop looping */
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
if ( ui->fds == ui->cursor_focus_fds )
|
|
|
|
{
|
|
|
|
ui->tmp_fds = ui->fds;
|
|
|
|
}
|
|
|
|
}
|
2021-08-23 00:22:25 +08:00
|
|
|
return 0; /* continue with the loop */
|
|
|
|
}
|
|
|
|
|
2024-04-02 12:31:24 +08:00
|
|
|
static uint8_t mui_task_get_current_cursor_focus_position(mui_t *ui)
|
2021-08-23 00:22:25 +08:00
|
|
|
{
|
2021-09-07 05:51:26 +08:00
|
|
|
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
|
|
|
if ( mui_uif_is_cursor_selectable(ui) )
|
2021-08-23 00:22:25 +08:00
|
|
|
{
|
|
|
|
if ( ui->fds == ui->cursor_focus_fds )
|
|
|
|
return 1; /* stop looping */
|
|
|
|
ui->tmp8++;
|
|
|
|
}
|
|
|
|
return 0; /* continue with the loop */
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
2024-04-02 12:31:24 +08:00
|
|
|
static uint8_t mui_task_read_nth_selectable_field(mui_t *ui)
|
2021-08-27 16:09:34 +08:00
|
|
|
{
|
2021-09-07 05:51:26 +08:00
|
|
|
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
|
|
|
if ( mui_uif_is_cursor_selectable(ui) )
|
2021-08-27 16:09:34 +08:00
|
|
|
{
|
|
|
|
if ( ui->tmp8 == 0 )
|
|
|
|
return 1; /* stop looping */
|
|
|
|
ui->tmp8--;
|
|
|
|
}
|
|
|
|
return 0; /* continue with the loop */
|
|
|
|
}
|
|
|
|
|
2024-04-02 12:31:24 +08:00
|
|
|
static uint8_t mui_task_find_execute_on_select_field(mui_t *ui)
|
2022-03-07 03:50:26 +08:00
|
|
|
{
|
|
|
|
if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_EXECUTE_ON_SELECT )
|
|
|
|
{
|
|
|
|
ui->target_fds = ui->fds;
|
|
|
|
return 1; /* stop looping */
|
|
|
|
}
|
|
|
|
return 0; /* continue with the loop */
|
|
|
|
}
|
|
|
|
|
2021-08-27 16:09:34 +08:00
|
|
|
|
2021-08-09 00:49:36 +08:00
|
|
|
/* === utility functions for the user API === */
|
|
|
|
|
2021-09-07 05:51:26 +08:00
|
|
|
static uint8_t mui_send_cursor_msg(mui_t *ui, uint8_t msg) MUI_NOINLINE;
|
|
|
|
static uint8_t mui_send_cursor_msg(mui_t *ui, uint8_t msg)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
|
|
|
if ( ui->cursor_focus_fds )
|
|
|
|
{
|
|
|
|
ui->fds = ui->cursor_focus_fds;
|
2021-08-28 15:30:19 +08:00
|
|
|
if ( mui_prepare_current_field(ui) )
|
2021-09-05 05:25:20 +08:00
|
|
|
return muif_get_cb(ui->uif)(ui, msg);
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
2021-09-05 05:25:20 +08:00
|
|
|
return 0; /* not called, msg not handled */
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* === user API === */
|
|
|
|
|
2021-08-23 00:22:25 +08:00
|
|
|
/*
|
|
|
|
returns the field pos which has the current focus
|
|
|
|
If the first selectable field has the focus, then 0 will be returned
|
|
|
|
Unselectable fields (for example labels) are skipped by this count.
|
|
|
|
If no fields are selectable, then 0 is returned
|
2022-01-10 02:53:04 +08:00
|
|
|
|
|
|
|
The return value can be used as last argument for mui_EnterForm or mui_GotoForm
|
|
|
|
|
|
|
|
WARNING: This function will destroy current fds and field information.
|
2021-08-23 00:22:25 +08:00
|
|
|
*/
|
2021-08-28 15:40:10 +08:00
|
|
|
uint8_t mui_GetCurrentCursorFocusPosition(mui_t *ui)
|
2021-08-23 00:22:25 +08:00
|
|
|
{
|
2022-01-10 02:53:04 +08:00
|
|
|
//fds_t *fds = ui->fds;
|
|
|
|
ui->tmp8 = 0;
|
2021-08-28 15:40:10 +08:00
|
|
|
mui_loop_over_form(ui, mui_task_get_current_cursor_focus_position);
|
2022-01-10 02:53:04 +08:00
|
|
|
//ui->fds = fds;
|
2021-08-23 00:22:25 +08:00
|
|
|
return ui->tmp8;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-28 15:40:10 +08:00
|
|
|
void mui_Draw(mui_t *ui)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-28 15:40:10 +08:00
|
|
|
mui_loop_over_form(ui, mui_task_draw);
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
2024-04-02 12:31:24 +08:00
|
|
|
static void mui_next_field(mui_t *ui)
|
2021-08-22 00:08:28 +08:00
|
|
|
{
|
2021-08-28 15:40:10 +08:00
|
|
|
mui_loop_over_form(ui, mui_task_find_next_cursor_uif);
|
2021-08-23 00:22:25 +08:00
|
|
|
// ui->cursor_focus_position++;
|
2021-08-22 00:08:28 +08:00
|
|
|
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
|
|
|
|
if ( ui->target_fds == NULL )
|
|
|
|
{
|
2021-08-28 15:40:10 +08:00
|
|
|
mui_loop_over_form(ui, mui_task_find_first_cursor_uif);
|
2021-08-22 00:08:28 +08:00
|
|
|
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
|
2021-08-23 00:22:25 +08:00
|
|
|
// ui->cursor_focus_position = 0;
|
2021-08-22 00:08:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-26 17:16:14 +08:00
|
|
|
|
2022-01-05 06:34:16 +08:00
|
|
|
/*
|
|
|
|
this function will overwrite the ui field related member variables
|
|
|
|
nth_token can be 0 if the fiel text is not a option list
|
|
|
|
the result is stored in ui->text
|
|
|
|
|
|
|
|
token delimiter is '|' (pipe symbol)
|
|
|
|
|
|
|
|
fds: The start of a field (MUI_DATA)
|
|
|
|
nth_token: The position of the token, which should be returned
|
|
|
|
*/
|
2021-09-26 21:32:45 +08:00
|
|
|
uint8_t mui_GetSelectableFieldTextOption(mui_t *ui, fds_t *fds, uint8_t nth_token)
|
2021-09-26 17:16:14 +08:00
|
|
|
{
|
|
|
|
fds_t *fds_backup = ui->fds; // backup the current fds, so that this function can be called inside a task loop
|
|
|
|
int len = ui->len; // backup length of the current command, 26 sep 2021: probably this is not required any more
|
2021-09-26 21:32:45 +08:00
|
|
|
uint8_t is_found;
|
2021-09-26 17:16:14 +08:00
|
|
|
|
|
|
|
ui->fds = fds;
|
|
|
|
// at this point ui->fds contains the field which contains the tokens
|
|
|
|
// now get the opion string out of the text field. nth_token can be 0 if this is no opion string
|
2021-09-26 21:32:45 +08:00
|
|
|
is_found = mui_fds_get_nth_token(ui, nth_token); // return value is ignored here
|
2021-09-26 17:16:14 +08:00
|
|
|
|
|
|
|
ui->fds = fds_backup; // restore the previous fds position
|
|
|
|
ui->len = len;
|
|
|
|
// result is stored in ui->text
|
2021-09-26 21:32:45 +08:00
|
|
|
return is_found;
|
2021-09-26 17:16:14 +08:00
|
|
|
}
|
2021-08-27 16:09:34 +08:00
|
|
|
|
2021-09-26 17:16:14 +08:00
|
|
|
uint8_t mui_GetSelectableFieldOptionCnt(mui_t *ui, fds_t *fds)
|
|
|
|
{
|
|
|
|
fds_t *fds_backup = ui->fds; // backup the current fds, so that this function can be called inside a task loop
|
|
|
|
int len = ui->len; // backup length of the current command 26 sep 2021: probably this is not required any more
|
|
|
|
uint8_t cnt = 0;
|
|
|
|
|
|
|
|
ui->fds = fds;
|
|
|
|
// at this point ui->fds contains the field which contains the tokens
|
|
|
|
// now get the opion string out of the text field. nth_token can be 0 if this is no opion string
|
|
|
|
cnt = mui_fds_get_token_cnt(ui);
|
|
|
|
|
|
|
|
ui->fds = fds_backup; // restore the previous fds position
|
|
|
|
ui->len = len;
|
|
|
|
// result is stored in ui->text
|
|
|
|
return cnt;
|
|
|
|
}
|
2021-09-05 23:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-09-07 05:51:26 +08:00
|
|
|
//static void mui_send_cursor_enter_msg(mui_t *ui) MUI_NOINLINE;
|
2021-09-26 21:32:45 +08:00
|
|
|
static uint8_t mui_send_cursor_enter_msg(mui_t *ui)
|
2021-09-07 05:51:26 +08:00
|
|
|
{
|
|
|
|
ui->is_mud = 0;
|
2021-09-26 21:32:45 +08:00
|
|
|
return mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_ENTER);
|
2021-09-07 05:51:26 +08:00
|
|
|
}
|
|
|
|
|
2021-08-23 00:22:25 +08:00
|
|
|
/*
|
|
|
|
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
|
2021-08-29 18:32:43 +08:00
|
|
|
mui_EnterForm is similar to mui_GotoForm and differes only in the second argument (which is the form id instead of the fds pointer)
|
2021-08-23 00:22:25 +08:00
|
|
|
*/
|
2021-08-29 18:32:43 +08:00
|
|
|
void mui_EnterForm(mui_t *ui, fds_t *fds, uint8_t initial_cursor_position)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-29 18:32:43 +08:00
|
|
|
/* exit any previous form, will not do anything if there is no current form */
|
|
|
|
mui_LeaveForm(ui);
|
|
|
|
|
2021-08-09 00:49:36 +08:00
|
|
|
/* clean focus fields */
|
|
|
|
ui->touch_focus_fds = NULL;
|
|
|
|
ui->cursor_focus_fds = NULL;
|
|
|
|
|
2021-09-20 02:36:41 +08:00
|
|
|
/* reset all the scoll values */
|
|
|
|
ui->form_scroll_top = 0;
|
|
|
|
ui->form_scroll_visible = 0;
|
|
|
|
ui->form_scroll_total = 0;
|
|
|
|
|
2021-08-29 18:32:43 +08:00
|
|
|
/* assign the form, which should be entered */
|
|
|
|
ui->current_form_fds = fds;
|
|
|
|
|
2021-08-09 00:49:36 +08:00
|
|
|
/* inform all fields that we start a new form */
|
2022-01-10 02:53:04 +08:00
|
|
|
MUI_DEBUG("mui_EnterForm: form_start, initial_cursor_position=%d\n", initial_cursor_position);
|
2021-08-28 15:40:10 +08:00
|
|
|
mui_loop_over_form(ui, mui_task_form_start);
|
2021-08-09 00:49:36 +08:00
|
|
|
|
|
|
|
/* assign initional cursor focus */
|
2021-09-05 23:41:50 +08:00
|
|
|
MUI_DEBUG("mui_EnterForm: find_first_cursor_uif\n");
|
2021-08-28 15:40:10 +08:00
|
|
|
mui_loop_over_form(ui, mui_task_find_first_cursor_uif);
|
2021-08-23 05:35:20 +08:00
|
|
|
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
|
2021-09-05 23:41:50 +08:00
|
|
|
MUI_DEBUG("mui_EnterForm: find_first_cursor_uif target_fds=%p\n", ui->target_fds);
|
2021-08-22 00:08:28 +08:00
|
|
|
|
|
|
|
while( initial_cursor_position > 0 )
|
|
|
|
{
|
2021-09-05 23:41:50 +08:00
|
|
|
mui_NextField(ui); // mui_next_field(ui) is not sufficient in case of scrolling
|
2021-08-22 00:08:28 +08:00
|
|
|
initial_cursor_position--;
|
|
|
|
}
|
|
|
|
|
2021-09-26 21:32:45 +08:00
|
|
|
while( mui_send_cursor_enter_msg(ui) == 255 )
|
|
|
|
{
|
|
|
|
mui_NextField(ui); // mui_next_field(ui) is not sufficient in case of scrolling
|
|
|
|
}
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* input: current_form_fds */
|
2021-08-23 00:22:25 +08:00
|
|
|
/*
|
|
|
|
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
|
|
|
|
*/
|
2021-08-28 15:40:10 +08:00
|
|
|
void mui_LeaveForm(mui_t *ui)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-08-29 18:32:43 +08:00
|
|
|
if ( mui_IsFormActive(ui) == 0 )
|
|
|
|
return;
|
|
|
|
|
2021-08-28 15:30:19 +08:00
|
|
|
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
|
2021-08-09 00:49:36 +08:00
|
|
|
ui->cursor_focus_fds = NULL;
|
|
|
|
|
|
|
|
/* inform all fields that we leave the form */
|
2021-09-05 23:41:50 +08:00
|
|
|
MUI_DEBUG("mui_LeaveForm: form_end\n");
|
2021-08-28 15:40:10 +08:00
|
|
|
mui_loop_over_form(ui, mui_task_form_end);
|
2021-08-22 01:32:56 +08:00
|
|
|
ui->current_form_fds = NULL;
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
2021-08-15 19:29:07 +08:00
|
|
|
/* 0: error, form not found */
|
2021-08-23 00:22:25 +08:00
|
|
|
/*
|
|
|
|
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
|
|
|
|
*/
|
2021-08-28 15:40:10 +08:00
|
|
|
uint8_t mui_GotoForm(mui_t *ui, uint8_t form_id, uint8_t initial_cursor_position)
|
2021-08-15 19:29:07 +08:00
|
|
|
{
|
2021-08-29 16:50:01 +08:00
|
|
|
fds_t *fds = mui_find_form(ui, form_id);
|
2021-08-15 19:29:07 +08:00
|
|
|
if ( fds == NULL )
|
|
|
|
return 0;
|
2021-08-29 18:32:43 +08:00
|
|
|
/* EnterForm will also leave any previous form */
|
|
|
|
mui_EnterForm(ui, fds, initial_cursor_position);
|
2021-08-15 19:29:07 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-08-28 15:40:10 +08:00
|
|
|
void mui_SaveForm(mui_t *ui)
|
2021-08-23 00:22:25 +08:00
|
|
|
{
|
2021-08-29 18:32:43 +08:00
|
|
|
if ( mui_IsFormActive(ui) == 0 )
|
2021-08-23 00:22:25 +08:00
|
|
|
return;
|
2021-08-29 18:32:43 +08:00
|
|
|
|
2021-09-26 17:16:14 +08:00
|
|
|
ui->last_form_fds = ui->cursor_focus_fds;
|
2021-08-28 15:30:19 +08:00
|
|
|
ui->last_form_id = mui_get_fds_char(ui->current_form_fds+1);
|
|
|
|
ui->last_form_cursor_focus_position = mui_GetCurrentCursorFocusPosition(ui);
|
2021-08-23 00:22:25 +08:00
|
|
|
}
|
|
|
|
|
2021-08-22 01:32:56 +08:00
|
|
|
/*
|
2021-08-23 00:22:25 +08:00
|
|
|
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
|
|
|
|
*/
|
2021-08-28 15:40:10 +08:00
|
|
|
void mui_RestoreForm(mui_t *ui)
|
2021-08-23 00:22:25 +08:00
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
mui_GotoForm(ui, ui->last_form_id, ui->last_form_cursor_focus_position);
|
2021-08-23 00:22:25 +08:00
|
|
|
}
|
|
|
|
|
2022-01-10 02:53:04 +08:00
|
|
|
/*
|
|
|
|
Save a cursor position for mui_GotoFormAutoCursorPosition command
|
2022-03-07 06:07:56 +08:00
|
|
|
Two such positions is stored.
|
2022-01-10 02:53:04 +08:00
|
|
|
*/
|
|
|
|
void mui_SaveCursorPosition(mui_t *ui, uint8_t cursor_position)
|
|
|
|
{
|
|
|
|
uint8_t form_id = mui_get_fds_char(ui->current_form_fds+1);
|
|
|
|
MUI_DEBUG("mui_SaveCursorPosition form_id=%d cursor_position=%d\n", form_id, cursor_position);
|
|
|
|
|
|
|
|
if ( form_id == ui->menu_form_id[0] )
|
|
|
|
ui->menu_form_last_added = 0;
|
|
|
|
else if ( form_id == ui->menu_form_id[1] )
|
|
|
|
ui->menu_form_last_added = 1;
|
|
|
|
else
|
|
|
|
ui->menu_form_last_added ^= 1;
|
|
|
|
ui->menu_form_id[ui->menu_form_last_added] = form_id;
|
|
|
|
ui->menu_form_cursor_focus_position[ui->menu_form_last_added] = cursor_position;
|
|
|
|
MUI_DEBUG("mui_SaveCursorPosition ui->menu_form_last_added=%d \n", ui->menu_form_last_added);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Similar to mui_GotoForm, but will jump to previously stored cursor location (mui_SaveCursorPosition) or 0 if the cursor position was not saved.
|
|
|
|
*/
|
|
|
|
uint8_t mui_GotoFormAutoCursorPosition(mui_t *ui, uint8_t form_id)
|
|
|
|
{
|
|
|
|
uint8_t cursor_position = 0;
|
|
|
|
if ( form_id == ui->menu_form_id[0] )
|
|
|
|
cursor_position = ui->menu_form_cursor_focus_position[0];
|
|
|
|
if ( form_id == ui->menu_form_id[1] )
|
|
|
|
cursor_position = ui->menu_form_cursor_focus_position[1];
|
|
|
|
MUI_DEBUG("mui_GotoFormAutoCursorPosition form_id=%d cursor_position=%d\n", form_id, cursor_position);
|
|
|
|
return mui_GotoForm(ui, form_id, cursor_position);
|
|
|
|
}
|
|
|
|
|
2022-01-08 02:46:39 +08:00
|
|
|
/*
|
|
|
|
return current form id or -1 if the menu system is inactive
|
|
|
|
*/
|
|
|
|
int mui_GetCurrentFormId(mui_t *ui)
|
|
|
|
{
|
|
|
|
if ( mui_IsFormActive(ui) == 0 )
|
|
|
|
return -1;
|
|
|
|
return mui_get_fds_char(ui->current_form_fds+1);
|
|
|
|
}
|
|
|
|
|
2021-08-23 00:22:25 +08:00
|
|
|
/*
|
|
|
|
updates "ui->cursor_focus_fds"
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
|
2021-08-22 01:32:56 +08:00
|
|
|
*/
|
2021-08-28 15:40:10 +08:00
|
|
|
void mui_NextField(mui_t *ui)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-09-26 21:32:45 +08:00
|
|
|
do
|
2021-09-27 01:05:09 +08:00
|
|
|
{
|
2021-09-26 21:32:45 +08:00
|
|
|
if ( mui_send_cursor_msg(ui, MUIF_MSG_EVENT_NEXT) )
|
|
|
|
return;
|
|
|
|
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
|
|
|
|
mui_next_field(ui);
|
2021-09-27 01:05:09 +08:00
|
|
|
} while ( mui_send_cursor_enter_msg(ui) == 255 );
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
2021-08-22 01:32:56 +08:00
|
|
|
/*
|
2021-08-23 00:22:25 +08:00
|
|
|
updates "ui->cursor_focus_fds"
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
|
2021-08-22 01:32:56 +08:00
|
|
|
*/
|
2021-08-28 15:40:10 +08:00
|
|
|
void mui_PrevField(mui_t *ui)
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-09-26 21:32:45 +08:00
|
|
|
do
|
2021-08-09 00:49:36 +08:00
|
|
|
{
|
2021-09-26 21:32:45 +08:00
|
|
|
if ( mui_send_cursor_msg(ui, MUIF_MSG_EVENT_PREV) )
|
|
|
|
return;
|
|
|
|
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
|
|
|
|
|
|
|
|
mui_loop_over_form(ui, mui_task_find_prev_cursor_uif);
|
2021-08-09 00:49:36 +08:00
|
|
|
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
|
2021-09-26 21:32:45 +08:00
|
|
|
if ( ui->target_fds == NULL )
|
|
|
|
{
|
|
|
|
//ui->cursor_focus_position = 0;
|
|
|
|
mui_loop_over_form(ui, mui_task_find_last_cursor_uif);
|
|
|
|
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
|
|
|
|
}
|
|
|
|
} while( mui_send_cursor_enter_msg(ui) == 255 );
|
2021-08-09 00:49:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-28 15:40:10 +08:00
|
|
|
void mui_SendSelect(mui_t *ui)
|
2021-08-09 15:50:03 +08:00
|
|
|
{
|
2021-08-28 15:30:19 +08:00
|
|
|
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_SELECT);
|
2021-08-15 22:23:17 +08:00
|
|
|
}
|
|
|
|
|
2022-03-07 03:50:26 +08:00
|
|
|
/*
|
|
|
|
Same as mui_SendSelect(), but will try to find a field, which is marked as "execute on select" (MUIF_EXECUTE_ON_SELECT_BUTTON).
|
|
|
|
If such a field exists, then this field is executed, otherwise the current field will receive the select message.
|
2022-09-04 05:10:51 +08:00
|
|
|
|
|
|
|
MUIF_EXECUTE_ON_SELECT_BUTTON is set by muif macro MUIF_EXECUTE_ON_SELECT_BUTTON
|
|
|
|
|
|
|
|
used by MUIInputVersatileRotaryEncoder.ino example
|
2022-03-07 03:50:26 +08:00
|
|
|
*/
|
|
|
|
void mui_SendSelectWithExecuteOnSelectFieldSearch(mui_t *ui)
|
|
|
|
{
|
|
|
|
mui_loop_over_form(ui, mui_task_find_execute_on_select_field); /* Is there a exec on select field? */
|
|
|
|
if ( ui->target_fds != NULL ) /* yes, found, ui->fds already points to the field */
|
|
|
|
{
|
|
|
|
fds_t *exec_on_select_field = ui->target_fds;
|
|
|
|
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
|
|
|
|
ui->cursor_focus_fds = exec_on_select_field; /* more cursor on the "exec on select" field */
|
|
|
|
mui_send_cursor_enter_msg(ui);
|
|
|
|
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_SELECT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* no "exec on select" field found, just send the select message to the field */
|
|
|
|
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_SELECT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mui_SendValueIncrement(mui_t *ui)
|
|
|
|
{
|
|
|
|
mui_send_cursor_msg(ui, MUIF_MSG_VALUE_INCREMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mui_SendValueDecrement(mui_t *ui)
|
|
|
|
{
|
|
|
|
mui_send_cursor_msg(ui, MUIF_MSG_VALUE_DECREMENT);
|
|
|
|
}
|