public void startApp() throws MIDletStateChangeException { System.out.println("Starting sensor gathering"); BootloaderListenerService.getInstance() .start(); // monitor the USB (if connected) and recognize commands from host long ourAddr = RadioFactory.getRadioPolicyManager().getIEEEAddress(); System.out.println("Our radio address = " + IEEEAddress.toDottedHex(ourAddr)); IAnalogInput sensor = EDemoBoard.getInstance().getAnalogInputs()[EDemoBoard.A4]; DatagramConnection dgConnection = null; Datagram dg = null; try { // specify broadcast_port dgConnection = (DatagramConnection) Connector.open("radiogram://broadcast:" + BROADCAST_PORT); dg = dgConnection.newDatagram(50); System.out.println("Maxlength for Packet is : " + dgConnection.getMaximumLength()); } catch (IOException ex) { System.out.println("Could not open radiogram broadcast connection"); ex.printStackTrace(); return; } int counter = 0; while (true) { try { // 9.8mV per inch double val = sensor.getVoltage(); voltages[counter] = val; double sum = 0; for (int i = 0; i < voltages.length; i++) { sum += voltages[i]; } System.out.println("Voltage average: " + sum / voltages.length); counter++; if (counter > 9) { counter = 0; } // System.out.println("Value in volts: "+ val); // double inches = val/0.0098; // System.out.println("Value in inches: "+ inches); // Write the string into the dataGram. // dg.reset(); // dg.writeLong(ourAddr); // dg.writeDouble(val); // Send DataGram // dgConnection.send(dg); // Sleep for 200 milliseconds. Utils.sleep(50); } catch (IOException ex) { System.err.println("Caught " + ex + " while collecting/sending sensor sample."); ex.printStackTrace(); } } }
public double getVoltage() { try { return gyro.getVoltage(); } catch (IOException ex) { ex.printStackTrace(); } return 0; }
public double getRateOfChange() { try { voltage = gyro.getVoltage(); // System.out.println("Gyro V is " + voltage ); } catch (IOException ex) { ex.printStackTrace(); } return ((voltage - offset) * V_TO_MV) / scalingFactor; // System.out.println("voltage = " + voltage); // double offsetVoltage = voltage-offset; // System.out.println("offsetVoltage = " + offsetVoltage); // double voltageInMillivolts = offsetVoltage*1000.0; // System.out.println("voltageInMillivolts =" + voltageInMillivolts); // double rateOfChange = voltageInMillivolts/scalingFactor; // System.out.println("rateOfChange = " + rateOfChange); // return rateOfChange; }