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.demos.common.SimpleMoteFinder;
20  import motej.event.CoreButtonEvent;
21  import motej.event.CoreButtonListener;
22  
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  /**
27   * 
28   * <p>
29   * @author <a href="mailto:vfritzsch@users.sourceforge.net">Volker Fritzsch</a>
30   */
31  public class ButtonsDemo {
32  	
33  	private static Logger log = LoggerFactory.getLogger(ButtonsDemo.class);
34  
35  	public static void main(String[] args) {
36  		SimpleMoteFinder simpleMoteFinder = new SimpleMoteFinder();
37  		Mote mote = simpleMoteFinder.findMote();
38  		mote.addCoreButtonListener(new CoreButtonListener() {
39  		
40  			public void buttonPressed(CoreButtonEvent evt) {
41  				if (evt.isButtonAPressed()) {
42  					System.out.println("Button A pressed!");
43  				}
44  				if (evt.isButtonBPressed()) {
45  					System.out.println("Button B pressed!");
46  				}
47  				if (evt.isNoButtonPressed()) {
48  					System.out.println("No button pressed.");
49  				}
50  			}
51  		
52  		});
53  		
54  		try {
55  			Thread.sleep(60000l);
56  		} catch (InterruptedException ex) {
57  			log.error(ex.getMessage(), ex);
58  		} finally {
59  			mote.disconnect();
60  		}
61  	}
62  }