package ch.ntb.inf.deep.runtime.mpc555.demo;

import ch.ntb.inf.deep.runtime.mpc555.Task;
import ch.ntb.inf.deep.runtime.mpc555.driver.Robi2;


public class Robi2LineDemo extends Task {
	
	private boolean sensors() {
		boolean isSensor = false;
		if (Robi2.getDistSensorValue(2) > 250) {
			isSensor = true;
		}
		for (short i=4;i<16;i++) {
			if (Robi2.getDistSensorValue(i) > 250) {
				isSensor = true;
			}
		}
		return isSensor;
	}

	private boolean leftFloorSensor() {
		return (Robi2.getDistSensorValue(0) > 550);
	}

	private boolean rightFloorSensor() {
		return (Robi2.getDistSensorValue(1) > 550); 
	}

	public void action() {
		// Zum testen: 
		/*
		OutT.print(Robi2.getDistSensorValue(0)); 
		OutT.print(' ');
		OutT.print(Robi2.getDistSensorValue(1));
		OutT.print(' ');
		OutT.print('-');
		OutT.print(' ');
		*/
		if (sensors()) {
			Robi2.stopDrives();
		} else if (leftFloorSensor() && rightFloorSensor()) {
			Robi2.setRightDriveSpeed(50);
			Robi2.setLeftDriveSpeed(100);
		} else if (!rightFloorSensor() && !leftFloorSensor()) {
			Robi2.setRightDriveSpeed(-50);
			Robi2.setLeftDriveSpeed(-100);
		} else if(!leftFloorSensor() && rightFloorSensor()){
			Robi2.setRightDriveSpeed(-50);
			Robi2.setLeftDriveSpeed(-100);
		}else{
			Robi2.setDrivesSpeedEqual(80);					
		}
	}
	
	static { 
		Robi2LineDemo task = new Robi2LineDemo();
		task.period = 0;
		Task.install(task);
	}
}
@@ -665,208 +665,8 @@
  %7B%0D%0A
-%09%09// Zum testen: %0D%0A%09%09/*%0D%0A%09%09OutT.print(Robi2.getDistSensorValue(0)); %0D%0A%09%09OutT.print(' ');%0D%0A%09%09OutT.print(Robi2.getDistSensorValue(1));%0D%0A%09%09OutT.print(' ');%0D%0A%09%09OutT.print('-');%0D%0A%09%09OutT.print(' ');%0D%0A%09%09*/%0D%0A
 %09%09if

remove unused comments