Moderators: roger, 99jonathan, imaqine
//-----------------------------------------------------------------------------------
import java.io.IOException;
import lejos.nxt.*;
public class Main {
public static void main(String[] args) throws IOException {
LightSensor ls = new LightSensor(SensorPort.S2);
DataLoggerNXT lightLogger = new DataLoggerNXT("lightData.txt",250,40,SensorPort.S2);
lightLogger.startDataCollection();
while (lightLogger.isCollectingData()) {
//in reality this loop would be whatever behavior the robot is doing, all the loop does here is keep the program running until it's ready to quit
}
lightLogger.writeDataToFile();
}
}
//-----------------------------------------------------------------------------------
package de.jot.teachin.client.logger;
import java.util.ArrayList;
import java.util.List;
import lejos.nxt.LCD;
/**
* Clientside Logger. Prints log-text to LCD of NXJ. Log-text
* can have any length. Following options are possible:
* out() : Prints text
* out() : Prints object by calling object.toString()
* info() : Prints text with "INFO:"-prefix
* warning() : Prints text with "WARN:"-prefix
* error() : Prints text with "ERR :"-prefix
* seperator() : Prints seperator "-------------"
*
* @author jot
*
*/
public class LineLogger {
private static LineLogger instance;
private List<String> linesList;
private int index;
private boolean needsDrawUpdate;
private boolean alwaysShowLastEntry;
private final String SEPERATOR = "----------------";
private LineLogger(){
linesList = new ArrayList<String>();
index = 0;
needsDrawUpdate = true;
alwaysShowLastEntry = false;
out("LineLogger 0.1");
out("by j.o.tepper");
seperator();
}
public static LineLogger getInstance(){
if (instance == null){
instance = new LineLogger();
}
return instance;
}
public void out(String string){
int stringIndex = 0;
int stringLength = string.length();
while(stringLength - stringIndex > 16){
linesList.add(string.substring(stringIndex, stringIndex + 16));
stringIndex += 16;
}
linesList.add(string.substring(stringIndex, string.length()));
if (alwaysShowLastEntry){
if (linesList.size() > 9){
index = linesList.size() - 9; // 8 + 1 because index starts at '0'
}
needsDrawUpdate = true;
}
}
public void out(Object object){
out(object.toString());
}
public void info(String string){
out("INFO: " + string);
}
public void error(String string){
out("ERR : " + string);
}
public void warning(String string){
out("WARN: " + string);
}
public void seperator(){
out(SEPERATOR);
}
public void next(){
if (index < linesList.size() - 8){
index++;
needsDrawUpdate = true;
}
}
public void prev(){
if (index > 0){
index--;
needsDrawUpdate = true;
}
}
public void draw(){
if (needsDrawUpdate){
LCD.clear();
for (int offset = index; offset < index + 8; offset++){
System.out.println(getLine(offset));
}
LCD.refresh();
needsDrawUpdate = false;
}
}
private String getLine(int index){
if (index >= linesList.size()){
return "";
}
return linesList.get(index);
}
}Users browsing this forum: No registered users and 2 guests