Przeglądaj źródła

Bug fixes:
- Disable temp buttons on press, show spinner, reenable after 5s if no response
- Only show silvia indicator if Machine 1/0 button on (by looking at PID messages)
- Show spinner when not connected
- Show toaster when shot timer starts, cancel runnable if user restarts shot timer.

alexDrinkwater 6 lat temu
rodzic
commit
f2dbdd28bf

+ 2 - 2
AndroidManifest.xml

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="nl.digitalthings.mebarista"
-    android:versionCode="37"
-    android:versionName="v7.beta37" >
+    android:versionCode="38"
+    android:versionName="v7.beta38" >
 
     <uses-sdk
         android:minSdkVersion="11"

+ 145 - 137
res/layout/activity_main.xml

@@ -55,29 +55,32 @@
         />
 
     <!-- Overlay over background ( the actual controls ) -->
-    <RelativeLayout 
+    <RelativeLayout
         android:id="@+id/root"
-    	android:layout_width="fill_parent"
-		android:layout_height="fill_parent"
-		android:padding="16dp"
-	    >
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:layout_alignParentStart="true"
+        android:layout_alignParentTop="true"
+        android:layout_marginStart="0dp"
+        android:layout_marginTop="0dp"
+        android:padding="16dp">
 
         <!-- Top bar -->
         <RelativeLayout
             android:id="@+id/topbar"
-    		android:layout_width="fill_parent"
-			android:layout_height="wrap_content" 
-			android:layout_alignParentTop="true" >
-                    
-	        <!--  Indicator / ON/OFF -->
-	        <ImageView
-				android:id="@+id/Indicator"
-		        android:layout_width="64dp"
-		        android:layout_height="64dp"
-		        android:layout_alignParentTop="true"
-			    android:layout_alignParentRight="true"	        
-		        android:src="@drawable/silvia_off"
-		        android:scaleType="centerInside" />
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_alignParentTop="true">
+
+            <!--  Indicator / ON/OFF -->
+            <ImageView
+                android:id="@+id/Indicator"
+                android:layout_width="64dp"
+                android:layout_height="64dp"
+                android:layout_alignParentTop="true"
+                android:layout_alignParentRight="true"
+                android:scaleType="centerInside"
+                android:src="@drawable/silvia_off" />
 
             <ProgressBar
                 android:id="@+id/progress"
@@ -87,54 +90,53 @@
                 android:layout_alignParentRight="true"
                 android:visibility="gone" >
             </ProgressBar>
-	        		
+
         </RelativeLayout>
 
-		<!--  Bottom bar -->
-		<RelativeLayout
+        <!--  Bottom bar -->
+        <RelativeLayout
             android:id="@+id/bottombar"
-    		android:layout_width="wrap_content"
-			android:layout_height="wrap_content"
-            android:layout_alignParentBottom="true"
-            android:layout_alignParentLeft="true" >
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentLeft="true"
+            android:layout_alignParentBottom="true">
 
             <RelativeLayout
                 android:id="@+id/gauges"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:layout_alignParentBottom="true"
-                android:layout_alignParentLeft="true" >
-
-            <nl.digitalthings.mebarista.Gauge
-                android:id="@+id/power"
-                android:layout_width="200dp"
-                android:layout_height="200dp"
-                android:layout_alignParentBottom="true"
                 android:layout_alignParentLeft="true"
