Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,12 @@ public class GuiLabelConfig{
public static final String ENABLE_ERROR_LEDS_RTC = "RTC Error LEDs";
public static final String ENABLE_ERROR_LEDS_SD = "SD Error LEDs";
public static final String LOW_POWER_AUTOSTOP = "Low-power Autostop";
/** Configuration byte 232 bits 0-2 (DEV-971), an Integer, see ButtonLogMode.BUTTON_MODE_* */
public static final String BUTTON_MODE = "Button Mode";
/** Configuration byte 232 bits 3-4 (DEV-971), an Integer, see ButtonLogMode.LOG_TRIGGERS_* */
public static final String LOG_TRIGGERS = "Log Triggers";
/** Configuration byte 232 bit 5 (DEV-971), a Boolean */
public static final String TTL_INPUT = "TTL Input";

public static final String KINEMATIC_LPM = "Kinematic Sensors Low-Power Mode";//XXX-RS-LSM-SensorClass? What about HighResolutionMode?!
public static final String CALIBRATION_ALL = AbstractSensor.GuiLabelConfigCommon.CALIBRATION_ALL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.shimmerresearch.driver.calibration.UtilCalibration;
import com.shimmerresearch.driver.calibration.CalibDetails.CALIB_READ_SOURCE;
import com.shimmerresearch.driver.shimmer2r3.BluetoothModuleVersionDetails;
import com.shimmerresearch.driver.shimmer2r3.ButtonLogMode;
import com.shimmerresearch.driver.shimmer2r3.ConfigByteLayoutShimmer3;
import com.shimmerresearch.driver.shimmerGq.ConfigByteLayoutShimmerGq802154;
import com.shimmerresearch.driverUtilities.ChannelDetails;
Expand Down Expand Up @@ -505,6 +506,11 @@ public static final class PRESSURE_SENSOR_ID {
public static final byte SET_TEST = (byte) 0xA8;

public static final byte SET_FEATURE = (byte) 0xB7;
/** Event channel status (DEV-971): [0xB9] answered by [ACK][0xBA][status x 9] */
public static final byte GET_EVENT_CHANNEL_STATUS_COMMAND = (byte) 0xB9;
public static final byte EVENT_CHANNEL_STATUS_RESPONSE = (byte) 0xBA;
/** An event channel record, [0x8A][0xBB][len][record][CRC-16], sent only to a host that opted in (DEV-971) */
public static final byte EVENT_RECORD_RESPONSE = (byte) 0xBB;

public static final int MAX_NUMBER_OF_SIGNALS = 77;//50; //used to be 11 but now 13 because of the SR30 + 8 for 3d orientation
public static final int MAX_INQUIRY_PACKET_SIZE = 47;
Expand Down Expand Up @@ -577,6 +583,13 @@ public String toString() {
private int mShowErrorLedsSd = 0;
private boolean mLowBattAutoStop = false;

/** Configuration byte 232 as read from the Shimmer or set by the host (DEV-971), see {@link ButtonLogMode} */
private int mButtonLogMode = 0;
/** Whether mButtonLogMode is the Shimmer's own: read from it, or set by the host */
private boolean mIsButtonLogModeKnown = false;
/** The Shimmer's answer to the event channel probe (SET_FEATURE): null until it has answered */
private Boolean mIsEventChannelSupported = null;

protected int mTrialId = 0;
protected int mTrialNumberOfShimmers = 0;
protected int mTrialDurationEstimatedInSecs = 0;
Expand Down Expand Up @@ -5004,6 +5017,10 @@ public void setDefaultShimmerConfiguration() {
setButtonStart(true);
setShowErrorLedsRtc(true);
setShowErrorLedsSd(true);
// Byte 232's own default, legacy. Whether it is the Shimmer's is
// left as it was: a default the Shimmer was never read for is not
// written to it over Bluetooth.
mButtonLogMode = 0;

setBluetoothBaudRate(9); //460800

Expand Down Expand Up @@ -5187,6 +5204,13 @@ public void configBytesParse(byte[] configBytes, COMMUNICATION_TYPE commType) {
if(isVerCompatibleWithAnyOf(Configuration.Shimmer3.configOptionLowPowerAutoStop.mListOfCompatibleVersionInfo)) {
setLowBattAutoStop((configBytes[configByteLayoutCast.idxSDExperimentConfig1] >> configByteLayoutCast.bitShiftLowBattStop) & configByteLayoutCast.maskLowBattStop);
}

// Kept as read, 0xFF included, so that a full configuration
// write gives the Shimmer back its own byte
if(configByteLayoutCast.idxButtonLogMode>0 && configBytes.length>configByteLayoutCast.idxButtonLogMode) {
mButtonLogMode = configBytes[configByteLayoutCast.idxButtonLogMode] & 0xFF;
mIsButtonLogModeKnown = true;
}

byte[] macIdBytes = new byte[configByteLayoutCast.lengthMacIdBytes];
System.arraycopy(configBytes, configByteLayoutCast.idxMacAddress, macIdBytes, 0 , configByteLayoutCast.lengthMacIdBytes);
Expand Down Expand Up @@ -5403,6 +5427,15 @@ public byte[] configBytesGenerate(boolean generateForWritingToShimmer, COMMUNICA

mConfigBytes[configByteLayoutCast.idxSDNumOfShimmers] = (byte) (mTrialNumberOfShimmers & 0xFF);
}

// Byte 232 (DEV-971). The image starts from zeros, so without
// this a full write turned the button mode back to legacy. The
// rules go first: they hold userButtonEnable and singleTouchStart,
// packed into bytes 217 and 218 below, as the firmware will.
if(configByteLayoutCast.idxButtonLogMode>0) {
applyButtonLogModeRules();
mConfigBytes[configByteLayoutCast.idxButtonLogMode] = (byte) getButtonLogModeToWrite();
}

if(getFirmwareIdentifier()==FW_ID.SDLOG || getFirmwareIdentifier()==FW_ID.LOGANDSTREAM || getFirmwareIdentifier()==FW_ID.STROKARE) {
mConfigBytes[configByteLayoutCast.idxSDExperimentConfig0] = (byte) ((mButtonStart & configByteLayoutCast.maskButtonStart) << configByteLayoutCast.bitShiftButtonStart);
Expand Down Expand Up @@ -6652,6 +6685,163 @@ public void setDisableBluetooth(boolean state) {
public void setButtonStart(int state) {
this.mButtonStart = state;
}

/**
* Configuration byte 232 (DEV-971) as the driver holds it: as read from the
* Shimmer, 0xFF included, or as set. {@link #getButtonLogModeCorrected()}
* is what the firmware acts on.
*/
public int getButtonLogMode() {
return mButtonLogMode;
}

/**
* Sets configuration byte 232 (DEV-971) whole. The firmware corrects a
* value it cannot act on to 0 (see {@link ButtonLogMode#correct(int)}).
* Like the field setters, it holds userButtonEnable and singleTouchStart
* as that firmware will ({@link #applyButtonLogModeRules()}).
*/
public void setButtonLogMode(int value) {
mButtonLogMode = value & 0xFF;
mIsButtonLogModeKnown = true;
applyButtonLogModeRules();
}

/**
* Sets the three fields of configuration byte 232 (DEV-971) at once.
*
* @param buttonMode one of ButtonLogMode.BUTTON_MODE_*
* @param logTriggers one of ButtonLogMode.LOG_TRIGGERS_*, read only when buttonMode is not legacy
* @param ttlInputEnabled whether the TTL input's edges are recorded
*/
public void setButtonLogMode(int buttonMode, int logTriggers, boolean ttlInputEnabled) {
setButtonLogMode(ButtonLogMode.compose(0, buttonMode, logTriggers, ttlInputEnabled));
}

/** What the user button does: one of ButtonLogMode.BUTTON_MODE_*, as the firmware will act on it */
public int getButtonMode() {
return getButtonLogModeCorrected() & ButtonLogMode.MASK_BUTTON_MODE;
}

/**
* Sets what the user button does (byte 232 bits 0-2). The other two fields
* keep the values last set, so they can be set in any order. Not
* BUTTON_MODE_LEGACY, it holds userButtonEnable at the mode's nearest
* equivalent and clears singleTouchStart where no press can start logging,
* as the firmware does.
*
* @param buttonMode one of ButtonLogMode.BUTTON_MODE_*
*/
public void setButtonMode(int buttonMode) {
setButtonLogMode(ButtonLogMode.compose(mButtonLogMode, buttonMode, ButtonLogMode.getRawLogTriggers(mButtonLogMode), ButtonLogMode.isRawTtlInputEnabled(mButtonLogMode)));
}

/**
* What else starts SD logging: one of ButtonLogMode.LOG_TRIGGERS_*, as the
* firmware will act on it. Always LOG_TRIGGERS_HOST while the button mode
* is legacy, which does not read them.
*/
public int getLogTriggers() {
return (getButtonLogModeCorrected() & ButtonLogMode.MASK_LOG_TRIGGERS) >> ButtonLogMode.BIT_SHIFT_LOG_TRIGGERS;
}

/**
* Sets what else starts SD logging (byte 232 bits 3-4). Read only when the
* button mode is not legacy, but kept for when it is set.
*
* @param logTriggers one of ButtonLogMode.LOG_TRIGGERS_*
*/
public void setLogTriggers(int logTriggers) {
setButtonLogMode(ButtonLogMode.compose(mButtonLogMode, ButtonLogMode.getRawButtonMode(mButtonLogMode), logTriggers, ButtonLogMode.isRawTtlInputEnabled(mButtonLogMode)));
}

/** Whether the TTL input's edges are recorded, as the firmware will act on it */
public boolean isTtlInputEnabled() {
return (getButtonLogModeCorrected() & ButtonLogMode.MASK_TTL_INPUT)!=0;
}

/** Sets whether the TTL input's edges are recorded (byte 232 bit 5), whatever the button mode */
public void setTtlInputEnabled(boolean ttlInputEnabled) {
setButtonLogMode(ButtonLogMode.compose(mButtonLogMode, ButtonLogMode.getRawButtonMode(mButtonLogMode), ButtonLogMode.getRawLogTriggers(mButtonLogMode), ttlInputEnabled));
}

/**
* Whether the driver has the Shimmer's own byte 232: read from it, or set
* here. When it has neither, a full configuration write over Bluetooth
* leaves the Shimmer's byte as it is.
*/
public boolean isButtonLogModeKnown() {
return mIsButtonLogModeKnown;
}

/**
* Whether the driver has the Shimmer3R's own byte 233, the microphone's
* configuration ({@link SensorSoundLevel#isAudioConfigKnown()}). True
* where there is no such byte.
*/
public boolean isAudioConfigKnown() {
AbstractSensor abstractSensor = getSensorClass(AbstractSensor.SENSORS.SOUND_LEVEL);
return !(abstractSensor instanceof SensorSoundLevel) || ((SensorSoundLevel) abstractSensor).isAudioConfigKnown();
}

/**
* Whether byte 232 can be taken at its word: the Shimmer answered the event
* channel probe, or the byte holds a value the firmware keeps. Firmware
* without the byte leaves it 0xFF, which is not one, and the dock cannot
* probe.
*/
public boolean isButtonLogModeMeaningful() {
return (mIsEventChannelSupported!=null && mIsEventChannelSupported) || ButtonLogMode.isValid(mButtonLogMode);
}

/**
* Byte 232 as this Shimmer's firmware will act on it, corrected for its
* board; 0, legacy, where the byte cannot be taken at its word
* ({@link #isButtonLogModeMeaningful()}).
*/
public int getButtonLogModeCorrected() {
if(!isButtonLogModeMeaningful()) {
return 0;
}
return ButtonLogMode.correctForBoard(mButtonLogMode, getHardwareVersion(), getExpansionBoardDetails());
}

/** The byte a full configuration write puts at 232: corrected where meaningful, otherwise as read */
protected int getButtonLogModeToWrite() {
return isButtonLogModeMeaningful() ? getButtonLogModeCorrected() : mButtonLogMode;
}

/**
* On firmware that has byte 232, does what it does when it takes a
* configuration (ShimConfig_checkAndCorrectConfig): holds userButtonEnable
* (byte 217 bit 5) at the button mode's nearest equivalent, which the legacy
* mode leaves as it is, and clears singleTouchStart (byte 218 bit 7). That
* firmware is LogAndStream from the release that brought SET_FEATURE, none
* of it built with single touch (IS_SUPPORTED_SINGLE_TOUCH is 0 in
* log-and-stream-common), so it clears the bit whatever byte 232 holds.
* Other firmware changes neither here.
*/
protected void applyButtonLogModeRules() {
if(!mShimmerVerObject.isSupportedSetFeature()) {
return;
}
setSingleTouch(false);
setButtonStart(ButtonLogMode.getNearestUserButtonEnable(getButtonLogModeCorrected(), isButtonStart()));
}

/**
* The Shimmer's answer to the event channel probe (DEV-971): true if it
* ACKed SET_FEATURE's FEATURE_EVENT_STREAM, false if it NACKed it or its
* firmware is older than SET_FEATURE, null until asked. Not version-based:
* the event channel's builds report the release before them.
*/
public Boolean isEventChannelSupported() {
return mIsEventChannelSupported;
}

protected void setEventChannelSupported(Boolean isEventChannelSupported) {
mIsEventChannelSupported = isEventChannelSupported;
}

protected void setDisableBluetooth(int state) {
this.mDisableBluetooth = state;
Expand Down Expand Up @@ -9752,6 +9942,15 @@ public Object getConfigValueUsingConfigLabel(String identifier, String configLab
case(Configuration.Shimmer3.GuiLabelConfig.EXPERIMENT_SYNC_WHEN_LOGGING):
returnValue = isSyncWhenLogging();
break;
case(Configuration.Shimmer3.GuiLabelConfig.BUTTON_MODE):
returnValue = getButtonMode();
break;
case(Configuration.Shimmer3.GuiLabelConfig.LOG_TRIGGERS):
returnValue = getLogTriggers();
break;
case(Configuration.Shimmer3.GuiLabelConfig.TTL_INPUT):
returnValue = isTtlInputEnabled();
break;

case(Configuration.Shimmer3.GuiLabelConfig.KINEMATIC_LPM):
if(isLSM303DigitalAccelLPM()&&checkLowPowerGyro()&&checkLowPowerMag()) {
Expand Down Expand Up @@ -9922,6 +10121,15 @@ public Object setConfigValueUsingConfigLabel(String identifier, String configLab
setDisableBluetooth(!(boolean)valueToSet);
setSyncWhenLogging((boolean)valueToSet);
break;
case(Configuration.Shimmer3.GuiLabelConfig.BUTTON_MODE):
setButtonMode((int)valueToSet);
break;
case(Configuration.Shimmer3.GuiLabelConfig.LOG_TRIGGERS):
setLogTriggers((int)valueToSet);
break;
case(Configuration.Shimmer3.GuiLabelConfig.TTL_INPUT):
setTtlInputEnabled((boolean)valueToSet);
break;

case(Configuration.Shimmer3.GuiLabelConfig.KINEMATIC_LPM):
setLowPowerAccelWR((boolean)valueToSet);
Expand Down
Loading
Loading