2 Commits 7dfb9a6a91 ... 9d116f937b

Author SHA1 Message Date
  Info @ meCoffee 9d116f937b V39, merged shottimer fix 5 years ago
  Info @ meCoffee 81810a15ed Fixed shottimer for preinfusion 5 years ago

+ 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="39"
+    android:versionName="v7.beta39" >
 
     <uses-sdk
         android:minSdkVersion="11"

+ 3 - 3
res/xml/preference.xml

@@ -768,13 +768,13 @@
                 android:summary="Running version: %s"
                 />
 
-            <!-- nl.digitalthings.mebarista.EditTextPreferenceWithSummary
+            <nl.digitalthings.mebarista.EditTextPreferenceWithSummary
                 android:id="@+id/pref_fw_pin"
                 android:key="pref_fw_pin"
                 android:defaultValue=""
                 android:title="Pin code required for flashing"
                 android:summary="'%s'"
-                / -->
+                />
 
             <SwitchPreference
                 android:id="@+id/pref_support_fw_enable"
@@ -810,7 +810,7 @@
             <Preference android:title="Flash firmware V10 ( newest )"
                 android:summary="When selected, meBarista will reflash your espresso machine. Read help section first."
                 android:dependency="pref_support_fw_enable"
-                android:enabled="false">
+                android:enabled="true">
 
                 <intent android:targetPackage="nl.digitalthings.mebarista"
                     android:targetClass="nl.digitalthings.mebarista.MainActivity"

+ 11 - 2
src/nl/digitalthings/mebarista/BaristaService.java

@@ -1218,22 +1218,31 @@ public class BaristaService extends IntentService implements SharedPreferences.O
 
     void do_firmware_2( String firmware_file ) {
 
+        Logx logx = new Logx( ma, ma.getBaseContext() );
+
         if( connected_os == null || connected_is == null ) {
 
             Log.i(TAG, "do_firmware_2 - aborted, no connection");
 
+            logx.logcat("No device connected.", "v");
+
             return;
         }
 
         Log.i(TAG, "do_firmware_2 - nieuwe stijl");
 
+        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(ma);
+        if ( !settings.getString( "pref_fw_pin", "" ).equals( "6502" ) ) {
+            logx.logcat("No soup for you: pincode not correct", "v");
+
+            return;
+        }
+
         if( bt2 != null )
             bt2.discover_stop( );
 
         load_firmware(firmware_file);
 
-        Logx logx = new Logx( ma, ma.getBaseContext() );
-
         // First reset enable might cause a reset
         Log.i( TAG, "First reset" );
         write_flush_sleep("\ncmd reset en\n", 5000);

+ 58 - 12
src/nl/digitalthings/mebarista/MainActivity.java

@@ -139,7 +139,7 @@ public class MainActivity extends Activity
     // Shot timer
     private long startTime = 0L;
     private Handler customHandler = new Handler();
-    int preinfusionDelay = 0;
+    float preinfusionDelay = 0, preinfusionPump = 0; // This is a float because SliderPreference returns a float
 
     // Video
     // http://stackoverflow.com/questions/1817742/how-can-i-capture-a-video-recording-on-android
@@ -283,9 +283,25 @@ 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));
-            customHandler.postDelayed(this, 500);
+
+            float st_secs = (SystemClock.uptimeMillis() - startTime) /* 1000.0f */;
+
+            if( sharedPrefs.getBoolean("pref_pinbl", false) ) {
+
+                if( st_secs >= preinfusionPump && st_secs <= preinfusionPump + preinfusionDelay )
+                    st_secs = preinfusionPump;
+
+                if( st_secs > preinfusionPump + preinfusionDelay )
+                    st_secs -= preinfusionDelay;
+
+            }
+
+            st_secs /= 1000.0f;
+
+            meter2.setValue( clamp( st_secs, 0, 45) );
+
+            customHandler.postDelayed( this, 500 );
+
         }
 
     };
@@ -451,7 +467,7 @@ public class MainActivity extends Activity
 
                     if (message.startsWith("sht ")) {
 
-                        try {
+                        /* try { */
                             int shottime = Integer.parseInt(parts[2]);
 
                             if (shottime == 0) {
@@ -461,19 +477,49 @@ public class MainActivity extends Activity
 
                                 // Setting can be changed from multiple locations: get it here
                                 preinfusionDelay = 0;
+                                preinfusionPump = 0;
                                 if (sharedPrefs.getBoolean("pref_pinbl", false)) {
-                                    preinfusionDelay = sharedPrefs.getInt("pref_piprd", 0);
+
+                                    preinfusionPump = sharedPrefs.getFloat( "pref_pistrt", 0);
+                                    preinfusionDelay = sharedPrefs.getFloat("pref_piprd", 0);
+
+                                    if( mBoundService.legacy ) {
+                                        preinfusionDelay = preinfusionDelay * 1000;
+                                        preinfusionPump = preinfusionPump * 1000;
+                                    }
+
                                 }
 
-                                System.out.println("PI Delay" + preinfusionDelay);
+                                System.out.println("PI Delay " + preinfusionDelay);
 
                                 customHandler.postDelayed(updateTimerThread, 1000);
                             } else {
                                 customHandler.removeCallbacks(updateTimerThread);
 
-                                float st_secs = shottime / time_scale - preinfusionDelay;
+                                // if shottime <= pipump : check setting if to increase
+                                // if shottime > pipump : check setting for piprd
+
+                                System.out.println( "Shot timer update " + shottime );
+
+                                // Init with normal use case : no PI
+                                float st_secs = shottime;
+
+                                // Adjust for PI
+                                if( sharedPrefs.getBoolean("pref_pinbl", false) ) {
+
+                                    if( st_secs >= preinfusionPump && st_secs <= preinfusionPump + preinfusionDelay )
+                                        st_secs = preinfusionPump;
 
-                                meter2.setValue(clamp(st_secs, 0, 30));
+                                    if( st_secs > preinfusionPump + preinfusionDelay )
+                                        st_secs -= preinfusionDelay;
+                                }
+
+                                // Convert millisecs to seconds
+                                st_secs /= 1000.0f;
+
+                                meter2.setValue( clamp(st_secs, 0, 45) );
+
+                                // Set timer to hide gauge after 30 secs
                                 customHandler.postDelayed(new Runnable() {
                                     public void run() {
                                         ShotTimer_hide();
@@ -481,9 +527,9 @@ public class MainActivity extends Activity
                                 }, 30 * 1000);
                             }
 
-                        } catch (Exception e) {
-                            Log.e(TAG, "Failed to parse SHT message");
-                        }
+                        /* } catch (Exception e) {
+                            Log.e(TAG, "Failed to parse SHT message" + e.getMessage());
+                        } */
 
                     }