home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / mac / programm / 14689 < prev    next >
Encoding:
Text File  |  1992-08-29  |  4.1 KB  |  123 lines

  1. Path: sparky!uunet!sun-barr!ames!elroy.jpl.nasa.gov!sdd.hp.com!uakari.primate.wisc.edu!zazen!brahma.macc.wisc.edu!user
  2. From: headley@macc.wisc.edu (George Headley)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: ANSWER: How to turn on an extended keyboard LED
  5. Message-ID: <headley-280892120050@brahma.macc.wisc.edu>
  6. Date: 28 Aug 92 20:01:15 GMT
  7. Sender: news@macc.wisc.edu (USENET News System)
  8. Followup-To: comp.sys.mac.programmer
  9. Organization: Academic Computing Center, UW - Madison
  10. Lines: 111
  11.  
  12. THE LED SAGE:
  13.  
  14. A client of mine was recently test driving a program I wrote for him.  
  15. At one point when the program was in a data entry stage he turned to 
  16. me and said "Does the keypad work?"
  17.  
  18. "Of course!" I replied.
  19.  
  20. "Well, then the num lock light should be on." said the person paying
  21. big $$$ for custom software.
  22.  
  23. "I'll get right on it!" said I.
  24.  
  25. Well, back to the ranch I went. I immeadiately reached for such tomes
  26. as Knaster & Rollins, Chernikoff, etc planning to crib the necessary 
  27. code.  Well, imagine my shock when I found NOOOO mention of this area 
  28. of Macintosh arcana. So I broke down and read the desktop bus manager 
  29. chapter in IM V and the hardware reference guide.  Finally, the faint 
  30. glimmerings of the answer emerged.  After much experimentation I got 
  31. the num lock light to turn on and off and got a happy client.
  32.  
  33. The End......
  34.  
  35. So to save the rest of csmp the agony of this particular exercise I offer 
  36. forth the "answer".  If I've overlooked any particular aspect please 
  37. mail me your insights and I'll release a "fixed" version.
  38.  
  39. /*
  40.     FUNCTION:       OSErr SetLED ( Byte led)
  41.  
  42.     PURPOSE:        Turn on the specified Extended Keyboard LED.
  43.  
  44.     COMMENTS:       The following constants can be defined in a
  45.                     header file for the program that calls SetLED.
  46.  
  47.                     #define NUM_LOCK        1
  48.                     #define CAPS_LOCK       2
  49.                     #define SCROLL_LOCK     4
  50.                     
  51.                     Remember to leave the LED pattern the way you
  52.                     find it or the INTERFACE POLICE will get you!
  53.                     
  54.                     MPW users will need to replace the assembly
  55.                     language in the completion routine.
  56.     
  57.     EXAMPLES:       SetLED(NUM_LOCK);            NUM_LOCK on 
  58.                     SetLOCK(-NUM_LOCK);          NUM_LOCK off
  59.  
  60.     AUTHOR:         George W. Headley
  61.                     Madison Academic Computing Center
  62.                     University of Wisconsin - Madison
  63.                     (headley@macc.wisc.edu)
  64.  */
  65.  
  66. #include <DeskBus.h>
  67.  
  68. #define    kLEDTalk            14
  69. #define    kLEDListen          10
  70.  
  71. OSErr           SetLED         ( Byte ledPat );
  72. pascal void     CompADBOp      ( void );
  73.  
  74. OSErr SetLED (Byte led)
  75. {
  76.     OSErr            err;
  77.     int              i,numADBs;
  78.     ADBDataBlock     ADBDB[15];
  79.     ADBAddress       ADBadd[15];
  80.     Byte             SRbuf[8];
  81.     Boolean          flag=FALSE;
  82.  
  83.     numADBs = CountADBs();
  84.     for ( i=1 ; i <= numADBs ; i++ )
  85.     {
  86.         ADBadd[i] = GetIndADB(&ADBDB[i], i);
  87.         if ( ADBDB[i].origADBAddr == 2 && ADBDB[i].devType == 2 )
  88.         {
  89.             SRbuf[0] = 2;
  90.             err = ADBOp( (Ptr) &flag, CompADBOp, (Ptr) SRbuf, kLEDTalk + 16
  91.                          ADBadd[i]);
  92.             while ( flag != TRUE )    ;
  93.             if ( err != noErr )  return (err);
  94.             SRbuf[2] = SRbuf[2] - led;
  95.             flag = FALSE;
  96.             err = ADBOp( (Ptr) &flag, CompADBOp, (Ptr) SRbuf, kLEDListen +
  97. 16 * 
  98.                          ADBadd[i]);
  99.             while ( flag != TRUE | err != noErr ) ;
  100.         }
  101.     }
  102.     return (err);
  103. }
  104.  
  105. /*
  106.     FUNCTION:       pascal void CompADBOp ( void)
  107.  
  108.     PURPOSE:        Set to TRUE the address pointed to by register A2.
  109. */
  110.  
  111. pascal void CompADBOp()
  112. {
  113.     asm{
  114.             move.b        #1,(a2)
  115.         }
  116. }
  117. ___________________________________________________________________________
  118.   George Headley                        Office:  (608) 262-7240
  119.   Wide-Area Networks and Outreach
  120.   Academic Computing Center             Internet: headley@macc.wisc.edu
  121.   University of Wisconsin - Madison     Bitnet:   headley@wiscmacc.bitnet
  122.