Пример #1
0
void settings_load()
{
    eeprom_read_block((void*)&conf, &conf_eep, sizeof(settings_t));
    if(settings_camera_index > 0)
    {
        eeprom_read_block((void*)&conf.camera, &camera_settings_eep[settings_camera_index - 1], sizeof(camera_settings_t));
    }
    if(conf.lcdContrast > 0xf || conf.lcdContrast < 0x1) conf.lcdContrast = 0x8;
    if(conf.lcdCoefficent > 0x7 || conf.lcdCoefficent < 0x3) conf.lcdCoefficent = 0x7;
    if(conf.lcdBias > 0x4 || conf.lcdBias < 0x3) conf.lcdBias = 0x4;
    if(conf.apertureMin > 100 || conf.apertureMin < 2) conf.apertureMin = 2;
    if(conf.lightIntegrationMinutes == 255 || conf.lightIntegrationMinutes == 0) conf.lightIntegrationMinutes = 10;
    if(conf.camera.brampGap > 20 || conf.camera.brampGap == 0) conf.camera.brampGap = 6;
    if(conf.errorAlert > 5) conf.errorAlert = 0;
    if(conf.linearInterpolation > 1) conf.linearInterpolation = 0;
    lcd.color(conf.lcdColor);
    ir.init();
    ir.make = conf.camera.cameraMake;
    if(conf.auxPort != AUX_MODE_DISABLED)
    {
        aux1_off();
        aux2_off();
    }
    if(bt.present && !remote.connected)
    {
        if(conf.btMode == BT_MODE_SLEEP) bt.sleep(); else bt.advertise();
    }
}
Пример #2
0
vector<string> Solution::prefix(vector<string> &A) 
{
    BT p;
    for(int i=0;i<A.size();i++)
        p.insert(A[i]);   
        
    p.getPrefix(A);
    
    return p.getAns();
}
Пример #3
0
uint8_t NMX::sendCommand(uint8_t command, uint8_t dataLength, uint8_t *data)
{
	if(!remote.nmx) return 0;

	char hexbuf[3];
	bt.sendCMD(PSTR("ATGW,0,28,0,0000000000FF"));

	uint8tohex(hexbuf, nodeAddress);
	bt.sendCMD((char*)hexbuf);

	uint8tohex(hexbuf, motorAddress);
	bt.sendCMD((char*)hexbuf);

	uint8tohex(hexbuf, command);
	bt.sendCMD((char*)hexbuf);

	uint8tohex(hexbuf, dataLength);
	bt.sendCMD((char*)hexbuf);

	for(uint8_t i = 0; i < dataLength; i++)
	{
		uint8tohex(hexbuf, data[i]);
		bt.sendCMD((char*)hexbuf);
	}

	bt.sendCMD(PSTR("\r"));
	return bt.checkOK();
}
Пример #4
0
void settings_load()
{
    eeprom_read_block((void*)&conf, &conf_eep, sizeof(settings));
    if(conf.lcdContrast > 0xf || conf.lcdContrast < 0x1) conf.lcdContrast = 0x8;
    if(conf.lcdCoefficent > 0x7 || conf.lcdCoefficent < 0x3) conf.lcdCoefficent = 0x7;
    if(conf.lcdBias > 0x4 || conf.lcdBias < 0x3) conf.lcdBias = 0x4;
    if(conf.apertureMin > 100 || conf.apertureMin < 2) conf.apertureMin = 2;
    lcd.color(conf.lcdColor);
    ir.init();
    ir.make = conf.cameraMake;
    if(conf.auxPort != AUX_MODE_DISABLED) aux_off();
    if(bt.present && !remote.connected)
    {
        if(conf.btMode == BT_MODE_SLEEP) bt.sleep(); else bt.advertise();
    }
}
Пример #5
0
void VDIP::processNXT(portConfig *portConfigBuffer)
{
	  char *name;
	  char *btAddress;
	  long	freeMemory;
          extern BT bt;
          if (myEEPROM2.getResetStatus() == (byte) 0){
	    if(nxtQueryDevice(this,portConfigBuffer->usbDev,&name,&btAddress,&freeMemory)){
              bt.setRemoteAddress(btAddress);
              delay(100);
              myEEPROM2.setResetStatus(1);
              delay(1000);
              software_Reset(); // increments the "status" so that the ChapR knows it has been reset
            }
          }    
}
Пример #6
0
BT<generic>::BT( BT & y)
{
	m_size = 0 ;
	m_root = NULL;
	
	Btn<generic> * temp ;
	
	PreOrder k ;

	for ( k = y.pre_begin() ; k != y.pre_end() ; k++)
	{
		i_give_up_insert (*k,k.current()->balance) ;
	}
	i_give_up_insert (*k,k.current()->balance) ;
	
}
Пример #7
0
uint8_t Remote::send(uint8_t id, uint8_t type)
{
	switch(id)
	{
		case REMOTE_BATTERY:
			return bt.sendDATA(id, type, (void *) &battery_percent, sizeof(uint8_t));
		case REMOTE_STATUS:
			return bt.sendDATA(id, type, (void *) &timer.status, sizeof(timer_status));
		case REMOTE_PROGRAM:
			return bt.sendDATA(id, type, (void *) &timer.current, sizeof(program));
		case REMOTE_START:
			return bt.sendDATA(id, type, 0, 0);
		case REMOTE_STOP:
			return bt.sendDATA(id, type, 0, 0);
	}
	return 0;
}
Пример #8
0
void debug(char *s)
{
    if(conf.debugEnabled == 0) return;
    if(VirtualSerial_connected)
        VirtualSerial_PutString(s);
    //else if(remote.connected && remote.model == REMOTE_MODEL_TLP)
        //remote.debug(s);
    else if(bt.state == BT_ST_CONNECTED)
        bt.send(s);
}
  void run()
  {
    typedef typename Space::execution_space ExecSpace;

    TestViewMappingSubview< ExecSpace > self;

    ASSERT_EQ( Aa.extent(0), AN );
    ASSERT_EQ( Ab.extent(0), AN - 2 );
    ASSERT_EQ( Ac.extent(0), AN - 2 );
    ASSERT_EQ( Ba.extent(0), BN0 );
    ASSERT_EQ( Ba.extent(1), BN1 );
    ASSERT_EQ( Ba.extent(2), BN2 );
    ASSERT_EQ( Bb.extent(0), BN0 - 2 );
    ASSERT_EQ( Bb.extent(1), BN1 - 2 );
    ASSERT_EQ( Bb.extent(2), BN2 - 2 );

    ASSERT_EQ( Ca.extent(0), CN0 );
    ASSERT_EQ( Ca.extent(1), CN1 );
    ASSERT_EQ( Ca.extent(2), CN2 );
    ASSERT_EQ( Ca.extent(3), 13 ); 
    ASSERT_EQ( Ca.extent(4), 14 );
    ASSERT_EQ( Cb.extent(0), CN0 - 2 );
    ASSERT_EQ( Cb.extent(1), CN1 - 2 );
    ASSERT_EQ( Cb.extent(2), CN2 - 2 );

    ASSERT_EQ( Da.extent(0), DN0 );
    ASSERT_EQ( Da.extent(1), DN1 );
    ASSERT_EQ( Da.extent(2), DN2 );
    ASSERT_EQ( Da.extent(3), DN3 );
    ASSERT_EQ( Da.extent(4), DN4 );

    ASSERT_EQ( Db.extent(0), DN1 - 2 );
    ASSERT_EQ( Db.extent(1), DN2 - 2 );
    ASSERT_EQ( Db.extent(2), DN3 - 2 );

    ASSERT_EQ( Da.stride_1(), Db.stride_0() );
    ASSERT_EQ( Da.stride_2(), Db.stride_1() );
    ASSERT_EQ( Da.stride_3(), Db.stride_2() );

    long error_count = -1;
    Kokkos::parallel_reduce( Kokkos::RangePolicy< ExecSpace >( 0, 1 ), *this, error_count );
    ASSERT_EQ( error_count, 0 );
  }
