[ create a new paste ] login | about

Link: http://codepad.org/ukYCq6r6    [ raw code | fork ]

C, pasted on Mar 6:
public List<SensorEvent> getEvents(double ns) {

		if (_list.isEmpty())
			return null;

		double lastTimeStamp = _list.get(_list.size() - 1).timestamp;
		double startTime = lastTimeStamp - ns;
		
		Log.d(TAG, "(startTime, lastTime) " + startTime + "," + lastTimeStamp);

		for (int i = _list.size() - 1; i >= 0; i--) { // TODO : optimize
			if (_list.get(i).timestamp <= startTime){
				return(_list.subList(i, _list.size()));
			}
		}
		

		return(_list);
	}


public void lock() {
		_mutex.acquireUninterruptibly();
	}

	public void unlock() {
		_mutex.release();
	}



	@Override
	public void onSensorChanged(SensorEvent event) {
		//Log.d(TAG, "event.  List.size() = " + _list.size());

		lock();
		
		int n = _list.size() -  _N_ELEMENTS;
		
		for (int i = 0 ; i <= n ; i++)
		{
			_list.remove(i);
		}
		
		_list.add(event);
		unlock();
	}




*******************



	private void updateGraph() {
		_collector.lock();

		_list = _collector.getEvents(10 * Math.pow(10, 9));

		Log.d(TAG, "updateGraph(): size = " + _list.size());

		SensorEvent last = _list.get(_list.size() - 1);

		DecimalFormat dec = new DecimalFormat();
		dec.setMaximumFractionDigits(3);
		dec.setMinimumFractionDigits(3);

		_timeText.setText(Long.toString(last.timestamp));
		text_x.setText(dec.format(last.values[0]));
		text_y.setText(dec.format(last.values[1]));
		text_z.setText(dec.format(last.values[2]));
		// text_norm.setText(dec.format()); // TODO

		_graph.setAbscissaStart(last.timestamp - 10 * (long) Math.pow(10, 9));
		_graph.setPoints(_list);
		
		_collector.unlock();
	}


Create a new paste based on this one


Comments: