aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/io/trygvis/android/bt/BtPromise.java4
-rw-r--r--app/src/main/java/io/trygvis/soilmoisture/DefaultSoilMoistureService.java8
-rw-r--r--app/src/main/java/io/trygvis/soilmoisture/MainActivity.java88
-rw-r--r--app/src/main/java/io/trygvis/soilmoisture/SmDevice.java10
-rw-r--r--app/src/main/java/io/trygvis/soilmoisture/SmSensor.java6
5 files changed, 91 insertions, 25 deletions
diff --git a/app/src/main/java/io/trygvis/android/bt/BtPromise.java b/app/src/main/java/io/trygvis/android/bt/BtPromise.java
index c569ec2..acbed8d 100644
--- a/app/src/main/java/io/trygvis/android/bt/BtPromise.java
+++ b/app/src/main/java/io/trygvis/android/bt/BtPromise.java
@@ -365,6 +365,10 @@ public class BtPromise {
Log.i(TAG, "next action: " + actionQ.get(currentAction).name);
}
+ // The new promise should probably be stacked on top, so that all of its
+ // finally handlers are executed after the added set concludes and then the
+ // current stack can continue.
+
actionQ.addAll(currentAction, detour.actionQ);
// failureQ.addAll(detour.failureQ);
finallyQ.addAll(detour.finallyQ);
diff --git a/app/src/main/java/io/trygvis/soilmoisture/DefaultSoilMoistureService.java b/app/src/main/java/io/trygvis/soilmoisture/DefaultSoilMoistureService.java
index 56f38f4..992bf97 100644
--- a/app/src/main/java/io/trygvis/soilmoisture/DefaultSoilMoistureService.java
+++ b/app/src/main/java/io/trygvis/soilmoisture/DefaultSoilMoistureService.java
@@ -112,7 +112,8 @@ public class DefaultSoilMoistureService extends Service implements SoilMoistureS
sendBroadcast(createNewDevice(address));
- boolean candidate = btDevice.getAddress().startsWith("FB:");
+ boolean candidate = btDevice.getAddress().startsWith("FB:") ||
+ btDevice.getAddress().startsWith("FD:");
if (!candidate) {
Log.w(TAG, "Skipping device: " + btDevice.getAddress());
@@ -259,7 +260,9 @@ public class DefaultSoilMoistureService extends Service implements SoilMoistureS
@Override
public void stopScanning() {
- btService.stopScanning();
+ if (btService != null) {
+ btService.stopScanning();
+ }
}
// -----------------------------------------------------------------------
@@ -283,6 +286,7 @@ public class DefaultSoilMoistureService extends Service implements SoilMoistureS
}
void handleNewSensorValueReady(SmSensor sensor, int value) {
+ Log.i(TAG, "new sensor value: " + sensor + "=" + value);
long timestamp = currentTimeMillis();
btService.runTx(db -> {
ContentValues values = new ContentValues();
diff --git a/app/src/main/java/io/trygvis/soilmoisture/MainActivity.java b/app/src/main/java/io/trygvis/soilmoisture/MainActivity.java
index 385a566..e9ecae2 100644
--- a/app/src/main/java/io/trygvis/soilmoisture/MainActivity.java
+++ b/app/src/main/java/io/trygvis/soilmoisture/MainActivity.java
@@ -342,6 +342,13 @@ public class MainActivity extends ListActivity {
} else {
current.addAll(sensors);
}
+
+ Log.i(TAG, "sort result:");
+ for (int i = 0; i < current.size(); i++) {
+ Object o = current.get(i);
+ Log.i(TAG, i + " = " + o);
+ }
+
dataSetObservable.notifyChanged();
}
@@ -401,27 +408,32 @@ public class MainActivity extends ListActivity {
@Override
public boolean hasStableIds() {
- return true;
+ return false;
+// return true;
}
@Override
public int getItemViewType(int position) {
- Object o = current.get(position);
-
- if (o instanceof BtDevice) {
- return 0;
- } else if (o instanceof SmDevice) {
- return 1;
- } else if (o instanceof SmSensor) {
- return 2;
- }
+// Object o = current.get(position);
+//
+// if (o instanceof BtDevice) {
+// return 0;
+// } else if (o instanceof SmDevice) {
+// return 1;
+// } else if (o instanceof SmSensor) {
+// return 2;
+// }
+//
+// throw new RuntimeException("Unknown kind: " + o.getClass());
- throw new RuntimeException("Unknown kind: " + o.getClass());
+ return IGNORE_ITEM_VIEW_TYPE;
+// throw new RuntimeException("Not supported");
}
@Override
public int getViewTypeCount() {
- return 3;
+ return 1;
+// return IGNORE_ITEM_VIEW_TYPE;
}
@Override
@@ -441,20 +453,35 @@ public class MainActivity extends ListActivity {
@Override
public long getItemId(int position) {
- return position;
+ Log.i(TAG, "getItemId, position=" + position);
+
+ Object o = current.get(position);
+ if (o instanceof BtDevice) {
+ BtDevice btDevice = (BtDevice) o;
+ return 1000 + btDevice.getId();
+ } else if (o instanceof SmDevice) {
+ SmDevice smDevice = (SmDevice) o;
+ return 2000 + smDevice.getId();
+ } else if (o instanceof SmSensor) {
+ SmSensor smSensor = (SmSensor) o;
+ return 3000 + smSensor.getId();
+ }
+
+ throw new RuntimeException("Not implemented");
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
+ Log.i(TAG, "getView, position=" + position + ", view=" + view);
Object o = current.get(position);
if (o instanceof BtDevice) {
//noinspection unchecked
return getBtDeviceView((BtDevice<SmDevice>) o, view);
} else if (o instanceof SmDevice) {
- return getSmDeviceView((SmDevice) o, view);
+ return getSmDeviceView(position, (SmDevice) o, view);
} else if (o instanceof SmSensor) {
- return getSoilSensorView((SmSensor) o, view);
+ return getSoilSensorView(position, (SmSensor) o, view);
}
throw new RuntimeException("Not implemented");
@@ -486,12 +513,17 @@ public class MainActivity extends ListActivity {
return view;
}
- private View getSmDeviceView(SmDevice smDevice, View view) {
+ private View getSmDeviceView(int position, SmDevice smDevice, View view) {
if (view == null) {
view = inflater.inflate(R.layout.fragment_device, null);
view.setTag(new DeviceItem(view));
- view.setClickable(true);
- view.setOnClickListener(v -> onSmDeviceClick(smDevice));
+ view.setOnClickListener(v -> {
+ Log.i(TAG, "onClick: SmDevice, " +
+// "position=" + position + ", " +
+ "device=" + smDevice /*+ ", " +
+ "tag=" + v.getTag()*/);
+ onSmDeviceClick(smDevice);
+ });
}
DeviceItem item = (DeviceItem) view.getTag();
@@ -511,10 +543,14 @@ public class MainActivity extends ListActivity {
address += " not useful";
}
+ address += ", connected=" + smDevice.getBtDevice().connected();
+
item.deviceAddress.setText(address);
- item.rssi.setText(getText(R.string.rssi) + ": " +
- (smDevice.getBtDevice().getRssi() != null ? valueOf(smDevice.getBtDevice().getRssi()) : getText(R.string.unknown)));
+ String rssi = getText(R.string.rssi) + ": " +
+ (smDevice.getBtDevice().getRssi() != null ? valueOf(smDevice.getBtDevice().getRssi()) : getText(R.string.unknown));
+ rssi += ", device: " + smDevice.toString();
+ item.rssi.setText(rssi);
boolean useful = smDevice.isUseful();
@@ -527,18 +563,24 @@ public class MainActivity extends ListActivity {
return view;
}
- private View getSoilSensorView(SmSensor smSensor, View view) {
+ private View getSoilSensorView(int position, SmSensor smSensor, View view) {
if (view == null) {
view = inflater.inflate(R.layout.fragment_sensor, null);
view.setTag(new SensorItem(smSensor, view));
view.setClickable(true);
- view.setOnClickListener(v -> onSensorClick(smSensor));
+ view.setOnClickListener(v -> {
+ Log.i(TAG, "onClick, SmSensor: " +
+// "position=" + position + ", " +
+ "sensor=" + smSensor /*+ ", " +
+ "tag=" + v.getTag()*/);
+ onSensorClick(smSensor);
+ });
}
SensorItem item = (SensorItem) view.getTag();
Integer value = smSensor.getLastValue();
- String text = "Connected: " + smSensor.getDevice().getBtDevice().connected();
+ String text = "Sensor " + smSensor;
text += ", value: " + (value == null ? "Unknown" : value);
item.description.setText(text);
diff --git a/app/src/main/java/io/trygvis/soilmoisture/SmDevice.java b/app/src/main/java/io/trygvis/soilmoisture/SmDevice.java
index 5d439bc..1074dd9 100644
--- a/app/src/main/java/io/trygvis/soilmoisture/SmDevice.java
+++ b/app/src/main/java/io/trygvis/soilmoisture/SmDevice.java
@@ -79,6 +79,16 @@ class SmDevice {
sensors.add(sensor);
}
+ public long getId() {
+ return id;
+ }
+
+ public String toString() {
+ return "SmDevice[id=" + id + ", " +
+ "address=" + btDevice.getAddress() + ", " +
+ "#sensors=" + sensors.size() + "]";
+ }
+
// -----------------------------------------------------------------------
// Message parsing and handling.
// -----------------------------------------------------------------------
diff --git a/app/src/main/java/io/trygvis/soilmoisture/SmSensor.java b/app/src/main/java/io/trygvis/soilmoisture/SmSensor.java
index 2a0d9cd..0f49027 100644
--- a/app/src/main/java/io/trygvis/soilmoisture/SmSensor.java
+++ b/app/src/main/java/io/trygvis/soilmoisture/SmSensor.java
@@ -50,6 +50,12 @@ class SmSensor {
//
// -----------------------------------------------------------------------
+ public String toString() {
+ return "SmSensor[id=" + id + ", " +
+ "device=" + device.getBtDevice().getAddress() + ", " +
+ "index=" + getIndex() + "]";
+ }
+
public void readCurrentValue() {
device.smService.readCurrentValue(this);
}