-                android:layout_marginRight="20dp"
-                atswidget:totalNotches="50"
-                atswidget:incrementPerLargeNotch="20"
-                atswidget:incrementPerSmallNotch="4"
-                atswidget:scaleCenterValue="0"
-                atswidget:scaleColor="0x9f004d0f"
-                atswidget:scaleMinValue="0"
-                atswidget:scaleMaxValue="100"
-                atswidget:rangeOkColor="0x9f00ff00"
-                atswidget:rangeOkMinValue="0"
-                atswidget:rangeOkMaxValue="10"
-                atswidget:rangeWarningColor="0x9fff8800"
-                atswidget:rangeWarningMinValue="10"
-                atswidget:rangeWarningMaxValue="25"
-                atswidget:rangeErrorColor="0x9fff0000"
-                atswidget:rangeErrorMinValue="25"
-                atswidget:rangeErrorMaxValue="100"
-                atswidget:unitTitle="Boiler %"
-            atswidget:lowerTitle=""
-            atswidget:upperTitle=""
-            atswidget:showGauge="false"
-            atswidget:showHand="true"
-            atswidget:showRange="true"
-            />
+                android:layout_alignParentBottom="true">
+
+                <nl.digitalthings.mebarista.Gauge
+                    android:id="@+id/power"
+                    android:layout_width="200dp"
+                    android:layout_height="200dp"
+                    android:layout_alignParentLeft="true"
+                    android:layout_alignParentBottom="true"
+                    android:layout_marginRight="20dp"
+                    atswidget:incrementPerLargeNotch="20"
+                    atswidget:incrementPerSmallNotch="4"
+                    atswidget:lowerTitle=""
+                    atswidget:rangeErrorColor="0x9fff0000"
+                    atswidget:rangeErrorMaxValue="100"
+                    atswidget:rangeErrorMinValue="25"
+                    atswidget:rangeOkColor="0x9f00ff00"
+                    atswidget:rangeOkMaxValue="10"
+                    atswidget:rangeOkMinValue="0"
+                    atswidget:rangeWarningColor="0x9fff8800"
+                    atswidget:rangeWarningMaxValue="25"
+                    atswidget:rangeWarningMinValue="10"
+                    atswidget:scaleCenterValue="0"
+                    atswidget:scaleColor="0x9f004d0f"
+                    atswidget:scaleMaxValue="100"
+                    atswidget:scaleMinValue="0"
+                    atswidget:showGauge="false"
+                    atswidget:showHand="true"
+                    atswidget:showRange="true"
+                    atswidget:totalNotches="50"
+                    atswidget:unitTitle="Boiler %"
+                    atswidget:upperTitle="" />
 
                 <nl.digitalthings.mebarista.Gauge
                     android:id="@+id/shottimer"
@@ -144,102 +146,108 @@
                     android:layout_toRightOf="@id/power"
 
                     android:visibility="gone"
-                    atswidget:totalNotches="45"
+                    atswidget:angleMaxValue="270"
+                    atswidget:angleMinValue="0"
                     atswidget:incrementPerLargeNotch="5"
                     atswidget:incrementPerSmallNotch="1"
-                    atswidget:scaleCenterValue="0"
-                    atswidget:scaleColor="0x9f004d0f"
-                    atswidget:scaleMinValue="0"
-                    atswidget:scaleMaxValue="45"
-                    atswidget:angleMinValue="0"
-                    atswidget:angleMaxValue="270"
+                    atswidget:lowerTitle=""
+                    atswidget:rangeErrorColor="0x9fff0000"
+                    atswidget:rangeErrorMaxValue="45"
+                    atswidget:rangeErrorMinValue="25"
                     atswidget:rangeOkColor="0x9fff8800"
-                    atswidget:rangeOkMinValue="0"
                     atswidget:rangeOkMaxValue="20"
+                    atswidget:rangeOkMinValue="0"
                     atswidget:rangeWarningColor="0x9f00ff00"
-                    atswidget:rangeWarningMinValue="20"
                     atswidget:rangeWarningMaxValue="25"
-                    atswidget:rangeErrorColor="0x9fff0000"
-                    atswidget:rangeErrorMinValue="25"
-                    atswidget:rangeErrorMaxValue="45"
-                    atswidget:unitTitle="Shot time"
-                    atswidget:lowerTitle=""
-                    atswidget:upperTitle=""
+                    atswidget:rangeWarningMinValue="20"
+                    atswidget:scaleCenterValue="0"
+                    atswidget:scaleColor="0x9f004d0f"
+                    atswidget:scaleMaxValue="45"
+                    atswidget:scaleMinValue="0"
                     atswidget:showGauge="false"
                     atswidget:showHand="true"
                     atswidget:showRange="true"
-                    />
+                    atswidget:totalNotches="45"
+                    atswidget:unitTitle="Shot time"
+                    atswidget:upperTitle="" />
 
             </RelativeLayout>
 
             <!-- Temperature control -->
