home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!ames!elroy.jpl.nasa.gov!sdd.hp.com!uakari.primate.wisc.edu!zazen!brahma.macc.wisc.edu!user
- From: headley@macc.wisc.edu (George Headley)
- Newsgroups: comp.sys.mac.programmer
- Subject: ANSWER: How to turn on an extended keyboard LED
- Message-ID: <headley-280892120050@brahma.macc.wisc.edu>
- Date: 28 Aug 92 20:01:15 GMT
- Sender: news@macc.wisc.edu (USENET News System)
- Followup-To: comp.sys.mac.programmer
- Organization: Academic Computing Center, UW - Madison
- Lines: 111
-
- THE LED SAGE:
-
- A client of mine was recently test driving a program I wrote for him.
- At one point when the program was in a data entry stage he turned to
- me and said "Does the keypad work?"
-
- "Of course!" I replied.
-
- "Well, then the num lock light should be on." said the person paying
- big $$$ for custom software.
-
- "I'll get right on it!" said I.
-
- Well, back to the ranch I went. I immeadiately reached for such tomes
- as Knaster & Rollins, Chernikoff, etc planning to crib the necessary
- code. Well, imagine my shock when I found NOOOO mention of this area
- of Macintosh arcana. So I broke down and read the desktop bus manager
- chapter in IM V and the hardware reference guide. Finally, the faint
- glimmerings of the answer emerged. After much experimentation I got
- the num lock light to turn on and off and got a happy client.
-
- The End......
-
- So to save the rest of csmp the agony of this particular exercise I offer
- forth the "answer". If I've overlooked any particular aspect please
- mail me your insights and I'll release a "fixed" version.
-
- /*
- FUNCTION: OSErr SetLED ( Byte led)
-
- PURPOSE: Turn on the specified Extended Keyboard LED.
-
- COMMENTS: The following constants can be defined in a
- header file for the program that calls SetLED.
-
- #define NUM_LOCK 1
- #define CAPS_LOCK 2
- #define SCROLL_LOCK 4
-
- Remember to leave the LED pattern the way you
- find it or the INTERFACE POLICE will get you!
-
- MPW users will need to replace the assembly
- language in the completion routine.
-
- EXAMPLES: SetLED(NUM_LOCK); NUM_LOCK on
- SetLOCK(-NUM_LOCK); NUM_LOCK off
-
- AUTHOR: George W. Headley
- Madison Academic Computing Center
- University of Wisconsin - Madison
- (headley@macc.wisc.edu)
- */
-
- #include <DeskBus.h>
-
- #define kLEDTalk 14
- #define kLEDListen 10
-
- OSErr SetLED ( Byte ledPat );
- pascal void CompADBOp ( void );
-
- OSErr SetLED (Byte led)
- {
- OSErr err;
- int i,numADBs;
- ADBDataBlock ADBDB[15];
- ADBAddress ADBadd[15];
- Byte SRbuf[8];
- Boolean flag=FALSE;
-
- numADBs = CountADBs();
- for ( i=1 ; i <= numADBs ; i++ )
- {
- ADBadd[i] = GetIndADB(&ADBDB[i], i);
- if ( ADBDB[i].origADBAddr == 2 && ADBDB[i].devType == 2 )
- {
- SRbuf[0] = 2;
- err = ADBOp( (Ptr) &flag, CompADBOp, (Ptr) SRbuf, kLEDTalk + 16
- *
- ADBadd[i]);
- while ( flag != TRUE ) ;
- if ( err != noErr ) return (err);
- SRbuf[2] = SRbuf[2] - led;
- flag = FALSE;
- err = ADBOp( (Ptr) &flag, CompADBOp, (Ptr) SRbuf, kLEDListen +
- 16 *
- ADBadd[i]);
- while ( flag != TRUE | err != noErr ) ;
- }
- }
- return (err);
- }
-
- /*
- FUNCTION: pascal void CompADBOp ( void)
-
- PURPOSE: Set to TRUE the address pointed to by register A2.
- */
-
- pascal void CompADBOp()
- {
- asm{
- move.b #1,(a2)
- }
- }
- ___________________________________________________________________________
- George Headley Office: (608) 262-7240
- Wide-Area Networks and Outreach
- Academic Computing Center Internet: headley@macc.wisc.edu
- University of Wisconsin - Madison Bitnet: headley@wiscmacc.bitnet
-