|
@@ -4,16 +4,16 @@
|
|
|
#ifdef _WIN32
|
|
|
#include <windows.h>
|
|
|
#include <mmsystem.h>
|
|
|
+#include <conio.h>
|
|
|
#endif
|
|
|
|
|
|
#include <stdio.h>
|
|
|
-#include <conio.h>
|
|
|
-
|
|
|
#include "serial.h"
|
|
|
|
|
|
struct serial_int_rx serial_rx;
|
|
|
extern struct rt_device serial_device;
|
|
|
|
|
|
+#ifdef _WIN32
|
|
|
/*
|
|
|
* Handler for OSKey Thread
|
|
|
*/
|
|
@@ -23,7 +23,6 @@ static DWORD OSKey_ThreadID;
|
|
|
static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam);
|
|
|
void rt_hw_usart_init(void)
|
|
|
{
|
|
|
-
|
|
|
/*
|
|
|
* create serial thread that receive key input from keyboard
|
|
|
*/
|
|
@@ -50,9 +49,52 @@ void rt_hw_usart_init(void)
|
|
|
* Start OS get key Thread
|
|
|
*/
|
|
|
ResumeThread(OSKey_Thread);
|
|
|
+}
|
|
|
+
|
|
|
+#else /* POSIX version */
|
|
|
+
|
|
|
+#include <pthread.h>
|
|
|
+#include <semaphore.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <termios.h> /* for tcxxxattr, ECHO, etc */
|
|
|
+#include <unistd.h> /* for STDIN_FILENO */
|
|
|
+
|
|
|
+/*simulate windows' getch(), it works!!*/
|
|
|
+int getch(void)
|
|
|
+{
|
|
|
+ int ch;
|
|
|
+ struct termios oldt, newt;
|
|
|
+
|
|
|
+ // get terminal input's attribute
|
|
|
+ tcgetattr(STDIN_FILENO, &oldt);
|
|
|
+ newt = oldt;
|
|
|
|
|
|
+ //set termios' local mode
|
|
|
+ newt.c_lflag &= ~(ECHO|ICANON);
|
|
|
+ tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
|
|
+
|
|
|
+ //read character from terminal input
|
|
|
+ ch = getchar();
|
|
|
+
|
|
|
+ //recover terminal's attribute
|
|
|
+ tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
|
|
+
|
|
|
+ return ch;
|
|
|
}
|
|
|
|
|
|
+static void * ThreadforKeyGet(void * lpParam);
|
|
|
+static pthread_t OSKey_Thread;
|
|
|
+void rt_hw_usart_init(void)
|
|
|
+{
|
|
|
+ int res;
|
|
|
+ res = pthread_create(&OSKey_Thread, NULL, &ThreadforKeyGet, NULL);
|
|
|
+ if (res)
|
|
|
+ {
|
|
|
+ printf("pthread create faild, <%d>\n", res);
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
+ }
|
|
|
+}
|
|
|
+#endif
|
|
|
/*
|
|
|
* ·½Ïò¼ü(¡û)£º 0xe04b
|
|
|
* ·½Ïò¼ü(¡ü)£º 0xe048
|
|
@@ -104,7 +146,11 @@ static int savekey(unsigned char key)
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
+#ifdef _WIN32
|
|
|
static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam)
|
|
|
+#else
|
|
|
+static void * ThreadforKeyGet(void * lpParam)
|
|
|
+#endif
|
|
|
{
|
|
|
unsigned char key;
|
|
|
|