Permalink
Browse files

Update Commit

- updated to allow sending ESC key...
- not working on win32 (alt key NOT detected - need winapi!)
- minor code clean-up
  • Loading branch information...
1 parent 98e9426 commit d8d4083663d287c2d8e8943f9185ddbf6f71bb73 @azman committed Jun 29, 2012
Showing with 43 additions and 32 deletions.
  1. +1 −0 makefile
  2. +13 −20 src/my1cons.c
  3. +1 −0 src/my1cons.h
  4. +28 −12 src/my1termu.c
View
@@ -19,6 +19,7 @@ ifeq ($(DO_MINGW),YES)
TESTPRO = $(TEMPPRO).exe
ifeq ($(DO_WIN32),yes)
DELETE = del
+ CFLAGS += -DDO_MINGW
else
XTOOL_DIR ?= /home/share/tool/mingw
XTOOL_TARGET = $(XTOOL_DIR)
View
@@ -11,7 +11,6 @@
my1key_t get_keypress(my1key_t *extended)
{
my1key_t init, full, temp;
-
init = getch();
full = KEY_NONE;
while(kbhit())
@@ -20,21 +19,15 @@ my1key_t get_keypress(my1key_t *extended)
full <<= 8;
full |= temp;
}
-
- if(extended)
- *extended = full;
-
+ if(extended) *extended = full;
return init;
}
//------------------------------------------------------------------------------
my1key_t get_key(void)
{
my1key_t cKey, cEsc;
cKey = get_keypress(&cEsc);
- if(cEsc!=KEY_NONE)
- {
- cKey = cEsc;
- }
+ if(cEsc!=KEY_NONE) cKey = cEsc;
return cKey;
}
//------------------------------------------------------------------------------
@@ -44,26 +37,26 @@ my1key_t get_keyhit(void)
return get_key();
}
//------------------------------------------------------------------------------
+my1key_t get_keyhit_ext(my1key_t *extended)
+{
+ if(extended) *extended = KEY_NONE;
+ if(!kbhit()) return KEY_NONE;
+ return get_keypress(extended);
+}
+//------------------------------------------------------------------------------
int get_param_int(int argc, char* argv[], int *index, int *value)
{
- int error = -1;
(*index)++;
- if(*index<argc)
- {
- *value = atoi(argv[*index]);
- error = 0;
- }
- return error;
+ if(*index>=argc) return -1;
+ *value = atoi(argv[*index]);
+ return 0;
}
//------------------------------------------------------------------------------
char* get_param_str(int argc, char* argv[], int *index)
{
char* pparam = 0x0;
(*index)++;
- if(*index<argc)
- {
- pparam = argv[*index];
- }
+ if(*index<argc) pparam = argv[*index];
return pparam;
}
//------------------------------------------------------------------------------
View
@@ -49,6 +49,7 @@ typedef unsigned int my1key_t; // must be at least 32-bit!
my1key_t get_keypress(my1key_t *extended);
my1key_t get_key(void);
my1key_t get_keyhit(void); // non-blocking wrapper for get_key
+my1key_t get_keyhit_ext(my1key_t *extended);
int get_param_int(int argc, char* argv[], int *index, int *value);
char* get_param_str(int argc, char* argv[], int *index);
//------------------------------------------------------------------------------
View
@@ -57,7 +57,7 @@ void sendprint(ASerialPort_t* aPort, int aData, termopts_t anOpt)
int main(int argc, char* argv[])
{
ASerialPort_t cPort;
- my1key_t key;
+ my1key_t key, ext;
termopts_t options = 0x0;
int terminal = 1, test, loop, mask, drag;
char filename[FILENAME_LEN], *ptty;
@@ -194,17 +194,39 @@ int main(int argc, char* argv[])
// start main loop
while(1)
{
- key = get_keyhit();
+ key = get_keyhit_ext(&ext);
if(key!=KEY_NONE)
{
- if(options&OPT_RAWMODE) // simply send raw key hit
+ // lazy to modify all - create extra storage
+ if(ext!=KEY_NONE)
{
- if(key==KEY_ESCAPE) // toggle raw mode
+ // key = alt-key? && ext = actual key!
+ // tested on linux only!
+ if(key==KEY_ESCAPE&&ext==KEY_ESCAPE)
+ {
+ sendprint(&cPort,key,options);
+ continue;
+ }
+ key = ext;
+ }
+ // check raw mode toggling!
+ if(key==KEY_ESCAPE) // toggle raw mode
+ {
+ if(options&OPT_RAWMODE)
{
options &= ~OPT_RAWMODE;
printf("\n\nSwitching to Command Mode!\n\n");
- continue;
}
+ else
+ {
+ options |= OPT_RAWMODE;
+ printf("\n\nSwitching to Raw Mode!\n\n");
+ }
+ continue;
+ }
+ // now process the key!
+ if(options&OPT_RAWMODE) // simply send raw key hit
+ {
if(key<0x100) // 8-bit ascii
{
sendprint(&cPort,key,options);
@@ -229,13 +251,7 @@ int main(int argc, char* argv[])
}
else
{
- if(key==KEY_ESCAPE) // toggle raw mode
- {
- options |= OPT_RAWMODE;
- printf("\n\nSwitching to Raw Mode!\n\n");
- continue;
- }
- else if(key==KEY_F1) // show commands
+ if(key==KEY_F1) // show commands
{
printf("\n\n------------\n");
printf("Command Keys\n");

0 comments on commit d8d4083

Please sign in to comment.