Skip to content
Browse files

somechanges

  • Loading branch information...
1 parent beb3c5f commit 2a274dd027c4db1f05db38edd1b2bff1ac78d3d3 @serman committed Feb 22, 2012
View
8 .gitignore
@@ -1,2 +1,10 @@
code/android/Android_GeigerCounter_basico/bin/
code/android/Android_GeigerCounter_basico/gen/
+## generic files to ignore
+*~
+*.lock
+*.DS_Store
+*.swp
+*.out
+*.class
+
View
3 code/android/Android_GeigerCounter_basico/AndroidManifest.xml
@@ -5,7 +5,8 @@
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10"/>
- <uses-feature android:name="android.hardware.usb.accessory" />
+ <uses-feature android:name="android.hardware.usb.accessory" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="@drawable/ic_launcher"
View
46 code/android/Android_GeigerCounter_basico/res/layout/main.xml
@@ -77,21 +77,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
- android:gravity="center" >
- <Button
- android:id="@+id/record_button"
- android:layout_width="0dip"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="@string/record_button"
- />
- <Button
- android:id="@+id/continue_button"
- android:layout_width="0dip"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="@string/pause_button"
- />
+ android:gravity="center" >
</LinearLayout>
<TextView
android:id="@+id/raw_display"
@@ -105,5 +91,33 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="seq"
- android:textSize="10sp" />
+ android:textSize="10sp" />
+
+ <RelativeLayout
+ android:id="@+id/relativeLayout1"
+ android:layout_width="match_parent"
+ android:layout_height="140dp"
+ android:orientation="horizontal" >
+
+ <Button
+ android:id="@+id/record_button"
+ android:layout_width="120dip"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/record_button"
+ android:layout_marginTop="2dip"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentBottom="true"/>
+
+ <Button
+ android:id="@+id/continue_button"
+ android:layout_width="120dip"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/pause_button"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentBottom="true"
+ />
+ </RelativeLayout>
+
</LinearLayout>
View
101 code/android/Android_GeigerCounter_basico/src/com/dofideas/geiger2/DataRecorder.java
@@ -0,0 +1,101 @@
+package com.dofideas.geiger2;
+
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.Date;
+import android.text.format.DateUtils;
+import android.content.Context;
+import java.text.SimpleDateFormat;
+
+import android.os.Environment;
+import android.text.format.DateFormat;
+import android.util.Log;
+
+public class DataRecorder {
+
+ private Context contextRef;
+ private DataOutputStream fos;
+ DataRecorder(Context andContext){
+ this.contextRef=andContext;
+ }
+ boolean checkForCard(){
+ //checking for media CArd
+ boolean mExternalStorageAvailable = false;
+ boolean mExternalStorageWriteable = false;
+
+ String state = Environment.getExternalStorageState();
+ if (Environment.MEDIA_MOUNTED.equals(state)) {
+ // We can read and write the media
+ mExternalStorageAvailable = mExternalStorageWriteable = true;
+ } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
+ // We can only read the media
+ mExternalStorageAvailable = true;
+ mExternalStorageWriteable = false;
+ } else {
+ // Something else is wrong. It may be one of many other states, but all we need
+ // to know is we can neither read nor write
+ mExternalStorageAvailable = mExternalStorageWriteable = false;
+ }
+ Log.d("qq","mExternalStorageWriteable: "+mExternalStorageWriteable);
+ return mExternalStorageWriteable;
+
+ }
+
+ boolean open(){
+ if(checkForCard()){
+ if(openFile()){
+ Log.d("qq","open: ");
+ return true;
+ }
+ }
+ return false;
+ }
+ boolean openFile(){
+ File folder1= contextRef.getExternalFilesDir(null);
+ try {
+ Log.d("qq","open file " + folder1.getCanonicalPath());
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ Calendar cal = Calendar.getInstance();
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm");
+ String dateStr = sdf.format(cal.getTime());
+
+ File file = new File(folder1, dateStr+".txt");
+
+ try {
+ fos = new DataOutputStream( new FileOutputStream(file) );
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ boolean closeFile(){
+ Log.d("qq","closing file");
+ try {
+ fos.close();
+ } catch (Exception e) {
+ return false;
+ }
+ return true;
+ }
+
+ boolean addData (int cpm, int seq) {
+ try {
+ fos.writeUTF(seq + " " + cpm + "\n" );
+ } catch (IOException e) {
+ Log.d("qq","error in addDAta: ");
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+}
View
54 code/android/Android_GeigerCounter_basico/src/com/dofideas/geiger2/MainActivity.java
@@ -49,6 +49,10 @@
private ParcelFileDescriptor fileDescriptor;
private FileInputStream inputStream;
+ //DataRecorder
+ private DataRecorder mRecorder;
+ private Button rec;
+ private boolean state_recording=false;
// Broadcast Receiver
private final BroadcastReceiver bcastReceiver = new BroadcastReceiver(){
@Override
@@ -68,7 +72,9 @@ public void onReceive(Context context, Intent intent) {
};
// Model
- private final GeigerModel model = new GeigerModel();
+ private final GeigerModel model = new GeigerModel();
+
+
/** Called when the activity is first created. */
@@ -94,20 +100,41 @@ public void onCreate(Bundle savedInstanceState) {
Log.d(TAG,"onCreate() : bcastReceiver registered :"+bcastReceiver);
// TODO: temp test: trigger ACTION_USB_PERMISSION from buttom
- Button rec = (Button) findViewById(R.id.record_button);
+ rec = (Button) findViewById(R.id.record_button);
rec.setOnClickListener(new OnClickListener(){
-
public void onClick(View v) {
Log.d(TAG,"onClick()");
- Intent mIntent = new Intent();
- mIntent.setAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
- sendBroadcast(mIntent);
+ // Intent mIntent = new Intent();
+ // mIntent.setAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
+ // sendBroadcast(mIntent);
+
+ state_recording=!state_recording;
+
+ if(state_recording){ //they clicked and now it is recording
+ if(mRecorder.open()==false){
+ state_recording=false;
+ }
+ else
+ rec.setText("Stop Record");
+ }
+ else{
+ rec.setText("Record");
+ mRecorder.closeFile();
+ }
+
+
+
+
}
});
// Register this in model
model.addObserver(this);
+ mRecorder = new DataRecorder(this);
+ //mRecorder.open();
+
+
}
@@ -155,6 +182,11 @@ protected void onStop() {
protected void onPause() {
Log.d(TAG,"onPause()");
super.onPause();
+ if(state_recording){
+ state_recording=false;
+ mRecorder.closeFile();
+ rec.setText("record");
+ }
}
@Override
@@ -166,6 +198,7 @@ protected void onDestroy() {
// the app from launcher without problems.
closeAccessory();
super.onDestroy();
+ mRecorder.closeFile();
}
private void openAccessory(UsbAccessory accessory){
@@ -287,11 +320,18 @@ public void update(Observable observable, Object data) {
// Call updateViews from Main thread
handler.post(new Runnable(){
public void run() {
- updateViews();
+ updateViews();
+ if(state_recording)
+ recordValues();
}});
}
+ private void recordValues(){
+ //if(model.getSeqNum())
+ mRecorder.addData(model.getCpm1min(), model.getSeqNum());
+ }
+
private void updateViews(){
Log.d(TAG,"updateViews()");
// Get values from model

0 comments on commit 2a274dd

Please sign in to comment.
Something went wrong with that request. Please try again.