-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleMenuOptions.c
164 lines (152 loc) · 4.21 KB
/
ConsoleMenuOptions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <stdio.h>
#include "ConsoleMenuOptions.h"
static void ShowAllStates(void);
uint8_t StringCompareAndParseToNum(char* inBuff, uint8_t maxPossibleLen)
{
if (inBuff == NULL)
return -1;
uint8_t len = maxPossibleLen;
if (maxPossibleLen == NULL)
len = OPTION_NAMES_LEN;
//Users code
/*---------Put your Functions launch to the header file ConsoleMenuOptions.h----------*/
/*-------------------------------------------------------------------------------------*/
u8 OptnQnty = sizeof(MenuOption) / sizeof(menuChoise_t);
for (uint8_t u = 0; u < OptnQnty; u++) {
if (strncmp(inBuff, MenuOption[u].optionName, len) == 0)
return MenuOption[u].optionId;
}
return 0;
}
void SettingsCMD_Handling(char* inBuff, const uint16_t maxPossibleLen)
{
uint8_t parsedCMD = StringCompareAndParseToNum(inBuff, NULL);
ConsolesMenuHandle.CMD[parsedCMD] = ~ConsolesMenuHandle.CMD[parsedCMD] & 0x01;
uint8_t IsParsedCMD_Enabled = ConsolesMenuHandle.CMD[parsedCMD];
switch (parsedCMD)
{
//Users code
/*------------------------------Put your Functions launch here----------------------------*/
//case EXAMPLE: {
// ExampleOfYourFunctions();
//}break;
/*----------------------------------------------------------------------------------------*/
case ALL: {
ShowAllStates();
}break;
case DETAILS: {
if (IsParsedCMD_Enabled)
printf("DETAILS ON!\n");
else
printf("DETAILS OFF!\n");
}break;
case PAUSE_CONSOLE: {
if (IsParsedCMD_Enabled)
printf("Pause Console ON: Mainbackground process don't show!\n");
else
printf("Pause Console OFF: Show Mainbackground process!\n");
}break;
case ENABLE_TIMER: {
if (IsParsedCMD_Enabled)
printf("Timer ENABLED!\n");
else
printf("Timer DISABLED!\n");
}break;
case MAKE_PACKET: {
}break;
case DMA_ENABLE: {
if (IsParsedCMD_Enabled)
printf("DMA interrupting peripheral ON!\n");
else
printf("DMA interrupting peripheral OFF!\n");
}break;
case START_COMMUNICATION: {
if (IsParsedCMD_Enabled) {
printf("START COMMUNICATION\n");
ConsolesMenuHandle.CMD[STOP_COMMUNICATION] = 0;
}
}break;
case STOP_COMMUNICATION: {
if (IsParsedCMD_Enabled) {
printf("STOP COMMUNICATION\n");
ConsolesMenuHandle.CMD[START_COMMUNICATION] = 0;
}
}break;
default:
break;
}
memset(inBuff, 0, 2/*maxPossibleLen*/); //memsetstr
return;
}
int ScanKeyboardWithWhiteSpaces(char* inBuff, uint16_t maxPossibleLen)
{
int res = -1;
uint16_t ptr = 0;
char catchedChar = 0;
memset(inBuff, 0, maxPossibleLen);
uint8_t timeout = 200;
do {
scanf_s("%s%c", (char*)&inBuff[ptr], maxPossibleLen, &catchedChar, 1);
ptr = strlen(inBuff);
if (ptr > maxPossibleLen - 1)
return -2;
inBuff[ptr] = ' ';
ptr++;
} while ((catchedChar != '\n') && (timeout--)); //(catchedChar == ' ')
if (timeout == 0)
return res;
inBuff[ptr] = '\0';
return res = 0;
}
#ifdef _CRT_DISABLE_PERFCRIT_LOCKS //!it not unlocks yet
int ScanKeyboardNoLock(char *inBuff, uint16_t maxPossibleLen)
{
int res = -1;
int i, ch;
for (i = 0; (i < maxPossibleLen) && ((ch = _getchar_nolock()) != EOF)
&& (ch != '\n'); i++)
{
inBuff[i] = (char)ch;
}
// Terminate string with a null character
inBuff[i] = '\0';
printf("Input was: %s\n", inBuff);
}
#endif // _CRT_DISABLE_PERFCRIT_LOCKS
void ScanCMDsScenarios(char *buffer, const int maxPossibleLen)
{
u8 u = 0;
void* arg = NULL; //UNUSED
for (u = cmdsValEnumsfirstINDEX; u < cmdsValEnumslastINDEX; u++) {
if ((ConsolesMenuHandle.executeFunc[u] != NULL) && (ConsolesMenuHandle.CMD[u])) {
ConsolesMenuHandle.executeFunc[u](buffer, maxPossibleLen, arg);
}
}
return;
}
static void ShowAllStates(void)
{
#ifdef DEBUG /*|| ENABLE_SOME_STATES_MONITORING*/
printf("\n\n\n..............\n");
printf("State 1: = %d\n", State1);
printf("State 2: = %d\n", State2);
printf("State 3: = %d\n", State3);
printf("..............\n");
#define MORE_DETAILS_SHOW 1
#if (MORE_DETAILS_SHOW == 1)
if (MoreDetailsInShowing) {
if (State1.Status & OPEN) {
printf("+--> State1.member: = %d\n", State1.member);
}
if (State2.Status & OPEN) {
printf("+--> State2.member: = %d\n", State2.member);
}
if (State3.Status & OPEN) {
printf("+--> State3 - Status: = %d\n", State3.Status);
printf("+--> State3 - member: = %d\n", State3.member);
}
}
#endif
#endif
return;
}