comparison Discovery/Src/tMenuEdit.c @ 1026:5fedf7ba2392 GasConsumption

Added text based edit item: In previous version only numbers could be entered as data field. This changes introduces a edit field for entering text in upper characters. '_' are used for seperation because simple white spaces (' ') would cause problems in the handling of the edit field. String length is limited to eigth charecters.
author Ideenmodellierer
date Sun, 07 Sep 2025 18:55:45 +0200
parents ac25c35a3c97
children e938901f6386
comparison
equal deleted inserted replaced
1025:6e11f7327efd 1026:5fedf7ba2392
44 #include "tMenuEditCustom.h" 44 #include "tMenuEditCustom.h"
45 45
46 /* Private types -------------------------------------------------------------*/ 46 /* Private types -------------------------------------------------------------*/
47 #define TEXTSIZE 16 47 #define TEXTSIZE 16
48 48
49 #define IDENT_MAY_INPUT_NUM 4 /* legacy value of ident.input struct */
50 #define IDENT_MAX_INPUT_TEXT 9 /* 8 data items + 0 for string operations */
51
49 typedef struct 52 typedef struct
50 { 53 {
51 uint32_t pEventFunction; 54 uint32_t pEventFunction;
52 uint32_t callerID; 55 uint32_t callerID;
53 } SEventHandler; 56 } SEventHandler;
61 64
62 typedef struct 65 typedef struct
63 { 66 {
64 char orgText[32]; 67 char orgText[32];
65 char newText[32]; 68 char newText[32];
66 uint32_t input[4]; 69 uint32_t input[IDENT_MAX_INPUT_TEXT];
67 uint16_t coord[3]; 70 uint16_t coord[3];
68 int8_t begin[4], size[4]; 71 int8_t begin[IDENT_MAX_INPUT_TEXT], size[IDENT_MAX_INPUT_TEXT];
69 tFont *fontUsed; 72 tFont *fontUsed;
70 uint32_t callerID; 73 uint32_t callerID;
71 uint8_t maintype; 74 uint8_t maintype;
72 uint8_t subtype; 75 uint8_t subtype;
73 } SEditIdent; 76 } SEditIdent;
83 FIELD_UDIGIT, 86 FIELD_UDIGIT,
84 FIELD_2DIGIT, 87 FIELD_2DIGIT,
85 FIELD_3DIGIT, 88 FIELD_3DIGIT,
86 FIELD_SDIGIT, 89 FIELD_SDIGIT,
87 FIELD_FLOAT, 90 FIELD_FLOAT,
91 FIELD_TEXT,
88 FIELD_END 92 FIELD_END
89 } SField; 93 } SField;
90 94
91 /* Private variables ---------------------------------------------------------*/ 95 /* Private variables ---------------------------------------------------------*/
92 GFX_DrawCfgScreen tMEscreen; 96 GFX_DrawCfgScreen tMEscreen;
282 { 286 {
283 if(WriteSettings) 287 if(WriteSettings)
284 { 288 {
285 reset_SettingWarning(); 289 reset_SettingWarning();
286 GFX_logoAutoOff(); 290 GFX_logoAutoOff();
287 ext_flash_write_settings(0); 291 ext_flash_write_settings(EF_SETTINGS,0);
288 WriteSettings = 0; 292 WriteSettings = 0;
289 } 293 }
290 } 294 }
291 295
292 void helperLeaveMenuEditField(uint8_t idID) 296 void helperLeaveMenuEditField(uint8_t idID)
440 { 444 {
441 subBlockPosition++; 445 subBlockPosition++;
442 return 1; 446 return 1;
443 } 447 }
444 448
445 if(((block + 1) < 4) && (ident[actualId].size[block+1] > 0)) 449 if((((block + 1) < 4) || ((ident[actualId].maintype == FIELD_TEXT) && ((block + 1) < IDENT_MAX_INPUT_TEXT))) && (ident[actualId].size[block+1] > 0))
446 { 450 {
447 block++; 451 block++;
448 subBlockPosition = 0; 452 subBlockPosition = 0;
449 return 1; 453 return 1;
450 } 454 }
474 { 478 {
475 content = 10 * (ident[actualId].newText[ident[actualId].begin[block] + 0] - '0'); 479 content = 10 * (ident[actualId].newText[ident[actualId].begin[block] + 0] - '0');
476 content += ident[actualId].newText[ident[actualId].begin[block] + 1]; 480 content += ident[actualId].newText[ident[actualId].begin[block] + 1];
477 } 481 }
478 else 482 else
479 if(ident[actualId].maintype == FIELD_NUMBERS) 483 if((ident[actualId].maintype == FIELD_NUMBERS) || (ident[actualId].maintype == FIELD_TEXT))
480 content = ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition]; 484 content = ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition];
481 else 485 else
482 if((ident[actualId].maintype == FIELD_ON_OFF) || (ident[actualId].maintype == FIELD_TOGGLE)) 486 if((ident[actualId].maintype == FIELD_ON_OFF) || (ident[actualId].maintype == FIELD_TOGGLE))
483 content = ident[actualId].input[block]; 487 content = ident[actualId].input[block];
484 else 488 else
493 uint16_t positionOffset; 497 uint16_t positionOffset;
494 498
495 if(event[actualevid].callerID != ident[actualId].callerID) 499 if(event[actualevid].callerID != ident[actualId].callerID)
496 return; 500 return;
497 501
498 if(ident[actualId].maintype == FIELD_NUMBERS) 502 if((ident[actualId].maintype == FIELD_NUMBERS) || (ident[actualId].maintype == FIELD_TEXT))
499 { 503 {
500 oneCharText[0] = ident[actualId].newText[ident[actualId].begin[oldblock] + oldsubblockpos]; 504 oneCharText[0] = ident[actualId].newText[ident[actualId].begin[oldblock] + oldsubblockpos];
501 oneCharText[1] = 0; 505 oneCharText[1] = 0;
502 positionOffset = GFX_return_offset(ident[actualId].fontUsed, ident[actualId].newText, ident[actualId].begin[oldblock] + oldsubblockpos); 506 positionOffset = GFX_return_offset(ident[actualId].fontUsed, ident[actualId].newText, ident[actualId].begin[oldblock] + oldsubblockpos);
503 write_content( ident[actualId].coord[0] + positionOffset, ident[actualId].coord[1], ident[actualId].coord[2], ident[actualId].fontUsed, oneCharText, CLUT_MenuEditFieldSelected); 507 write_content( ident[actualId].coord[0] + positionOffset, ident[actualId].coord[1], ident[actualId].coord[2], ident[actualId].fontUsed, oneCharText, CLUT_MenuEditFieldSelected);
550 uint16_t positionOffset; 554 uint16_t positionOffset;
551 555
552 if(event[actualevid].callerID != ident[actualId].callerID) 556 if(event[actualevid].callerID != ident[actualId].callerID)
553 return; 557 return;
554 558
555 if(ident[actualId].maintype == FIELD_NUMBERS) 559 if((ident[actualId].maintype == FIELD_NUMBERS) || (ident[actualId].maintype == FIELD_TEXT))
556 { 560 {
557 oneCharText[0] = ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition]; 561 oneCharText[0] = ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition];
558 oneCharText[1] = 0; 562 oneCharText[1] = 0;
559 positionOffset = GFX_return_offset(ident[actualId].fontUsed, ident[actualId].newText, ident[actualId].begin[block] + subBlockPosition); 563 positionOffset = GFX_return_offset(ident[actualId].fontUsed, ident[actualId].newText, ident[actualId].begin[block] + subBlockPosition);
560 write_content( ident[actualId].coord[0] + positionOffset, ident[actualId].coord[1], ident[actualId].coord[2], ident[actualId].fontUsed, oneCharText, CLUT_MenuEditDigit); 564 write_content( ident[actualId].coord[0] + positionOffset, ident[actualId].coord[1], ident[actualId].coord[2], ident[actualId].fontUsed, oneCharText, CLUT_MenuEditDigit);
580 584
581 set_globalState(event[actualevid].callerID); 585 set_globalState(event[actualevid].callerID);
582 block = 0; 586 block = 0;
583 subBlockPosition = 0; 587 subBlockPosition = 0;
584 588
585 if(ident[actualId].maintype == FIELD_NUMBERS) 589 if((ident[actualId].maintype == FIELD_NUMBERS) || (ident[actualId].maintype == FIELD_TEXT))
586 { 590 {
587 change_CLUT_entry(CLUT_MenuEditLineSelected, CLUT_MenuEditCursor); 591 change_CLUT_entry(CLUT_MenuEditLineSelected, CLUT_MenuEditCursor);
588 // old stuff? hw 150916, reactivated 150923, this shows which digit will be changed now as it marks the other grey/black 592 // old stuff? hw 150916, reactivated 150923, this shows which digit will be changed now as it marks the other grey/black
589 // now fixed for button settings with newContent <= '0'+99 condition 593 // now fixed for button settings with newContent <= '0'+99 condition
590 change_CLUT_entry((CLUT_MenuEditField0 + actualId), CLUT_MenuEditFieldSelected); 594 change_CLUT_entry((CLUT_MenuEditField0 + actualId), CLUT_MenuEditFieldSelected);
688 write_content_of_actual_Id(); 692 write_content_of_actual_Id();
689 set_globalState(menuID); 693 set_globalState(menuID);
690 break; 694 break;
691 case FIELD_SELECT: 695 case FIELD_SELECT:
692 write_buttonTextline(TXT2BYTE_ButtonMinus, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonPlus); 696 write_buttonTextline(TXT2BYTE_ButtonMinus, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonPlus);
693 697 break;
698 case FIELD_TEXT:
699 write_buttonTextline(TXT2BYTE_ButtonMinus, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonPlus);
700 if((newContent >= 'A') && (newContent <= '_'))
701 ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition] = newContent;
702
703 mark_new_digit_of_actual_id_block_and_subBlock();
694 break; 704 break;
695 } 705 }
696 } 706 }
697 707
698 708
813 } 823 }
814 } 824 }
815 else 825 else
816 if((ident[actualId].maintype == FIELD_NUMBERS) && (action == ACTION_BUTTON_ENTER) && (newContent >= '0') && (newContent <= '9')) 826 if((ident[actualId].maintype == FIELD_NUMBERS) && (action == ACTION_BUTTON_ENTER) && (newContent >= '0') && (newContent <= '9'))
817 ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition] = newContent; 827 ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition] = newContent;
828 else
829 if((ident[actualId].maintype == FIELD_TEXT) && (action == ACTION_BUTTON_ENTER) && (newContent >= '0') && (newContent <= '9'))
830 ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition] = newContent;
818 831
819 if(action == ACTION_BUTTON_ENTER) 832 if(action == ACTION_BUTTON_ENTER)
820 { 833 {
821 if((ident[actualId].maintype == FIELD_NUMBERS) && (ident[actualId].subtype == FIELD_3DIGIT)) 834 if((ident[actualId].maintype == FIELD_NUMBERS) && (ident[actualId].subtype == FIELD_3DIGIT))
822 { 835 {
909 checkUpdateSDigit(newContent); 922 checkUpdateSDigit(newContent);
910 } else if (ident[actualId].maintype == FIELD_NUMBERS && newContent >= '0' && newContent <= '9') { 923 } else if (ident[actualId].maintype == FIELD_NUMBERS && newContent >= '0' && newContent <= '9') {
911 ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition] = newContent; 924 ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition] = newContent;
912 } 925 }
913 926
927 if ((ident[actualId].maintype == FIELD_TEXT) && (newContent >= 'A' && newContent <= '_'))
928 {
929 ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition] = newContent;
930 }
914 mark_new_digit_of_actual_id_block_and_subBlock(); 931 mark_new_digit_of_actual_id_block_and_subBlock();
915 } 932 }
916 933
917 934
918 void downMenuEditFieldDigit(void) 935 void downMenuEditFieldDigit(void)
946 } 963 }
947 964
948 if (ident[actualId].maintype == FIELD_NUMBERS && ident[actualId].subtype == FIELD_SDIGIT) { 965 if (ident[actualId].maintype == FIELD_NUMBERS && ident[actualId].subtype == FIELD_SDIGIT) {
949 checkUpdateSDigit(newContent); 966 checkUpdateSDigit(newContent);
950 } else if (ident[actualId].maintype == FIELD_NUMBERS && newContent >= '0' && newContent <= '9') { 967 } else if (ident[actualId].maintype == FIELD_NUMBERS && newContent >= '0' && newContent <= '9') {
968 ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition] = newContent;
969 }
970 if ((ident[actualId].maintype == FIELD_TEXT) && (newContent >= 'A' && newContent <= '_')) {
951 ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition] = newContent; 971 ident[actualId].newText[ident[actualId].begin[block] + subBlockPosition] = newContent;
952 } 972 }
953 973
954 mark_new_digit_of_actual_id_block_and_subBlock(); 974 mark_new_digit_of_actual_id_block_and_subBlock();
955 } 975 }
1016 *pNewValue1 = sum[0]; 1036 *pNewValue1 = sum[0];
1017 *pNewValue2 = sum[1]; 1037 *pNewValue2 = sum[1];
1018 *pNewValue3 = sum[2]; 1038 *pNewValue3 = sum[2];
1019 *pNewValue4 = sum[3]; 1039 *pNewValue4 = sum[3];
1020 } 1040 }
1021 1041 void evaluateNewStringText(uint32_t editID, uint8_t *pNewString)
1042 {
1043 if(editID != ident[actualId].callerID)
1044 return;
1045
1046 uint8_t i, digitCount;
1047 uint8_t digit = '_';
1048
1049 memset(pNewString, 0 , IDENT_MAX_INPUT_TEXT);
1050
1051 i = 0;
1052 while( ident[actualId].size[i] && (i < IDENT_MAX_INPUT_TEXT - 1))
1053 {
1054 for(digitCount = 0; digitCount < ident[actualId].size[i]; digitCount++)
1055 {
1056 digit = ident[actualId].newText[ident[actualId].begin[i] + digitCount];
1057 }
1058 pNewString[i] = digit;
1059 i++;
1060 }
1061 }
1022 1062
1023 uint8_t get_id_of(uint32_t editID) 1063 uint8_t get_id_of(uint32_t editID)
1024 { 1064 {
1025 uint8_t temp_id; 1065 uint8_t temp_id;
1026 1066
1154 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditFieldRegular); 1194 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditFieldRegular);
1155 write_content_of_Id(id); 1195 write_content_of_Id(id);
1156 1196
1157 id = backup_id; 1197 id = backup_id;
1158 } 1198 }
1159 1199 void tMenuEdit_newInputText(uint32_t editID, uint8_t* ptext)
1200 {
1201 uint8_t backup_id, temp_id;
1202 uint8_t index = 0;
1203
1204 temp_id = get_id_of(editID);
1205 if(temp_id == 255)
1206 return;
1207
1208 backup_id = id;
1209 id = temp_id;
1210
1211 if(editID != ident[id].callerID)
1212 {
1213 temp_id = 0;
1214 while((temp_id < IDENT_MAX_INPUT_TEXT) && (editID != ident[temp_id].callerID))
1215 temp_id++;
1216 if(editID != ident[temp_id].callerID)
1217 return;
1218 id = temp_id;
1219 }
1220 for(index = 0; index < IDENT_MAX_INPUT_TEXT; index++)
1221 {
1222 ident[id].input[index] = *ptext++;
1223 }
1224 create_newText_for_Id(id);
1225 if(id <= idLast)
1226 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditFieldRegular);
1227 write_content_of_Id(id);
1228
1229 id = backup_id;
1230 }
1160 1231
1161 void resetEnterPressedToStateBeforeButtonAction(void) 1232 void resetEnterPressedToStateBeforeButtonAction(void)
1162 { 1233 {
1163 EnterPressed = EnterPressedBeforeButtonAction; 1234 EnterPressed = EnterPressedBeforeButtonAction;
1164 } 1235 }
1255 ident[localId].newText[ident[localId].begin[i]] = '\006'; 1326 ident[localId].newText[ident[localId].begin[i]] = '\006';
1256 i++; 1327 i++;
1257 } 1328 }
1258 } 1329 }
1259 1330
1331 void create_newText_for_Id_and_field_text(int8_t localId)
1332 {
1333 uint8_t i;
1334
1335 i = 0;
1336 while( ident[localId].size[i] && (i < 9))
1337 {
1338 if(ident[localId].input[i])
1339 ident[localId].newText[ident[localId].begin[i]] = ident[localId].input[i];
1340 i++;
1341 }
1342 }
1343
1344
1260 void create_newText_for_actual_Id_and_field_select(void) 1345 void create_newText_for_actual_Id_and_field_select(void)
1261 { 1346 {
1262 create_newText_for_Id_and_field_select(actualId); 1347 create_newText_for_Id_and_field_select(actualId);
1263 } 1348 }
1264 1349
1271 i = 0; 1356 i = 0;
1272 1357
1273 if( ident[localId].maintype == FIELD_SELECT) 1358 if( ident[localId].maintype == FIELD_SELECT)
1274 { 1359 {
1275 create_newText_for_Id_and_field_select(localId); 1360 create_newText_for_Id_and_field_select(localId);
1361 return;
1362 }
1363
1364 if( ident[localId].maintype == FIELD_TEXT)
1365 {
1366 create_newText_for_Id_and_field_text(localId);
1276 return; 1367 return;
1277 } 1368 }
1278 1369
1279 while( ident[localId].size[i] && (i < 4)) 1370 while( ident[localId].size[i] && (i < 4))
1280 { 1371 {
1441 void write_field_sdigit(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, int32_t int1, int32_t int2, int32_t int3, int32_t int4) 1532 void write_field_sdigit(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, int32_t int1, int32_t int2, int32_t int3, int32_t int4)
1442 { 1533 {
1443 write_field_udigit_and_2digit(FIELD_SDIGIT, editID, XleftGimpStyle, XrightGimpStyle, YtopGimpStyle, Font, text, ((input_u)int1).uint32, ((input_u)int2).uint32, ((input_u)int3).uint32, ((input_u)int4).uint32); 1534 write_field_udigit_and_2digit(FIELD_SDIGIT, editID, XleftGimpStyle, XrightGimpStyle, YtopGimpStyle, Font, text, ((input_u)int1).uint32, ((input_u)int2).uint32, ((input_u)int3).uint32, ((input_u)int4).uint32);
1444 } 1535 }
1445 1536
1537 void write_field_text(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, uint8_t* pInput)
1538 {
1539 if(id >= 9)
1540 return;
1541
1542 int8_t beginTmp;
1543
1544 ident[id].maintype = FIELD_TEXT;
1545 ident[id].subtype = FIELD_TEXT;
1546
1547 ident[id].coord[0] = XleftGimpStyle;
1548 ident[id].coord[1] = XrightGimpStyle;
1549 ident[id].coord[2] = YtopGimpStyle;
1550 ident[id].fontUsed = (tFont *)Font;
1551 ident[id].callerID = editID;
1552
1553 strncpy(ident[id].orgText, text, 32);
1554 strncpy(ident[id].newText, text, 32);
1555 ident[id].orgText[31] = 0;
1556 ident[id].newText[31] = 0;
1557
1558 for(int i=0;i < IDENT_MAX_INPUT_TEXT -1;i++)
1559 {
1560 ident[id].input[i] = pInput[i];
1561 ident[id].size[i] = 0;
1562 }
1563 pInput[8] = 0;
1564
1565 beginTmp = 0;
1566 for(int i=0;i < IDENT_MAX_INPUT_TEXT;i++)
1567 {
1568 while((ident[id].orgText[beginTmp] != '#')&& ident[id].orgText[beginTmp])
1569 beginTmp++;
1570
1571 if(ident[id].orgText[beginTmp] == '#')
1572 {
1573
1574 ident[id].begin[i] = beginTmp;
1575 ident[id].size[i] = 1;
1576 beginTmp = ident[id].begin[i] + ident[id].size[i];
1577 }
1578 else
1579 break;
1580 }
1581
1582 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditFieldRegular);
1583
1584 create_newText_for_Id(id);
1585
1586 if(editID == 0)
1587 write_content_without_Id();
1588 else
1589 {
1590 write_content_of_Id(id);
1591 if(!tME_stop)
1592 idLast = id;
1593 id++;
1594 }
1595 }
1596
1446 1597
1447 void write_field_select(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, uint8_t int1, uint8_t int2, uint8_t int3, uint8_t int4) 1598 void write_field_select(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, uint8_t int1, uint8_t int2, uint8_t int3, uint8_t int4)
1448 { 1599 {
1449 if(id >= 9) 1600 if(id >= 9)
1450 return; 1601 return;