home *** CD-ROM | disk | FTP | other *** search
/ TAP YIPL / TAP_and_YIPL_Collection_CD.iso / PHREAK / CELLULAR / CTEK.ZIP / KEYCON.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-14  |  2.9 KB  |  126 lines

  1. /*
  2.   OKI Keypad Control Program
  3.   Copyright (C) 1994 by Network Wizards
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <dos.h>
  8. #include <conio.h>
  9. #include <bios.h>
  10. #include <ctype.h>
  11. #include <string.h>
  12.  
  13. #define FALSE        0
  14. #define TRUE        1
  15.  
  16. #define VERSION            "1.4(940214)"   /* major.minor(last-edit-date) */
  17.  
  18. typedef unsigned char bool;
  19. typedef unsigned char byte;
  20. typedef unsigned int  word;
  21.  
  22. #include "ctlib.h"
  23.  
  24. #define BUFLEN        128
  25. #define ESC        0x1B
  26.  
  27. char buf[BUFLEN];
  28.  
  29. main(argc,argv)
  30.   int argc;
  31.   char *argv[];
  32. {
  33.   byte cmd;
  34.   
  35.   /* initialize ct library using the specified COM port */
  36.   if (argc > 1)
  37.   {
  38.     if (*argv[1] == '1')
  39.       ct_lib_init(900,0x3f8,4);
  40.     else if (*argv[1] == '2')
  41.       ct_lib_init(900,0x2f8,3);
  42.     else if (*argv[1] == '3')
  43.       ct_lib_init(900,0x3e8,5);
  44.     else
  45.     {
  46.       puts("Type 'TEST 2' to use COM2");
  47.       exit(0);
  48.     }
  49.   }
  50.   else
  51.     ct_lib_init(900,0x3f8,4);        /* com1 by default */
  52.  
  53.   /* power up oki and tell it what we are */
  54.   if (!ct_on(MODE_NORMAL))
  55.   {
  56.     cprintf("?No response from OKI\r\n");
  57.     cprintf("  Make sure the phone is turned OFF and\r\n");
  58.     cprintf("  all cables are properly attached.\r\n\n");
  59.     cleanup();
  60.     exit(1);
  61.   }
  62.  
  63.   printf("Type ESCape to EXIT.\n\
  64.  Keypresses are one of:\n\
  65.     1  2  3\n\
  66.     4  5  6\n\
  67.     7  8  9\n\
  68.     *  0  #\n\
  69. up(+),   down(-)\n\
  70. rcl(r),  sto(s), alph(a), menu(m)\n\
  71. snd(d),  clr(c), end(e)\n");
  72.         
  73.   /* read keypresses until ESC, and act on them */
  74.   for (;;)
  75.   {
  76.     if (kbhit())
  77.     {
  78.       cmd = tolower(getch());
  79.       if (cmd == ESC)
  80.     break;
  81.       switch (cmd)
  82.       {
  83.         case '1': send(CT_KEY_1);     break;
  84.         case '2': send(CT_KEY_2);     break;
  85.         case '3': send(CT_KEY_3);     break;
  86.         case '4': send(CT_KEY_4);     break;
  87.         case '5': send(CT_KEY_5);     break;
  88.         case '6': send(CT_KEY_6);     break;
  89.         case '7': send(CT_KEY_7);     break;
  90.         case '8': send(CT_KEY_8);     break;
  91.         case '9': send(CT_KEY_9);     break;
  92.         case '0': send(CT_KEY_0);     break;
  93.         case '*': send(CT_KEY_STAR);  break;
  94.         case '#': send(CT_KEY_POUND); break;
  95.         case '+': send(CT_KEY_UP);    break;
  96.         case '-': send(CT_KEY_DOWN);  break;
  97.         case 'r': send(CT_KEY_RCL);   break;
  98.         case 's': send(CT_KEY_STO);   break;
  99.         case 'a': send(CT_KEY_ALPH);  break;
  100.         case 'm': send(CT_KEY_MENU);  break;
  101.         case 'd': send(CT_KEY_SND);   break;
  102.         case 'e': send(CT_KEY_END);   break;
  103.         case 'c': send(CT_KEY_CLR);   break;
  104.     default:  break;
  105.       }
  106.     }
  107.   }
  108.   cleanup();
  109.   exit(0);
  110. }
  111.  
  112. cleanup()
  113. {
  114.   ct_off();                /* turn off phone */
  115.   ct_lib_done();            /* cleanup library stuff */
  116. }
  117.  
  118. /* "push" key for 100 milliseconds */
  119. send(key)
  120.   int key;
  121. {
  122.   ct_keypress(key);
  123.   delay(100);
  124.   ct_keypress(CT_KEY_RELEASE);
  125. }
  126.