/* begin(name)
   This function performs all tasks required to initialize the RN-42 HID module
   for use with the MaKey MaKey.
   We set up authentication, sleep, special config settings. As well as
   seting the auto-connect mode. The name can also be configured with the 
   *name* parameter. */
uint8_t makeyMateClass::begin(char * name)
{
  bluetooth.begin(9600);  // Initialize the software serial port at 9600
  freshStart();  // Get the module into a known mode, non-command mode, not connected

  while (!enterCommandMode())  // Enter command mode
      delay(100);    
  delay(BLUETOOTH_RESPONSE_DELAY);

  setAuthentication(1);  // enable authentication
  setName(name);  // Set the module name
  setMode(0);  // slave mode, worth trying mode 4 (auto dtr) as well 
  
  /* I'm torn on setting sleep mode. If you care about a low latency connection
   keep sleep mode set to 0000. You can save about 15mA of current consumption
   with the "80A0" setting, but I experience quite a bit more latency. */ 
  //setSleepMode("80A0");  // Deep sleep mode, 100ms sleeps - saves about 15mA when idling
  setSleepMode("0000");  // Low latency, high current usage ~ 40mA
  setSpecialConfig(16);  // optimize for low latency, short burst data
  
  /* These I wouldn't recommend changing. These settings are required for HID
     use and sending Keyboard and Mouse commands */
  setKeyboardMouseMode();  // bluetooth.println("SH,0030");
    
  // We must reboot if we're changing the mode to HID mode.
  // If you've already have the module in HID mode, this can be commented out
  if (!getHIDMode())
  {
    setHIDMode();  // Set RN-42 to HID profile mode
    reboot();
  }
  else
  {
    Serial.println("Already in HID mode!");
  }
}
Beispiel #2
0
int AT_Pre_Process (char *buf_cmd)
{
#if 0
	if(!strcmp(buf_cmd, SLEEPMODE)){
            LOGD(TAG "SLEEP_MODE");
            pret = setSleepMode(fd_atcmd);
            if(!strcmp(pret, STR_OK))
                write_chars(fd_uart, "OK\r",3);
            else
               write_chars(fd_uart, "ERROR\r",6);
        }
        else if(!strcmp(buf_cmd, EMER_CALL)){
            LOGD(TAG "EMERCALL");
            pret = dial112(fd_atcmd);
            if(!strcmp(pret, STR_OK))
                write_chars(fd_uart, "OK\r",3);
            else
               write_chars(fd_uart, "ERROR\r",6);
        } 
        else if(!strcmp(buf_cmd, GET_SN)) {
            LOGD(TAG "GET_SN");
            pret = getSN(buf_ret, sizeof(buf_ret), fd_atcmd);
            if(!strcmp(pret, STR_OK))
                write_chars(fd_uart, buf_ret, sizeof(buf_ret));
            else
               write_chars(fd_uart, "ERROR\r",6);
        }
         else if(strstr(buf_cmd, SET_SN) || !strcmp(buf_cmd, ATH)) {
            LOGD(TAG "%s\n", buf_cmd); 
            // Add '\r\n' tp command buf.
            buf_cmd[len] = '\r';
            buf_cmd[len+1] = '\n';
            buf_cmd[len+2] = '\0';
            pret = at_command_set(buf_cmd, fd_atcmd);
            if(!strcmp(pret, STR_OK))
                write_chars(fd_uart, "OK\r",3);
            else
               write_chars(fd_uart, "ERROR\r",6);
        }
        else if(!strcmp(buf_cmd, AT) || !strcmp(buf_cmd, ATE0)) {
            // AT and ATE0 are commands for test command between
            // ATE tool and target. Just return "OK\r" when receive.
            LOGD(TAG "%s\n", buf_cmd);
            write_chars(fd_uart, "OK\r",3);
        }               
        else{
            LOGD(TAG "Unsupported command\n");
            write_chars(fd_uart, "ERROR\r",6);            
        }
#endif

	#ifdef MTK_DT_SUPPORT
		if(!strcmp(buf_cmd, "AT+SWITCH"))
		{
            LOGD(TAG "AT+SWITCH");	
			if(g_mdFlag==1)
				g_mdFlag=2;
			else if(g_mdFlag==2)
				g_mdFlag=1;
			else
				LOGD(TAG "Unsupported MD Flag\n");
        }
	#endif
	return 0;
}
/** Power on and prepare for general usage.
 * This will activate the device and take it out of sleep mode (which must be done
 * after start-up). This function also sets both the accelerometer and the gyroscope
 * to their most sensitive settings, namely +/- 2g and +/- 250 degrees/sec, and sets
 * the clock source to use the X Gyro for reference, which is slightly better than
 * the default internal clock source.
 */
void MPU6050::init() {
	setSleepMode(false);
	setRangeAcceleration(0);
	setRangeGyroscope(0);
}