Пример #10
0
	void rotateRight(P y) { // zig
		BT tmp;
		P x = tmp.root();
		BT::assignFrom(x, -y);

		int& bx = (*x).balance();
		int& by = (*y).balance();

		BT::assignFrom(-y, +x);
		BT::assignFrom(+x, y);
		BT::assignFrom(y, x);

		if (bx >= 0)
			by++;
		else
			by -= bx - 1;

		if (by <= 0)
			bx++;
		else
			bx += by + 1;
	}
Пример #11
0
void hardware_off(void)
{
    hardware_flashlight(0);
    if(battery_status() == 0)
    {
        //if(timer.cableIsConnected())
        //{
        //    menu.message(STR("Error: Cable"));
        //}
        //else
        //{
            shutter_off();

            // Save the current time-lapse settings to nv-mem
            timer.saveCurrent();

            // If USB is used, detach from the bus
            USB_Detach();

            // Shutdown bluetooth
            bt.disconnect();
            bt.sleep();

            // Disable all interrupts
            cli();

            // Shutdown
            setHigh(POWER_HOLD_PIN);

            FOREVER;
        //}
    } 
    else // Plugged in
    {
        // Charging screen //
        clock.sleeping = 1;
        menu.spawn((void *) batteryStatus);
    }
}
Пример #12
0
// returns data length in bytes (max 4)
uint32_t NMX::sendQuery(uint8_t command)
{
	uint8_t b;
	uint32_t value = 0;
	if(sendCommand(command, 0, 0))
	{
		bt.sendCMD(PSTR("ATGR,0,24\r"));
		if(bt.checkOK())
		{
			char *buf;
			if(bt.waitEvent(STR("GATT_VAL"), &buf))
			{
				DEBUG(STR("GATT RESPONSE: "));
				DEBUG(buf);

				if(strncmp(buf, STR("GATT_VAL"), 8) == 0 && strlen(buf) >= 21)
				{
					uint8_t len;
					if(hextouint8(&len, &buf[22]))
					{
						if(len <= 4)
						{
							for(uint8_t i = 0; i < len; i++)
							{
								hextouint8(&b, &buf[24 + i * 2]);
								value += ((uint32_t)b << (8 * (len - i - 1)));
							}
							return value;
						}
					}
				}

				return 0;
			}
		}
	}
	return 0;
}
Пример #13
0
	void rotateLeft(P x) { // zag
		BT tmp;
		P y = tmp.root();
		BT::assignFrom(y, +x);

		int& bx = (*x).balance();
		int& by = (*y).balance();

		BT::assignFrom(+x, -y);
		BT::assignFrom(-y, x);
		BT::assignFrom(x, y);

		if (by <= 0)
			bx--;
		else
			bx -= by + 1;

		if (bx >= 0)
			by--;
		else
			by += bx - 1;

	}
