Skip to content

Commit

Permalink
feat: Switches getch
Browse files Browse the repository at this point in the history
  • Loading branch information
ntlhui committed Dec 20, 2024
1 parent 2394444 commit cb92f7a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/chargeTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ STATES_e ChargeTask::run(void)
{
if(kbhit())
{
this->inputBuffer[CLI_BUFFER_LEN - 1] = getch();
this->inputBuffer[CLI_BUFFER_LEN - 1] = SF_OSAL_getch();
byteshiftl(this->inputBuffer, CLI_BUFFER_LEN, 1, 0);
if(strcmp(this->inputBuffer, CLI_INTERRUPT_PHRASE) == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void CLI::init(void)
// While there is an avaliable character typed, get it
while (kbhit())
{
getch();
SF_OSAL_getch();
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/cli/conio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ extern "C"
return Serial.available();
}

// Get pressed key
int getch(void)
int SF_OSAL_getch(void)
{
#if SF_PLATFORM == SF_PLATFORM_PARTICLE
while (Serial.available() == 0)
{
delay(1);
}
return Serial.read();
#elif SF_PLATFORM == SF_PLATFORM_GLIBC
return getchar();
#endif
}

// Write character
Expand All @@ -54,7 +57,7 @@ extern "C"
Particle.process();
if (kbhit())
{
userInput = getch();
userInput = SF_OSAL_getch();
switch(userInput)
{
case '\b':
Expand Down
15 changes: 8 additions & 7 deletions src/cli/conio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@
extern "C"
{
#endif
/**
* @brief Gets character from serial
*
* @return int key thats pressed
*/
int getch(void);
/**
* @brief Checks if key is pressed
*
*
* @return int whether key is pressed
*/
int kbhit(void);
Expand Down Expand Up @@ -50,6 +44,13 @@ extern "C"
*/
int SF_OSAL_getline(char *buffer, int buflen);

/**
* @brief Reads the next character from stdin
*
* @return The obtained character on success or EOF on failure.
*/
int SF_OSAL_getch(void);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/cli/menuItems/debugCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void CLI_monitorTempSensor(void)
{
if(kbhit())
{
ch = getch();
ch = SF_OSAL_getch();
if('q' == ch)
{
break;
Expand Down Expand Up @@ -178,7 +178,7 @@ void CLI_monitorIMU(void)
{
if(kbhit())
{
ch = getch();
ch = SF_OSAL_getch();

if('q' == ch)
{
Expand Down Expand Up @@ -216,7 +216,7 @@ void CLI_monitorWetDry(void)
{
if(kbhit())
{
ch = getch();
ch = SF_OSAL_getch();

if('q' == ch)
{
Expand Down
2 changes: 1 addition & 1 deletion src/cli/menuItems/gpsCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void CLI_GPS()
{
if(kbhit())
{
ch = getch();
ch = SF_OSAL_getch();
if('q' == ch)
{
break;
Expand Down

0 comments on commit cb92f7a

Please sign in to comment.