-		    <LinearLayout
-		        android:id="@+id/tempcontrol"
-		        android:orientation="vertical"
-				android:layout_width="wrap_content"
-				android:layout_height="wrap_content"
-				android:layout_alignParentBottom="true"
-				android:layout_alignParentRight="true" >
-				
-		        <TextView
-					android:id="@+id/BTemp"
-					android:layout_width="fill_parent"
-					android:layout_height="wrap_content"
-					android:text="---,-- °"
-					android:textSize="24sp"
-					android:textStyle="bold"
-					android:textColor="#FFFFFF"					 
-					android:gravity="center" 
-				    />
-		    
-		    	<RelativeLayout
-		        	android:id="@+id/tempcontrolctrls"
-					android:layout_width="wrap_content"
-					android:layout_height="wrap_content" >
-				
-			   		<Button
-						android:id="@+id/MinButton"
-						android:layout_width="52dp"
-						android:layout_height="52dp"
-						android:text="-"
-						android:textSize="28sp"
-						android:textStyle="bold"
-						android:textColor="#FFFFFF"
-						android:background="#B0993300"
-						 />
-					
-			        <TextView 
-						android:id="@+id/SetPoint"
-						android:layout_width="70dp"
-						android:layout_height="wrap_content"
-						android:text="---,-- °"
-						android:textSize="14sp"
-						android:textColor="#FFFFFF"
-						android:editable="false"
-						android:gravity="center" 
-			            android:layout_gravity="center"
-						android:layout_toRightOf="@id/MinButton"
-						android:layout_centerVertical="true"
-						android:layout_marginLeft="0dp"
-						/>
-			        
-			        <Button
-						android:id="@+id/PlusButton"
-						android:layout_width="52dp"
-						android:layout_height="52dp"
-						android:text="+"
-						android:textSize="28sp"
-						android:textStyle="bold"
-						android:textColor="#FFFFFF"
-						android:background="#B0993300"
-						android:layout_toRightOf="@id/SetPoint"
-						 />
-			        
-				</RelativeLayout>        		
+            <LinearLayout
+                android:id="@+id/tempcontrol"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_alignParentRight="true"
+                android:layout_alignParentBottom="true"
+                android:gravity="center_horizontal"
+                android:orientation="vertical">
+
+                <ProgressBar
+                    android:id="@+id/TempLoading"
+                    style="?android:attr/progressBarStyle"
+                    android:layout_width="50dp"
+                    android:layout_height="50dp"
+                    android:indeterminate="true"
+                    android:visibility="invisible"/>
+
+                <TextView
+                    android:id="@+id/BTemp"
+                    android:layout_width="fill_parent"
+                    android:layout_height="67dp"
+                    android:gravity="center"
+                    android:text="---,-- °"
+                    android:textColor="#FFFFFF"
+                    android:textSize="24sp"
+                    android:textStyle="bold" />
+
+                <RelativeLayout
+                    android:id="@+id/tempcontrolctrls"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content">
+
+
+                    <Button
+                        android:id="@+id/MinButton"
+                        android:layout_width="52dp"
+                        android:layout_height="52dp"
+                        android:background="#B0993300"
+                        android:text="-"
+                        android:textColor="#FFFFFF"
+                        android:textSize="28sp"
+                        android:textStyle="bold" />
+
+                    <TextView
+                        android:id="@+id/SetPoint"
+                        android:layout_width="70dp"
+                        android:layout_height="wrap_content"
+                        android:layout_centerVertical="true"
+                        android:layout_gravity="center"
+                        android:layout_marginLeft="0dp"
+                        android:layout_toRightOf="@id/MinButton"
+                        android:editable="false"
+                        android:gravity="center"
+                        android:text="---,-- °"
+                        android:textColor="#FFFFFF"
+                        android:textSize="14sp" />
+
+                    <Button
+                        android:id="@+id/PlusButton"
+                        android:layout_width="52dp"
+                        android:layout_height="52dp"
+                        android:layout_toRightOf="@id/SetPoint"
+                        android:background="#B0993300"
+                        android:text="+"
+                        android:textColor="#FFFFFF"
+                        android:textSize="28sp"
+                        android:textStyle="bold" />
+
+                </RelativeLayout>
 
             </LinearLayout>
 
-		</RelativeLayout>
+
+        </RelativeLayout>
 
 
 

+ 10 - 0
src/nl/digitalthings/mebarista/BaristaService.java

