Package de.nordakademie.cerca

Source Code of de.nordakademie.cerca.Cerca

package de.nordakademie.cerca;

import java.lang.reflect.InvocationTargetException;

import lejos.nxt.Battery;
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.LightSensor;
import lejos.nxt.SensorPort;
import de.nordakademie.cerca.battery.NativeBattery;
import de.nordakademie.cerca.button.NativeButton;
import de.nordakademie.cerca.lcd.NativeLCD;
import de.nordakademie.cerca.sensorport.DefaultNativeSensorPort;
import de.nordakademie.cerca.sensorport.NativeSensorPort;
/**
* @author Jonas Niessen
* @version 1.0
*
* This is just a sample class to show how Cerca works.
*/
public class Cerca {
  static {
    // load C library
    System.loadLibrary("cerca");
  }
  public static void main(String[] args) {
    // implementing customized behavior
    NativeLCD lcd = NativeLCD.getInstance();
    lcd.setBehaviour(new MyLCD());
   
    NativeBattery nb = NativeBattery.getInstance();
    nb.setBehaviour(new MyBattery());
   
    MySensorPort mySensorPort = new MySensorPort();
    mySensorPort.setISensorPort(0, new LightSensorStub());
   
    NativeSensorPort sensorPort = NativeSensorPort.getInstance();
    sensorPort.setBehaviour(mySensorPort);
   
    NativeButton nBtn = NativeButton.getInstance();
    nBtn.setBehaviour(new MyButton());
   
    // calling native LeJOS methods
//    int voltage = Battery.getVoltageMilliVolt();
//    System.out.println("Voltage: " + voltage);
   
   
    //
   
//    LCD.drawString("SensorPort 1 Value: " + SensorPort.S1.readValue(), 1, 2);
    System.out.println("S1 Value: " + SensorPort.S1.readValue());
    System.out.println("S1 RawValue: " + SensorPort.S1.readRawValue());
   
    LightSensor light =  new LightSensor(SensorPort.S1, true); //Hierdurch wird der Port1 ersetzt, MySensorPort ist dann nicht mehr richtig die Quelle?
    System.out.println("light: Value=" + light.readValue() + " NormalizedValue=" + light.readNormalizedValue());
     
//    System.out.println("light.readValue in Cerca.java:" + light.readValue());
//    LCD.drawString("SensorPort 1 Value: " + SensorPort.S1.readValue(), 1, 2);
    System.out.println("S1 Value: " + SensorPort.S1.readValue());
    System.out.println("S1 RawValue: " + SensorPort.S1.readRawValue());
   
    /*new Thread() {
      public void run() {
        try {
          Class myClass = ClassLoader.getSystemClassLoader().loadClass("de.nordakademie.cerca.LineFollower");
         
          //Class myClass = Class.forName("de.nordakademie.cerca.LineFollower", false, this.getContextClassLoader());
          myClass.getMethod("main", new Class[] {String[].class}).invoke(null, new Object[]{new String[]{}});
        } catch (ClassNotFoundException e) {

        } catch (SecurityException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (NoSuchMethodException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IllegalArgumentException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (InvocationTargetException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
//        LineFollower.main(new String[]{});
//
//        Motor.A.stop();
//        Motor.B.stop();
//        Motor.C.stop();
//        Motor.A.resetTachoCount();
//        Motor.B.resetTachoCount();
//        Motor.C.resetTachoCount();
//        MotorStub.off();
      }

    }.start(); */

   
    //

//    LCD.refresh();   
   
//    LCD.drawString("SensorPort 1 Value: " + SensorPort.S1.readValue(), 1, 2);
//    LCD.drawString("SensorPort 2 Value: " + SensorPort.S2.readValue(), 1, 2);   
//    LCD.drawString("SensorPort 3 Value: " + SensorPort.S3.readValue(), 1, 2);   
//    LCD.drawString("SensorPort 4 Value: " + SensorPort.S4.readValue(), 1, 2); 
   
//    LCD.drawString("Buttons-Stati: " + Button.readButtons(),  1, 2);
  }
}
TOP

Related Classes of de.nordakademie.cerca.Cerca

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.