Ejemplo n.º 1
0
void ledThrottlePattern() {
    if (rcThrottle < 200) {
        blinkleds(1);
    }
    if (rcThrottle >= 200) {
        blinkleds(0);
    }
}
Ejemplo n.º 2
0
void
akbdattach(struct device *parent, struct device *self, void *aux)
{
	ADBSetInfoBlock adbinfo;
	struct akbd_softc *sc = (struct akbd_softc *)self;
	struct adb_attach_args *aa_args = (struct adb_attach_args *)aux;
	int error, kbd_done;
	short cmd;
	u_char buffer[9];
	struct wskbddev_attach_args a;
	static int akbd_console_initted;
	int wskbd_eligible = 1;

	sc->origaddr = aa_args->origaddr;
	sc->adbaddr = aa_args->adbaddr;
	sc->handler_id = aa_args->handler_id;

	sc->sc_leds = (u_int8_t)0x00;	/* initially off */
	sc->sc_caps = 0;
	sc->sc_iso = 0;

	adbinfo.siServiceRtPtr = (Ptr)akbd_adbcomplete;
	adbinfo.siDataAreaAddr = (caddr_t)sc;

	printf(": ");
	switch (sc->handler_id) {
	case ADB_STDKBD:
		printf("standard keyboard\n");
		break;
	case ADB_ISOKBD:
		printf("standard keyboard (ISO layout)\n");
		sc->sc_iso = 1;
		break;
	case ADB_EXTKBD:
		cmd = ADBTALK(sc->adbaddr, 1);
		kbd_done =
		    (adb_op_sync((Ptr)buffer, cmd) == 0);

		/* Ignore Logitech MouseMan/Trackman pseudo keyboard */
		if (kbd_done && buffer[1] == 0x9a && buffer[2] == 0x20) {
			printf("Mouseman (non-EMP) pseudo keyboard\n");
			adbinfo.siServiceRtPtr = (Ptr)0;
			adbinfo.siDataAreaAddr = (Ptr)0;
			wskbd_eligible = 0;
		} else if (kbd_done && buffer[1] == 0x9a && buffer[2] == 0x21) {
			printf("Trackman (non-EMP) pseudo keyboard\n");
			adbinfo.siServiceRtPtr = (Ptr)0;
			adbinfo.siDataAreaAddr = (Ptr)0;
			wskbd_eligible = 0;
		} else {
			printf("extended keyboard\n");
#ifdef notyet
			blinkleds(sc);
#endif
		}
		break;
	case ADB_EXTISOKBD:
		printf("extended keyboard (ISO layout)\n");
		sc->sc_iso = 1;
#ifdef notyet
		blinkleds(sc);
#endif
		break;
	case ADB_KBDII:
		printf("keyboard II\n");
		break;
	case ADB_ISOKBDII:
		printf("keyboard II (ISO layout)\n");
		sc->sc_iso = 1;
		break;
	case ADB_PBKBD:
		printf("PowerBook keyboard\n");
		break;
	case ADB_PBISOKBD:
		printf("PowerBook keyboard (ISO layout)\n");
		sc->sc_iso = 1;
		break;
	case ADB_ADJKPD:
		printf("adjustable keypad\n");
		wskbd_eligible = 0;
		break;
	case ADB_ADJKBD:
		printf("adjustable keyboard\n");
		break;
	case ADB_ADJISOKBD:
		printf("adjustable keyboard (ISO layout)\n");
		sc->sc_iso = 1;
		break;
	case ADB_ADJJAPKBD:
		printf("adjustable keyboard (Japanese layout)\n");
		break;
	case ADB_PBEXTISOKBD:
		printf("PowerBook extended keyboard (ISO layout)\n");
		sc->sc_iso = 1;
		break;
	case ADB_PBEXTJAPKBD:
		printf("PowerBook extended keyboard (Japanese layout)\n");
		break;
	case ADB_JPKBDII:
		printf("keyboard II (Japanese layout)\n");
		break;
	case ADB_PBEXTKBD:
		printf("PowerBook extended keyboard\n");
		break;
	case ADB_DESIGNKBD:
		printf("extended keyboard\n");
#ifdef notyet
		blinkleds(sc);
#endif
		break;
	case ADB_PBJPKBD:
		printf("PowerBook keyboard (Japanese layout)\n");
		break;
	case ADB_PBG3JPKBD:
		printf("PowerBook G3 keyboard (Japanese layout)\n");
		break;
	case ADB_PBG4KBD:
		printf("PowerBook G4 keyboard (Inverted T)\n");
		break;
	case ADB_IBITISOKBD:
		printf("iBook keyboard with inverted T (ISO layout)\n");
		sc->sc_iso = 1;
		break;
	default:
		printf("mapped device (%d)\n", sc->handler_id);
#if 0
		wskbd_eligible = 0;
#endif
		break;
	}
	error = set_adb_info(&adbinfo, sc->adbaddr);
#ifdef ADB_DEBUG
	if (adb_debug)
		printf("akbd: returned %d from set_adb_info\n", error);
#endif

	if (akbd_is_console() && wskbd_eligible)
		a.console = (++akbd_console_initted == 1);
	else
		a.console = 0;
	a.keymap = &akbd_keymapdata;
	a.accessops = &akbd_accessops;
	a.accesscookie = sc;

	sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
}
Ejemplo n.º 3
0
void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  P1DIR |= 0x03;                        // Set P1.0 & P1.1 to output direction
  P1OUT = 0x04;                         // Dummy, to set P1.2 pullup (S1 grounds P1.2!!)
  P1REN |= 0x04;                        // sets P1.2 pullup


    volatile unsigned int B_pressed=0;           // volatile to prevent optimization -
    volatile unsigned int Led_Blink_on=0;
    volatile unsigned int B_sense=0;
    volatile unsigned int i=0;
    volatile unsigned int tmp=0;
    volatile unsigned int k=25000;				// ~half second time period for exercise 4
    volatile unsigned int r=0;					// used for button counter