@@ -842,6 +842,11 @@ public class BaristaService extends IntentService implements SharedPreferences.O
                 boolean key_found = false;
             for( Map.Entry<String,?> entry : keys.entrySet( ) ) {
 
+                // Update editor settings on set confimation
+                if (parts[2].startsWith("s_")) {
+                    parts[2] = parts[2].replace("s_", "");
+                }
+
                 if( entry.getKey().equals("pref_" + parts[2]) ) {
                     String entry_type = entry.getValue().getClass().getName();
 
@@ -879,6 +884,11 @@ public class BaristaService extends IntentService implements SharedPreferences.O
             //editor.putInt("pref_" + parts[2], Integer.parseInt( parts[3].replace( ".00", "" ) ) );
 
             editor.commit();
+
+            // Send update message to main activity
+            if( !pause_updates )
+                mHandler.obtainMessage(MainActivity.UPDATE, msg.length(), -1, msg).sendToTarget();
+
             //PreferenceManager.getDefaultSharedPreferences(ma).registerOnSharedPreferenceChangeListener(this);
             //pause_prefs = false;
 

+ 65 - 29
src/nl/digitalthings/mebarista/MainActivity.java

@@ -13,7 +13,6 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
-import java.net.URI;
 import java.net.URL;
 import java.net.URLConnection;
 import java.text.DecimalFormat;
@@ -55,9 +54,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.os.StrictMode;
 import android.os.SystemClock;
-import android.preference.Preference;
 import android.preference.PreferenceManager;
-import android.support.v4.content.ContextCompat;
 import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.Menu;
@@ -68,11 +65,8 @@ import android.view.SurfaceHolder;
 import android.view.SurfaceView;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.Window;
 import android.view.WindowManager;
-import android.webkit.WebSettings;
 import android.webkit.WebView;
-import android.webkit.WebViewClient;
 import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
@@ -81,15 +75,11 @@ import android.widget.RelativeLayout;
 import android.widget.ShareActionProvider;
 import android.widget.TextView;
 import android.widget.Toast;
-import android.widget.Toolbar;
 
 import org.achartengine.ChartFactory;
 import org.achartengine.GraphicalView;
 import org.achartengine.tools.ZoomEvent;
 import org.achartengine.tools.ZoomListener;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.ParserConfigurationException;
 
 public class MainActivity extends Activity
         implements View.OnClickListener, ZoomListener, SurfaceHolder.Callback {
@@ -115,8 +105,12 @@ public class MainActivity extends Activity
     private LinearLayout tempcontrol;
     private View video;
     private ProgressBar progress_bar;
+    private ProgressBar tempLoadingBar;
     private WebView installation_manual;
     private Button minbutton, plusbutton;
+    private Runnable pidRunnable;
+    private Runnable timerHideRunnable;
+    private Runnable tempRunnable;
 
     // State
     private long last_message;
@@ -284,7 +278,7 @@ public class MainActivity extends Activity
     private Runnable updateTimerThread = new Runnable() {
         public void run() {
             float shotTime = (SystemClock.uptimeMillis() - startTime) / 1000.0f;
-            meter2.setValue(clamp(shotTime - preinfusionDelay, 0, 30));
+            meter2.setValue(clamp(shotTime - preinfusionDelay, 0, 45));
             customHandler.postDelayed(this, 500);
         }
 
@@ -299,6 +293,7 @@ public class MainActivity extends Activity
             if (System.currentTimeMillis() - last_message > 3000) {
 
                 indicator.setImageResource(R.drawable.silvia_off);
+                progress_bar.setVisibility( View.VISIBLE );
 
                 btemp.setText("---,-- °");
                 setpoint.setText("---,-- °");
@@ -393,7 +388,16 @@ public class MainActivity extends Activity
                     setTitle("meBarista: " + (String) msg.obj);
                     break;
                 case UPDATE:
-                    mChartView.repaint();
+                    // Temperature setpoint response from meCoffee
+                    if (parts[2].equals("s_tmpsp")) {
+                        float setPoint = Float.parseFloat(parts[3]) / 100.0f;
+
+                        DecimalFormat format = new DecimalFormat("#0.00");
+                        setpoint.setText(format.format(setPoint) + " °");
+                        curSetpoint = setPoint;
+
+                        enableTempButtons();
+                    }
                     break;
 
                 case DEVICE_OFF:
@@ -411,7 +415,8 @@ public class MainActivity extends Activity
                 case MESSAGE_READ:
                     last_message = System.currentTimeMillis();
 
-                    indicator.setImageResource(R.drawable.silvia_on);
+                    Log.i( TAG, "Hiding spinner" );
+                    progress_bar.setVisibility( View.GONE );
 
                     if( logging_enabled ) {
 
@@ -424,9 +429,9 @@ public class MainActivity extends Activity
                         break;
 
                     if (message.startsWith("pid ")) {
-
                         try {
-
+                            customHandler.removeCallbacks(pidRunnable);
+                            indicator.setImageResource(R.drawable.silvia_on);
                             float res = Integer.parseInt(parts[1]) + Integer.parseInt(parts[2]) + Integer.parseInt(parts[3]);
 
                             if (parts.length >= 5)
@@ -437,6 +442,12 @@ public class MainActivity extends Activity
                             meter1.setValue(Math.min(res, 100.0f));
 
                             //System.out.println( "updated graph" );
+                            pidRunnable = new Runnable() {
+                                public void run() {
+                                    indicator.setImageResource(R.drawable.silvia_off);
+                                }
+                            };
+                            customHandler.postDelayed(pidRunnable, 2 * 1000);
 
                             return;
                         } catch (Exception e) {
@@ -455,8 +466,10 @@ public class MainActivity extends Activity
                             int shottime = Integer.parseInt(parts[2]);
 
                             if (shottime == 0) {
+                                customHandler.removeCallbacks(timerHideRunnable);
                                 meter2.setValue(0f);
                                 ShotTimer_show();
+                                Toast.makeText(getApplicationContext(), "Shot started", Toast.LENGTH_SHORT).show();
                                 startTime = SystemClock.uptimeMillis();
 
                                 // Setting can be changed from multiple locations: get it here
@@ -470,15 +483,17 @@ public class MainActivity extends Activity
                                 customHandler.postDelayed(updateTimerThread, 1000);
                             } else {
                                 customHandler.removeCallbacks(updateTimerThread);
-
                                 float st_secs = shottime / time_scale - preinfusionDelay;
+                                Toast.makeText(getApplicationContext(), "Shot finished: " + st_secs + " s", Toast.LENGTH_SHORT).show();
 
-                                meter2.setValue(clamp(st_secs, 0, 30));
-                                customHandler.postDelayed(new Runnable() {
+
+                                meter2.setValue(clamp(st_secs, 0, 45));
+                                timerHideRunnable = new Runnable() {
                                     public void run() {
                                         ShotTimer_hide();
                                     }
-                                }, 30 * 1000);
+                                };
+                                customHandler.postDelayed(timerHideRunnable, 30 * 1000);
                             }
 
                         } catch (Exception e) {
@@ -553,7 +568,6 @@ public class MainActivity extends Activity
         }
     };
 
-
     public void execute2(Context context) {
         // Don't create the graph if it is disabled in the preference
         SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
@@ -779,6 +793,7 @@ public class MainActivity extends Activity
         tempcontrol = (LinearLayout) findViewById(R.id.tempcontrol);
         video = findViewById(R.id.video);
         progress_bar = (ProgressBar) findViewById( R.id.progress );
+        tempLoadingBar = (ProgressBar) findViewById( R.id.TempLoading );
 
         teller = 0;
 
@@ -919,26 +934,47 @@ public class MainActivity extends Activity
 
     @Override
     public void onClick(View v) {
-
         switch (v.getId()) {
-
             case R.id.MinButton:
-
-                mBoundService.write(("cmd set tmpsp " + (int) ((curSetpoint - 0.5) * 100) + "\n")); // TODO: remove nl
-
+                changeTemp((int) ((curSetpoint - 0.5) * 100));
                 break;
 
             case R.id.PlusButton:
-
-                mBoundService.write(("cmd set tmpsp " + (int) ((curSetpoint + 0.5) * 100) + "\n")); // TODO: remove nl
-
+                changeTemp((int) ((curSetpoint + 0.5) * 100));
                 break;
 
             default:
                 break;
-
         }
+    }
+
+    private void enableTempButtons() {
+        Log.i( TAG, "Hidding temp spinner" );
+        customHandler.removeCallbacks(tempRunnable);
+        tempLoadingBar.setVisibility( View.GONE );
+        minbutton.setClickable(true);
+        plusbutton.setClickable(true);
+    }
+
+    private void disableTempButtons() {
+        Log.i( TAG, "Showing temp spinner" );
+        tempLoadingBar.setVisibility( View.VISIBLE );
+        minbutton.setClickable(false);
+        plusbutton.setClickable(false);
+    }
+
+    private void changeTemp(int temp) {
+        disableTempButtons();
+        mBoundService.write(("cmd set tmpsp " + temp + "\n")); // TODO: remove new line
+
+        tempRunnable = new Runnable() {
+            public void run() {
+                Toast.makeText(getApplicationContext(), "Error: Unable to update temperature", Toast.LENGTH_SHORT).show();
+                enableTempButtons();
+            }
+        };
 
+        customHandler.postDelayed(tempRunnable, 5 * 1000);
     }
 
     // Installation manual