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.buttons;
17  
18  import motej.Mote;
19  import motej.MoteFinder;
20  import motej.event.CoreButtonEvent;
21  import motej.event.CoreButtonListener;
22  
23  /**
24   * 
25   * <p>
26   * @author <a href="mailto:vfritzsch@users.sourceforge.net">Volker Fritzsch</a>
27   */
28  public class ButtonsDemo {
29  
30  	public static void main(String[] args) {
31  		System.out.println("press 'q' to quit.");
32  		
33  		Mote mote = MoteFinder.getMoteFinder().findMote();
34  		mote.addCoreButtonListener(new CoreButtonListener() {
35  		
36  			public void buttonPressed(CoreButtonEvent evt) {
37  				if (evt.isButtonAPressed()) {
38  					System.out.println("Button A pressed!");
39  				}
40  				if (evt.isButtonBPressed()) {
41  					System.out.println("Button B pressed!");
42  				}
43  				if (evt.isNoButtonPressed()) {
44  					System.out.println("No button pressed.");
45  				}
46  			}
47  		
48  		});
49  		
50  		while (true) {
51  			String line = System.console().readLine();
52  			if (line.indexOf("q") != -1) {
53  				mote.disconnect();
54  				System.exit(0);
55  			}
56  		}
57  	}
58  }