1   /*
2    * Copyright 2007-2008 Volker Fritzsch
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License. 
15   */
16  package motej.demos.discovery;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import motej.Mote;
22  import motej.MoteFinder;
23  import motej.MoteFinderListener;
24  
25  /**
26   * 
27   * <p>
28   * @author <a href="mailto:vfritzsch@users.sourceforge.net">Volker Fritzsch</a>
29   */
30  public class AdvancedDiscovery {
31  
32  	private static List<Mote> motes = new ArrayList<Mote>();
33  	
34  	public static void main(String[] args) throws InterruptedException {
35  		MoteFinderListener listener = new MoteFinderListener() {
36  		
37  			public void moteFound(Mote mote) {
38  				System.out.println("Found mote: " + mote.getBluetoothAddress());
39  				mote.rumble(2000l);
40  				motes.add(mote);
41  			}
42  		
43  		};
44  		
45  		MoteFinder finder = MoteFinder.getMoteFinder();
46  		finder.addMoteFinderListener(listener);
47  		
48  		System.out.println("Starting discovery..");
49  		finder.startDiscovery();
50  		
51  		System.out.println("Putting thread to sleep..");
52  		Thread.sleep(30000l);
53  		
54  		System.out.println("Stopping discovery..");
55  		finder.stopDiscovery();
56  		
57  		for (Mote m : motes) {
58  			m.disconnect();
59  		}
60  	}
61  
62  }