use of sample.ble.sensortag.sensor.BaseSensor in project BleSensorTag by StevenRudenko.
the class BleServicesAdapter method getChildView.
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final ChildViewHolder holder;
if (convertView == null) {
holder = new ChildViewHolder();
convertView = inflater.inflate(R.layout.li_characteristic, parent, false);
holder.name = (TextView) convertView.findViewById(R.id.name);
holder.uuid = (TextView) convertView.findViewById(R.id.uuid);
holder.modes = (TextView) convertView.findViewById(R.id.modes);
holder.seek = (SeekBar) convertView.findViewById(R.id.seek);
holder.seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (serviceListener == null || def == null || !fromUser) {
return;
}
final BaseSensor<?> sensor = (BaseSensor<?>) def.getSensor(holder.service.getUuid().toString());
if (sensor == null) {
return;
}
if (sensor instanceof TiPeriodicalSensor) {
final TiPeriodicalSensor periodicalSensor = (TiPeriodicalSensor) sensor;
periodicalSensor.setPeriod(progress + periodicalSensor.getMinPeriod());
serviceListener.onServiceUpdated(holder.service);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
convertView.setTag(holder);
} else {
holder = (ChildViewHolder) convertView.getTag();
}
final BluetoothGattCharacteristic item = getChild(groupPosition, childPosition);
final String uuid = item.getUuid().toString();
final String name;
final String modes = getModeString(item.getProperties());
holder.service = item.getService();
final String serviceUUID = item.getService().getUuid().toString();
final Sensor<?> sensor = def != null ? (Sensor<?>) def.getSensor(serviceUUID) : null;
// reset visibility
holder.uuid.setVisibility(View.VISIBLE);
holder.seek.setVisibility(View.GONE);
if (sensor != null) {
name = sensor.getCharacteristicName(uuid);
if (sensor instanceof BaseSensor) {
final BaseSensor<?> tiSensor = (BaseSensor<?>) sensor;
if (tiSensor.isConfigUUID(uuid)) {
if (sensor instanceof TiPeriodicalSensor) {
final TiPeriodicalSensor periodicalSensor = (TiPeriodicalSensor) sensor;
final int max = periodicalSensor.getMaxPeriod() - periodicalSensor.getMinPeriod();
final int value = periodicalSensor.getPeriod() - periodicalSensor.getMinPeriod();
holder.seek.setMax(max);
holder.seek.setProgress(value);
holder.seek.setVisibility(View.VISIBLE);
holder.uuid.setVisibility(View.GONE);
}
}
}
} else {
name = "Unknown";
}
holder.name.setText(name);
holder.uuid.setText(uuid);
holder.modes.setText(modes);
return convertView;
}
use of sample.ble.sensortag.sensor.BaseSensor in project BleSensorTag by StevenRudenko.
the class DeviceServicesActivity method onChildClick.
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if (gattServiceAdapter == null) {
return false;
}
final BluetoothGattCharacteristic characteristic = gattServiceAdapter.getChild(groupPosition, childPosition);
final DeviceDef def = getBleManager().getDeviceDefCollection().get(getDeviceName(), getDeviceAddress());
if (def == null) {
return false;
}
final Sensor<?> sensor = (Sensor<?>) def.getSensor(characteristic.getService().getUuid().toString());
if (sensor == null) {
return true;
}
if (sensor == activeSensor) {
return true;
}
final String address = getDeviceAddress();
if (sensor instanceof BaseSensor) {
final BaseSensor<?> baseSensor = (BaseSensor<?>) sensor;
if (activeSensor != null) {
activeSensor.setEnabled(false);
getBleManager().update(address, activeSensor, activeSensor.getConfigUUID(), null);
}
activeSensor = baseSensor;
baseSensor.setEnabled(true);
getBleManager().update(address, sensor, baseSensor.getConfigUUID(), null);
getBleManager().listen(address, sensor, baseSensor.getDataUUID());
} else {
getBleManager().read(address, sensor, characteristic.getUuid().toString());
}
return true;
}
Aggregations