// Exercise 2: Detect the presence of button and blink RED LED for ~1 sec

// Exercise 3: Start and stop (freeze) LED blink sequence
// according to button pressed. When unfreezed, Green LED blinks
// twice as fast as RED


// Exercise 4: Start and stop (freeze) RED LED blink sequence
// according to button pressed. If button is pressed twice
//(momentarily), then double the blink frequency.

  for (;;)
  {
	  B_sense = P1IN & 0x04;
	 /* do{						// check how many times button pressed in half second
		  if(B_sense == 0)		// detect press of button
		  {
			  do
				  B_sense = P1IN & 0x04;
			  while(B_sense == 0);
			  r++;				// if pressed add r + 1
		  }
		  k--;
	  }while((k != 0) & (r != 2));			// while half second not passed and not pressed 2 times
	  k=25000;					// give back ~half second
	  if (r == 2)				// if button pressed 2 times
	  {
		  do{					// not yet sure
			  blinkfast();
			  B_sense = P1IN & 0x04;	// continuously check if button is pressed
		  }while(B_sense != 0);
		  r=0;					// make r 0 for next counting
	  }*/

   if (B_sense==0) //debounce
      {
	   	   do
	   	   {
	   		   B_sense = P1IN & 0x04;	// continuously check if button is pressed

	   	   }while(B_sense == 0);		// and exit the loop when button unpressed

	   	   B_pressed ^= 1;				// change the B_pressed by xoring it
	   	   if(B_pressed == 1)			// if it is 1
	   	   {
	   		   Led_Blink_on = 1;		// change variable value to 1
	   		   //tmp = 0;
	   	   }
	   	   else							// if not
	   	   {
	   		   Led_Blink_on = 0;		// change variable value to 0
	   		   tmp ^= 1;				// by xoring tmp we tell blinkleds function to what frequency to blink them
	   	   }

      }
   else									// if b_sense = 0 which it is after button is unpressed
   {
	   if(Led_Blink_on == 1)			// if led blink is on
	   {
		   do{
			   B_sense = P1IN & 0x04;
			   blinkleds(tmp);				// blink leds according to tmp
	   }while(B_sense != 0);
	   }
	   else								// or else
	   {
		   do{
			   B_sense = P1IN & 0x04;
			   freeze();				// freeze leds
		   }while(B_sense != 0);
	   }
   }
 }

}