-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtask1.cpp
52 lines (45 loc) · 2.27 KB
/
task1.cpp
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
/**
* Joel Brigida
* CDA 4102: Computer Architecture
* Implementation file for Reading User Input
* June 28, 2023
*/
#include <Arduino.h>
#include "tasks.h"
/** TASK 1: Lowest Level Function: Read Raw User Input **/
/** Always scanning the keyboard **/
void userCLITask(void *param) // Function definition for user CLI task
{
Serial.println("Starting Task 1...");
Message sendMsg; // Declare user message
char input; // Each char of user input
char buffer[BUF_LEN]; // buffer to hold user input
uint8_t index = 0; // character count
memset(buffer, 0, BUF_LEN); // Clear user input buffer
Serial.println("Task 1 Entering for(;;) Loop...");
for(;;)
{
if(Serial.available() > 0)
{
input = Serial.read(); // read each character of user input
if(index < (BUF_LEN - 1))
{
buffer[index] = input; // write received character to buffer
index++;
}
if(input == '\n') // Check when user presses ENTER key
{
Serial.print("\n");
strcpy(sendMsg.msg, buffer); // copy input to Message node
xQueueSend(msgQueue, (void *)&sendMsg, 20); // Send to msgQueue for interpretation
memset(buffer, 0, BUF_LEN); // Clear input buffer
index = 0; // Reset index counter.
}
else // echo each character back to the serial terminal
{
Serial.print(input);
}
}
vTaskDelay(25 / portTICK_PERIOD_MS); // yield to other tasks
}
}