Пример #14
0
void init()
{
    int n,l,r,w;
    cin>>n;
    for (int i=1; i<=n; ++i)
    {
        cin>>l>>r>>w;
        t.ins(i,l,r,w);
        ru[l]++; ru[r]++;
    }
    for (int i=1; i<=n; ++i)
        if (!ru[i])
        {
            t.root=i;
            break;
        }
}
Пример #15
0
void init()
{
    memset(ru,0,sizeof(ru));
    cin>>n;
    for (int i=1; i<=n; ++i)
    {
        cin>>l>>r;
        t.ins(i,l,r);
        ru[l]++; ru[r]++;
    }
    for (int i=1; i<=n; ++i)
        if (!ru[i])
        {
            t.root=i;
            break;
        }
}
Пример #16
0
void debug(const char *s)
{
    if(conf.debugEnabled == 0) return;
    if(VirtualSerial_connected)
    {
        char c = pgm_read_byte(s);
        while(c)
        {
            VirtualSerial_PutChar(c);
            s++;
            c = pgm_read_byte(s);
        }
    }
    //else if(remote.connected && remote.model == REMOTE_MODEL_TLP)
        //remote.debug(s);
    else if(bt.state == BT_ST_CONNECTED)
        bt.sendP(s);
}
Пример #17
0
uint8_t Remote::debugMessage(char *str)
{
	uint8_t len = 0;
	while(*(str + len) != '\0' && len < 255) len++;
	return bt.sendDATA(REMOTE_DEBUG, REMOTE_TYPE_SEND, (void *) str, len);
}
Пример #18
0
uint8_t Remote::set(uint8_t id, uint8_t value)
{
	return bt.sendDATA(id, REMOTE_TYPE_SET, (void *) &value, sizeof(value));
}
Пример #19
0
uint8_t Remote::unWatch(uint8_t id)
{
	return bt.sendDATA(id, REMOTE_TYPE_NOTIFY_UNWATCH, 0, 0);
}
Пример #20
0
uint8_t Remote::request(uint8_t id)
{
	requestActive = 1;
	return bt.sendDATA(id, REMOTE_TYPE_REQUEST, 0, 0);
}
volatile char sysInfo(char key, char first)
{
	if(first)
	{
		lcd.cls();

		char l;
		char* text;
		char buf[6];
		uint16_t val;

		// Lines (Y) = 6, 12, 18, 24, 30
		val = (uint16_t)bt.version();

		text = TEXT("TLP01");
		l = lcd.measureStringTiny(text);
		lcd.writeStringTiny(80 - l, 6 + SY, text);
		lcd.writeStringTiny(3, 6 + SY, TEXT("Model:"));

		if(val > 1)
			text = TEXT("BTLE");
		else
			text = TEXT("KS99");

		l = lcd.measureStringTiny(text);
		lcd.writeStringTiny(80 - l, 12 + SY, text);
		lcd.writeStringTiny(3, 12 + SY, TEXT("Edition:"));

		lcd.writeStringTiny(3, 18 + SY, TEXT("Firmware:"));
		uint32_t version = VERSION;

		char c;

		l = 0;

		while(version)
		{
			c = (char)(version % 10);
			buf[0] = ((char)(c + '0'));
			buf[1] = 0;
			text = buf;
			l += lcd.measureStringTiny(text) + 1;
			lcd.writeStringTiny(80 - l, 18 + SY, text);

			version -= (uint32_t)c;
			version /= 10;
		}

		if(val > 1)
		{
			int_to_str(val, buf);
			text = buf;
			l = lcd.measureStringTiny(text);
			lcd.writeStringTiny(80 - l, 30 + SY, text);
			lcd.writeStringTiny(3, 30 + SY, TEXT("BT FW Version:"));
		}

		menu.setTitle(TEXT("System Info"));
		menu.setBar(TEXT("RETURN"), BLANK_STR);
		lcd.update();
	}

	if(key == FL_KEY || key == LEFT_KEY)
		return FN_CANCEL;

	return FN_CONTINUE;
}
Пример #22
0
int main()
{
	int n,x;
	BT Tree;
	Tree.root = Tree.newNode(1);
	Tree.root->left = Tree.newNode(2);
	Tree.root->right = Tree.newNode(3);
	Tree.root->left->left = Tree.newNode(4);
	Tree.root->left->right = Tree.newNode(5);
	Tree.root->random = Tree.root->left->right;
	Tree.root->left->left->random = Tree.root;
	Tree.root->left->right->random = Tree.root->right;
	Tree.inorder(Tree.root);
	cout<<endl;

	BT ClonedBT;
	ClonedBT.root = ClonedBT.clone(Tree.root);
	ClonedBT.inorder(ClonedBT.root);
	cout<<endl;

	map<Node*,Node*>* M = pointerMap(&Tree, &ClonedBT);
	map<Node*,Node*>::iterator it;
	// cout<<"Pointer to pointer map :\n";
	// for(it=M->begin(); it!=M->end();it++)
	// 	cout<<it->first<<" -> "<<it->second<<endl;
	
	map<Node*,Node*>* M_reverse = new map<Node*,Node*>;
	for(it=M->begin();it!=M->end();it++)
		(*M_reverse)[it->second]=it->first;

	// cout<<"Reverse map :\n";
	// for(it=M_reverse->begin(); it!=M_reverse->end();it++)
	// 	cout<<it->first<<" -> "<<it->second<<endl;
	clone_random(M,M_reverse,ClonedBT.root);
	
	Tree.inorder_random(Tree.root);
	cout<<endl;
	ClonedBT.inorder_random(ClonedBT.root);
	cout<<endl;
	return 0;
}
Пример #23
0
uint8_t Remote::send(uint8_t id, uint8_t type)
{
	switch(id)
	{
		case REMOTE_BATTERY:
			return bt.sendDATA(id, type, (void *) &battery_percent, sizeof(battery_percent));
		case REMOTE_STATUS:
			return bt.sendDATA(id, type, (void *) &timer.status, sizeof(timer.status));
		case REMOTE_PROGRAM:
			return bt.sendDATA(id, type, (void *) &timer.current, sizeof(timer.current));
		case REMOTE_MODEL:
		{
			uint8_t tmp = REMOTE_MODEL_TLP;
			return bt.sendDATA(id, type, (void *) &tmp, sizeof(uint8_t));
		}
		case REMOTE_FIRMWARE:
		{
			unsigned long version = VERSION;
			void *ptr = &version;
			return bt.sendDATA(id, type, ptr, sizeof(version));
		}
		case REMOTE_BT_FW_VERSION:
		{
			uint8_t btVersion = bt.version();
			return bt.sendDATA(id, type, (void *) &btVersion, sizeof(btVersion));
		}
		case REMOTE_PROTOCOL_VERSION:
		{
			unsigned long remoteVersion = REMOTE_VERSION;
			void *ptr = &remoteVersion;
			return bt.sendDATA(id, type, ptr, sizeof(remoteVersion));
		}
		case REMOTE_CAMERA_FPS:
			return bt.sendDATA(id, type, (void *) &conf.cameraFPS, sizeof(conf.cameraFPS));
		case REMOTE_CAMERA_MAKE:
			return bt.sendDATA(id, type, (void *) &conf.cameraMake, sizeof(conf.cameraMake));
		case REMOTE_ISO:
		{
			uint8_t tmp = camera.iso();
			return bt.sendDATA(id, type, (void *) &tmp, sizeof(tmp));
		}
		case REMOTE_APERTURE:
		{
			uint8_t tmp = camera.aperture();
			return bt.sendDATA(id, type, (void *) &tmp, sizeof(tmp));
		}
		case REMOTE_SHUTTER:
		{
			uint8_t tmp = camera.shutter();
			return bt.sendDATA(id, type, (void *) &tmp, sizeof(tmp));
		}
		case REMOTE_VIDEO:
		{
			uint8_t tmp = camera.recording;
			return bt.sendDATA(id, type, (void *) &tmp, sizeof(tmp));
		}
		case REMOTE_LIVEVIEW:
		{
			uint8_t tmp = camera.modeLiveView;
			return bt.sendDATA(id, type, (void *) &tmp, sizeof(tmp));
		}
		case REMOTE_THUMBNAIL:
		{
			menu.message(STR("Busy"));
/*
			uint8_t ret = camera.getCurrentThumbStart();
			if(ret != PTP_RETURN_ERROR)
			{
				bt.sendDATA(REMOTE_THUMBNAIL_SIZE, type, (void *) &PTP_Bytes_Total, sizeof(PTP_Bytes_Total));
				bt.sendDATA(id, type, (void *) PTP_Buffer, PTP_Bytes_Received);
				while(ret == PTP_RETURN_DATA_REMAINING)
				{
					ret = camera.getCurrentThumbContinued();
					bt.sendDATA(id, type, (void *) PTP_Buffer, PTP_Bytes_Received);
				}
			}
*/
			///////////////////////// DEMO Code ////////////////////////////
			PTP_Bytes_Total = sizeof(thm);
			bt.sendDATA(REMOTE_THUMBNAIL_SIZE, type, (void *) &PTP_Bytes_Total, sizeof(PTP_Bytes_Total));
			uint16_t total_sent = 0, i;
			while(total_sent < PTP_Bytes_Total)
			{
				for(i = 0; i < PTP_BUFFER_SIZE; i++)
				{
					PTP_Buffer[i] = pgm_read_byte(&thm[i + total_sent]);
					if(total_sent + i >= PTP_Bytes_Total) break;
				}
				PTP_Bytes_Received = i;
				total_sent += PTP_Bytes_Received;
				if(PTP_Bytes_Received == 0) break;
				bt.sendDATA(id, type, (void *) PTP_Buffer, PTP_Bytes_Received);
				if(total_sent >= PTP_Bytes_Total) break;
			}
			/////////////////////////////////////////////////////////////////
			return 0;
		}
		default:
			return bt.sendDATA(id, type, 0, 0);
	}
	return 0;
}
Пример #24
0
//
// processDisk() - called when a disk is discovered and properly located
//                 on P2.  This routine does everything that the Chapr can
//                 do with a flash drive, like update the name of the Chapr.
//
void VDIP::processDisk(portConfig *portConfigBuffer)
{    
     char buf[BIGENOUGH];

     // check that it's in port two (beep annoyingly otherwise)

     if(portConfigBuffer->port == 1) {

       // read through VDIP stuff looking for a text file with the name, personality etc.

       // PLEASE NOTE -- FILE NAMES MUST BE FEWER THAN 8 CHARACTERS

       // get the new name of the ChapR

       if(readFile("name.txt", buf, BIGENOUGH)){
         if (buf[EEPROM_NAMELENGTH - 1] == '\0'){
           myEEPROM.setName(buf);
         }
       }

       // get the new personality

       if(readFile("person.txt", buf, BIGENOUGH)){
         byte newNum = (byte) atoi(buf);
         if (newNum > 0 && newNum <= EEPROM_LASTPERSON){
           myEEPROM.setPersonality(newNum);
         }
       }

       // get the power-down timeout

       if(readFile("timeout.txt", buf, BIGENOUGH)){
         byte newNum = (byte) atoi(buf);
         if (newNum >= 0 && newNum <= EEPROM_MAXTIMEOUT){
         myEEPROM.setTimeout(newNum);
         }
       }

       // get the lag time

       if(readFile("lag.txt", buf, BIGENOUGH)){
         byte newNum = (byte) atoi(buf);
         if (newNum >= 0 && newNum <= EEPROM_MAXLAG){
         myEEPROM.setSpeed(newNum);
         }
       }

       // get the user mode

       if(readFile("mode.txt", buf, BIGENOUGH)){
         byte newNum = (byte) atoi(buf);
         if (newNum >= 0 && newNum <= EEPROM_MAXMODE){
         myEEPROM.setMode(newNum);
         }
       }
       
       // allows user to determine number of seconds in autonomous, teleOp and endgame (ChapR3 of EEPROM)
       // zero for either mode skips the mode

       if(readFile("mConfig.txt",buf, BIGENOUGH)){
	 char *ptr = buf;
	 for (int i = 0; i < 3; i++){
	   switch(i){
	   case 0: myEEPROM.setAutoLen(atoi(ptr));break;
	   case 1: myEEPROM.setTeleLen(atoi(ptr));break;
	   case 2: myEEPROM.setEndLen(atoi(ptr));break;
	   }
	   while (*ptr != '\r' && *ptr != '\0' && *ptr != '\n'){
	     ptr++;
	   }
	   while (*ptr == '\r' && *ptr == '\n'){
	     ptr++;
	   }
	   if (*ptr == '\0'){
	     break;
	   }
	 }
       }
     

       // contains the settings for the digital I/O pins (for FRC, aka ChapR3 of EEPROM)
     
       if (readFile("dgtlIn.txt", buf, BIGENOUGH)){
	 byte newNum = 0;
	 
	 for (int i = 0, ptr = 0; i < 8; i++){
	   byte bit = (buf[ptr] == '1')?1:0;
	   newNum |= bit<<i;
	   while (buf[ptr] != '\r' && buf[ptr] != '\0' && buf[ptr] != '\n'){
	     ptr++;
	   }
	   while (buf[ptr] == '\r' || buf[ptr] == '\n'){
	     ptr++;
	   }
	   if (buf[ptr] == '\0'){
	     break;
	   }
	 }
	 
	 myEEPROM.setDigitalInputs(newNum);
       }

       // contains the 4 analog inputs (for FRC, aka ChapR3 of EEPROM)
       
       if (readFile("analogIn.txt", buf, BIGENOUGH)){
	 char *ptr = buf;
	 for (int i = 0; i < 4; i++){
	   double value = atof(ptr);
	   if (value > 0 && value <= 5) {
	     value = (value*1023)/5;
		// TODO - translate to labview preferences here
		switch(i) {
		case 0:		myEEPROM.setAnalogInput1(value); break;
		case 1:		myEEPROM.setAnalogInput2(value); break;
		case 2:		myEEPROM.setAnalogInput3(value); break;
		case 3:		myEEPROM.setAnalogInput4(value); break;
		}
	   }
	   while (*ptr != '\r' && *ptr != '\0' && *ptr != '\n'){
	     ptr++;
	   }
	   while (*ptr == '\r' || *ptr == '\n'){
	     ptr++;
	   }
	   if (*ptr == '\0'){
	     break;
	   }
	 }
       }

       // get a target bluetooth connection name/ID AND connect if it is there
       // this MAY need to be changed to do the connection AFTER getting
       // done with the flash drive.  Note that this data IS NOT stored in
       // the EEPROM - instead, it is just used as the current paired device
       // and will be reset (like normal) whenever a new pairing is done.

       extern BT bt;

       if(readFile("targetID.txt", buf, BIGENOUGH,true)){
	    if (bt.addressFilter(buf,BIGENOUGH)) {	// useful address?
		 bt.setRemoteAddress(buf);
		 delay(100);
	    }
       }

// TODO: make target.txt work - it should take a NAME and find the BT ID for it

       if(readFile("target.txt", buf, BIGENOUGH,true)){
//	    Serial.print("target: \"");
//	    Serial.print(buf);
//	    Serial.println("\"");
//	    if(bt.nameToAddress(buf)) {
//		 bt.setRemoteAddress(buf);
//		 delay(100);
//	    }
       }

       // the confirm beep indicates that all files that existed were read
       // it doesn't confirm that all data was cool

       beeper.confirm();			 

     } else {

       // the disk was put in the wrong USB port!

       beeper.icky();

     } 
}
volatile char btConnect(char key, char first)
{
	static uint8_t sfirst = 1;
	uint8_t i;
	static uint8_t menuSize;
	static uint8_t menuSelected;
	uint8_t c;
	uint8_t update, menuScroll;
	update = 0;

	if(sfirst)
	{
		menuScroll = 0;
		menuSelected = 0;
		sfirst = 0;

		update = 1;
		if(bt.state != BT_ST_CONNECTED)
		{
			bt.advertise();
			bt.scan();
		}
	}

	switch(key)
	{
		case LEFT_KEY:
		case FL_KEY:
			sfirst = 1;
			if(bt.state != BT_ST_CONNECTED) bt.sleep();
			return FN_CANCEL;

		case FR_KEY:
			if(bt.state == BT_ST_CONNECTED)
			{
				bt.disconnect();
			}
			else
			{
				bt.connect(bt.device[menuSelected].addr);
			}
			break;
	}

	update = 1;
	switch(bt.event)
	{
		case BT_EVENT_DISCOVERY:
			debug(STR("dicovery!\r\n"));
			break;
		case BT_EVENT_SCAN_COMPLETE:
			debug(STR("done!\r\n"));
			if(bt.state != BT_ST_CONNECTED) bt.scan();
			break;
		case BT_EVENT_DISCONNECT:		
			bt.scan();
			break;
		default:
			update = 0;
	}

	bt.event = BT_EVENT_NULL; // clear event so we don't process it twice

	if(first)
	{
		update = 1;
	}

	if(key == UP_KEY && menuSelected > 0)
	{
		menuSelected--;
		update = 1;
	}
	else if(key == DOWN_KEY && menuSelected < menuSize - 1)
	{
		menuSelected++;
		update = 1;
	}

	if(update)
	{
		lcd.cls();

		if(bt.state == BT_ST_CONNECTED)
		{
			menu.setTitle(TEXT("Connect"));
			lcd.writeStringTiny(18, 20, TEXT("Connected!"));
			menu.setBar(TEXT("RETURN"), TEXT("DISCONNECT"));
		}
		else
		{
			if(menuSelected > 2)
				menuScroll = menuSelected - 2;

			menuSize = 0;

			for(i = 0; i < bt.devices; i++)
			{
				if(i >= menuScroll && i <= menuScroll + 4)
				{
					for(c = 0; c < MENU_NAME_LEN - 1; c++) // Write settings item text //
					{
							if(bt.device[i].name[c])
								lcd.writeChar(3 + c * 6, 8 + 9 * (menuSize - menuScroll), bt.device[i].name[c]);
					}
				}
				menuSize++;
			}

			if(bt.devices)
			{
				lcd.drawHighlight(2, 7 + 9 * (menuSelected - menuScroll), 81, 7 + 9 * (menuSelected - menuScroll) + 8);
				menu.setBar(TEXT("RETURN"), TEXT("CONNECT"));
			}
			else
			{
				lcd.writeStringTiny(6, 20, TEXT("No Devices Found"));
				menu.setBar(TEXT("RETURN"), BLANK_STR);
			}

			menu.setTitle(TEXT("Connect"));

			lcd.drawLine(0, 3, 0, 40);
			lcd.drawLine(83, 3, 83, 40);
		}

		lcd.update();
	}

	return FN_CONTINUE;
}