当前位置: 首页>>代码示例>>Java>>正文


Java Button.waitForAnyEvent方法代码示例

本文整理汇总了Java中lejos.hardware.Button.waitForAnyEvent方法的典型用法代码示例。如果您正苦于以下问题:Java Button.waitForAnyEvent方法的具体用法?Java Button.waitForAnyEvent怎么用?Java Button.waitForAnyEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lejos.hardware.Button的用法示例。


在下文中一共展示了Button.waitForAnyEvent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: adjustAngle

import lejos.hardware.Button; //导入方法依赖的package包/类
private void adjustAngle(boolean reverse) {
    pilot.travel(-MOVE_DISTANCE_TO_ADJUST_ANGLE);
    double firstDist = getAccurateDistance(); // 15.48
    pilot.travel(MOVE_DISTANCE_TO_ADJUST_ANGLE);
    double secondDist = getAccurateDistance(); // 9.5
    double tantheta = (secondDist - firstDist) / MOVE_DISTANCE_TO_ADJUST_ANGLE;
    if (Math.abs(secondDist - firstDist) > 10 || firstDist > OCCUPIED_THRESHOLD || secondDist > OCCUPIED_THRESHOLD) {
        return;
    }
    double theta = Math.atan(tantheta) * 180 / Math.PI;
    System.out.println("theta: " + theta);
    if (Math.abs(theta) > ADJUST_ANGLE_THRESHOLD) {
        Button.waitForAnyEvent();
        theta = 0;
    }
    theta *= reverse ? -1 : 1;
    pilot.rotate(theta);
}
 
开发者ID:JINKEHE,项目名称:Rescue-Victims,代码行数:19,代码来源:Megatron.java

示例2: run

import lejos.hardware.Button; //导入方法依赖的package包/类
@Override
public void run() {
	if (Button.waitForAnyEvent() == Button.ID_ESCAPE) {
		try {
			this.connection.close();
		} catch (IOException e) {
			System.err.println("Error when closing connection: " + e.getMessage());
		}
		if (this.debugPrint)
			System.out.println("Closing connection...");
	}
}
 
开发者ID:alisharif2,项目名称:dpm-project,代码行数:13,代码来源:WifiConnection.java

示例3: uncaughtException

import lejos.hardware.Button; //导入方法依赖的package包/类
@Override
public void uncaughtException(Thread th, Throwable t)  {
	Sound.buzz();
    TextLCD lcd = LocalEV3.get().getTextLCD(Font.getSmallFont());
    int offset = 0;
    while (true)
    {
   		lcd.clear();
   		lcd.drawString("Uncaught exception:", offset, 0);
   		lcd.drawString(t.getClass().getName(), offset, 2);
   		if (t.getMessage() != null) lcd.drawString(t.getMessage(), offset, 3);		
   		
   		if (t.getCause() != null) {
   			lcd.drawString("Caused by:", offset, 5);
   			lcd.drawString(t.getCause().toString(), offset, 6);
   		}
   		
   		StackTraceElement[] trace = t.getStackTrace();
   		for(int i=0;i<7 && i < trace.length ;i++) lcd.drawString(trace[i].toString(), offset, 8+i);
   		
   		lcd.refresh();
   		int id = Button.waitForAnyEvent();
   		if (id == Button.ID_ESCAPE) break;
   		if (id == Button.ID_LEFT) offset += 5;
   		if (id == Button.ID_RIGHT)offset -= 5;
   		if (offset > 0) offset = 0;
    }
    
    // Shutdown the EV3
   	try {
		Runtime.getRuntime().exec("init 0");
	} catch (IOException e) {
		// Ignore
	}
    System.exit(1);
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:37,代码来源:ExceptionHandler.java

示例4: waitForAnyEvent

import lejos.hardware.Button; //导入方法依赖的package包/类
/**
 * Wait for any press. it will block the current thread.
 * @return key value of the keyboard, can be multi-keys.
 */
public Event waitForAnyEvent() {
	int k = Button.waitForAnyEvent();
	if((k & 0xFF00) != 0) {
		return new Event(Event.KEY_RELEASE, (k>>8) & 0x0FF);	
	}
	
	return new Event(Event.KEY_PRESS, k);	
}
 
开发者ID:MisaZhu,项目名称:EV3GUI.leJOS,代码行数:13,代码来源:BrickButton.java

示例5: getIPAddress

import lejos.hardware.Button; //导入方法依赖的package包/类
/**
 * Requests an IP Address from the user where the server is running.<br>
 * For developer version only.
 */
private String getIPAddress() {
    String customaddress = "";
    if ( openrobertaProperties != null ) {
        customaddress = openrobertaProperties.getProperty("customaddress");
    }
    if ( customaddress == null || customaddress.equals("") ) {
        customaddress = "";
    }

    int i = 1;
    newScreen("Server?");
    lcd.drawString("lab.open-roberta.org", 0, 1, true);
    lcd.drawString("10.0.1.10:1999", 0, 2, false);
    lcd.drawString(customaddress, 0, 3, false);
    lcd.drawString("Another (type in)", 0, 4, false);
    lcd.drawString("(ESCAPE to exit)", 0, 7);

    while ( true ) {
        int id = Button.waitForAnyEvent(500);
        if ( id == Button.ID_ENTER ) {
            customaddress = select(i, customaddress);
            if ( customaddress == null ) {
                return enterIP();
            } else {
                return customaddress;
            }
        }
        if ( id == Button.ID_ESCAPE ) {
            return "";
        }
        if ( id == Button.ID_DOWN || id == Button.ID_RIGHT ) {
            if ( i != 4 ) {
                rewrite(i, false, customaddress);
                i++;
                rewrite(i, true, customaddress);
            } else {
                rewrite(i, false, customaddress);
                i = 1;
                rewrite(i, true, customaddress);
            }
        }
        if ( id == Button.ID_UP || id == Button.ID_LEFT ) {
            if ( i != 1 ) {
                rewrite(i, false, customaddress);
                i--;
                rewrite(i, true, customaddress);
            } else {
                rewrite(i, false, customaddress);
                i = 4;
                rewrite(i, true, customaddress);
            }
        }
    }
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:59,代码来源:GraphicStartup.java

示例6: toolException

import lejos.hardware.Button; //导入方法依赖的package包/类
private void toolException(Throwable t) {
    Sound.buzz();
    TextLCD lcd = BrickFinder.getDefault().getTextLCD(Font.getSmallFont());
    int offset = 0;
    // Get rid of invocation exception
    if ( t.getCause() != null ) {
        t = t.getCause();
    }
    while ( true ) {
        lcd.clear();
        lcd.drawString("Tool exception:", offset, 1);
        lcd.drawString(t.getClass().getName(), offset, 3);
        if ( t.getMessage() != null ) {
            lcd.drawString(t.getMessage(), offset, 4);
        }

        if ( t.getCause() != null ) {
            lcd.drawString("Caused by:", offset, 5);
            lcd.drawString(t.getCause().toString(), offset, 6);
        }

        StackTraceElement[] trace = t.getStackTrace();
        for ( int i = 0; i < 7 && i < trace.length; i++ ) {
            lcd.drawString(trace[i].toString(), offset, 8 + i);
        }

        lcd.refresh();
        int id = Button.waitForAnyEvent();
        if ( id == Button.ID_ESCAPE ) {
            break;
        }
        if ( id == Button.ID_LEFT ) {
            offset += 5;
        }
        if ( id == Button.ID_RIGHT ) {
            offset -= 5;
        }
        if ( offset > 0 ) {
            offset = 0;
        }
    }
    lcd.clear();
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:44,代码来源:GraphicStartup.java

示例7: initial_adjustment

import lejos.hardware.Button; //导入方法依赖的package包/类
private static void initial_adjustment()
{
    LCD.drawString("Adjusting ...", 4, 4);

    boolean flag = true;

    while (flag)
    {
        int event = Button.waitForAnyEvent();

        switch (event)
        {
            case UP_Press:
                forward(pen);
                break;

            case DOWN_Press:
                reverse(pen);
                break;

            case UP_Release:
            case DOWN_Release:
                stop(pen);
                break;

            case RIGHT_Press:
                forward(assembly);
                break;

            case LEFT_Press:
                reverse(assembly);
                break;

            case RIGHT_Release:
            case LEFT_Release:
                stop(assembly);
                break;

            case CENTER_Press:
                flag = false;
        }
    }

    // After a successful adjustment the assembly is at position ASSEMBLY_LENGTH (all the way to the right) and is prepared for limit tracking.
    mAssemblyPos = 0; //ASSEMBLY_LENGTH;
}
 
开发者ID:abid-mujtaba,项目名称:ev3-Plotter,代码行数:47,代码来源:Plotter.java


注:本文中的lejos.hardware.Button.waitForAnyEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。