@@ -1385,7 +1385,7 @@ else if(responseCommand==SAMPLING_RATE_RESPONSE) {
13851385 }
13861386 }
13871387 }
1388- else if (getHardwareVersion ()== HW_ID . SHIMMER_3 ) {
1388+ else if (isShimmerGen3or3R ()) {
13891389 byte [] bufferSR = readBytes (2 , responseCommand ); //read the sampling rate
13901390 if (bufferSR !=null ){
13911391 setSamplingRateShimmer (convertSamplingRateBytesToFreq (bufferSR [0 ], bufferSR [1 ], getSamplingClockFreq ()));
@@ -1430,11 +1430,14 @@ else if(responseCommand==FW_VERSION_RESPONSE){
14301430 }
14311431
14321432 else if (responseCommand ==ALL_CALIBRATION_RESPONSE ) {
1433- if (getHardwareVersion ()== HW_ID . SHIMMER_3 ) {
1433+ if (isShimmerGen3or3R ()) {
14341434 processAccelCalReadBytes ();
14351435 processGyroCalReadBytes ();
14361436 processMagCalReadBytes ();
14371437 processLsm303dlhcAccelCalReadBytes ();
1438+ if (getHardwareVersion () == HW_ID .SHIMMER_3R ) {
1439+ //TODO added support for Shimmer3R alt accel and alt mag if needed but this has been replaced by calib dump
1440+ }
14381441 }
14391442 else { //Shimmer2R etc.
14401443 processAccelCalReadBytes ();
@@ -2109,7 +2112,7 @@ else if(bytearray[1]==EXG_CHIP_INDEX.CHIP2.ordinal()){ //1 = CHIP 2
21092112 }
21102113 else if (currentCommand ==SET_SENSORS_COMMAND ) {
21112114 mEnabledSensors =tempEnabledSensors ;
2112- if (getHardwareVersion ()== HW_ID . SHIMMER_3 || getHardwareVersion ()== HW_ID . SHIMMER_3R ){
2115+ if (isShimmerGen3or3R () ){
21132116 checkExgResolutionFromEnabledSensorsVar ();
21142117 }
21152118 byteStack .clear (); // Always clear the packetStack after setting the sensors, this is to ensure a fresh start
@@ -2585,129 +2588,15 @@ private void initializeShimmer2R(){
25852588 }
25862589
25872590 private void initializeShimmer3R (){
2588-
2589- setHardwareVersionAndCreateSensorMaps (HW_ID .SHIMMER_3R );
2590- // initialise(HW_ID.SHIMMER_3);
2591-
2592- setHaveAttemptedToReadConfig (true );
2593-
2594- if (mSendProgressReport ){
2595- operationPrepare ();
2596- setBluetoothRadioState (BT_STATE .CONNECTING );
2597- }
2598-
2599- //readExpansionBoardID();
2600-
2601- if (isBtCrcModeSupported ()) {
2602- writeBtCommsCrcMode (DEFAULT_BT_CRC_MODE_IF_SUPPORTED );
2603- }
2604-
2605- if (isSetupDeviceWhileConnecting ()){
2606- if (mFixedShimmerConfigMode !=null && mFixedShimmerConfigMode !=FIXED_SHIMMER_CONFIG_MODE .NONE ){
2607- boolean triggerConfig = setFixedConfigWhenConnecting ();
2608- if (triggerConfig ){
2609- writeConfigBytes (false );
2610- }
2611- }
2612- else {
2613- if (this .mUseInfoMemConfigMethod && getFirmwareVersionCode ()>=6 ){
2614- writeConfigBytes (false );
2615- }
2616- else {
2617- if (isThisVerCompatibleWith (HW_ID .SHIMMER_3 , FW_ID .LOGANDSTREAM , 0 , 5 , 2 )){
2618- writeShimmerUserAssignedName (getShimmerUserAssignedName ());
2619- }
2620- if (mSetupEXG ){
2621- writeEXGConfiguration ();
2622- mSetupEXG = false ;
2623- }
2624- writeGSRRange (getGSRRange ());
2625- writeAccelRange (getAccelRange ());
2626- writeGyroRange (getGyroRange ());
2627- writeMagRange (getMagRange ());
2628- writeShimmerAndSensorsSamplingRate (getSamplingRateShimmer ());
2629- writeInternalExpPower (1 );
2630- // setContinuousSync(mContinousSync);
2631- }
2632- }
2633- }
2634-
2635- if (this .mUseInfoMemConfigMethod && getFirmwareVersionCode ()>=6 ){
2636- readConfigBytes ();
2637- readPressureCalibrationCoefficients ();
2638- }
2639- else {
2640- readSamplingRate ();
2641- readMagRange ();
2642- readAccelRange ();
2643- readGyroRange ();
2644- readAccelSamplingRate ();
2645- readCalibrationParameters ("All" );
2646- readPressureCalibrationCoefficients ();
2647- readEXGConfigurations ();
2648- //enableLowPowerMag(mLowPowerMag);
2649-
2650- readDerivedChannelBytes ();
2651-
2652- if (isThisVerCompatibleWith (HW_ID .SHIMMER_3 , FW_ID .LOGANDSTREAM , 0 , 5 , 2 )){
2653- readTrial ();
2654- readConfigTime ();
2655- readShimmerName ();
2656- readExperimentName ();
2657- }
2658- }
2659-
2660- readLEDCommand ();
2661-
2662- if (isThisVerCompatibleWith (HW_ID .SHIMMER_3 , FW_ID .LOGANDSTREAM , 0 , 5 , 2 ) ||
2663- isThisVerCompatibleWith (HW_ID .SHIMMER_3 , FW_ID .BTSTREAM , 0 , 8 , 1 )){
2664- readStatusLogAndStream ();
2665- }
2666-
2667- if (isThisVerCompatibleWith (HW_ID .SHIMMER_3 , FW_ID .LOGANDSTREAM , 0 , 5 , 9 ) ||
2668- isThisVerCompatibleWith (HW_ID .SHIMMER_3 , FW_ID .BTSTREAM , 0 , 8 , 1 )){
2669- readBattery ();
2670- }
2671-
2672- if (getShimmerVerObject ().isSupportedBtFwVerRequest ()) {
2673- readBtFwVersion ();
2674- }
2675-
2676- // Only read calibration dump over bluetooth if the Shimmer is not
2677- // docked as the Shimmer won't have access to the SD card
2678- if (!isDocked ()){
2679- readCalibrationDump ();
2680- }
2681-
2682- if (isSetupDeviceWhileConnecting ()){
2683- if (mFixedShimmerConfigMode !=null && mFixedShimmerConfigMode !=FIXED_SHIMMER_CONFIG_MODE .NONE ){
2684- writeEnabledSensors (mEnabledSensors ); //this should always be the last command
2685- } else {
2686- //writeAccelRange(mDigitalAccelRange);
2687- writeEnabledSensors (mSetEnabledSensors ); //this should always be the last command
2688- }
2689- }
2690- else {
2691- inquiry ();
2692- }
2693-
2694- if (mSendProgressReport ){
2695- // Just unlock instruction stack and leave logAndStream timer as
2696- // this is handled in the next step, i.e., no need for
2697- // operationStart() here
2698- startOperation (BT_STATE .CONNECTING , getListofInstructions ().size ());
2699-
2700- setInstructionStackLock (false );
2701- }
2702-
2703- startTimerReadStatus (); // if shimmer is using LogAndStream FW, read its status periodically
2704- startTimerReadBattStatus (); // if shimmer is using LogAndStream FW, read its status periodically
2705-
2706-
2591+ initializeShimmer3or3R (HW_ID .SHIMMER_3R );
27072592 }
27082593
27092594 private void initializeShimmer3 (){
2710- setHardwareVersionAndCreateSensorMaps (HW_ID .SHIMMER_3 );
2595+ initializeShimmer3or3R (HW_ID .SHIMMER_3 );
2596+ }
2597+
2598+ private void initializeShimmer3or3R (int hardwareVersion ){
2599+ setHardwareVersionAndCreateSensorMaps (hardwareVersion );
27112600// initialise(HW_ID.SHIMMER_3);
27122601
27132602 setHaveAttemptedToReadConfig (true );
@@ -2780,23 +2669,22 @@ private void initializeShimmer3(){
27802669
27812670 readLEDCommand ();
27822671
2783- if (isThisVerCompatibleWith (HW_ID .SHIMMER_3 , FW_ID .LOGANDSTREAM , 0 , 5 , 2 ) ||
2784- isThisVerCompatibleWith (HW_ID .SHIMMER_3 , FW_ID .BTSTREAM , 0 , 8 , 1 )){
2672+ if (getShimmerVerObject ().isSupportedBtStatusRequest ()) {
27852673 readStatusLogAndStream ();
27862674 }
2787-
2788- if (isThisVerCompatibleWith (HW_ID .SHIMMER_3 , FW_ID .LOGANDSTREAM , 0 , 5 , 9 ) ||
2789- isThisVerCompatibleWith (HW_ID .SHIMMER_3 , FW_ID .BTSTREAM , 0 , 8 , 1 )){
2675+
2676+ if (getShimmerVerObject ().isSupportedBtBatteryRequest ()) {
27902677 readBattery ();
27912678 }
27922679
27932680 if (getShimmerVerObject ().isSupportedBtFwVerRequest ()) {
27942681 readBtFwVersion ();
27952682 }
27962683
2797- // Only read calibration dump over bluetooth if the Shimmer is not
2798- // docked as the Shimmer won't have access to the SD card
2799- if (!isDocked ()){
2684+ //TODO this could actually be causing a lot of misunderstanding and a disconnect between what the user thinks is set and what is actually set.
2685+ // Only read calibration dump over bluetooth if the Shimmer3 is not
2686+ // docked as the Shimmer3 won't have access to the SD card. The Shimmer3R does.
2687+ if (hardwareVersion ==HW_ID .SHIMMER_3R || !isDocked ()){
28002688 readCalibrationDump ();
28012689 }
28022690
@@ -2823,7 +2711,6 @@ private void initializeShimmer3(){
28232711
28242712 startTimerReadStatus (); // if shimmer is using LogAndStream FW, read its status periodically
28252713 startTimerReadBattStatus (); // if shimmer is using LogAndStream FW, read its status periodically
2826-
28272714 }
28282715
28292716 @ Override
@@ -3414,7 +3301,7 @@ public void readPressureCalibrationCoefficients() {
34143301 writeInstruction (GET_BMP180_CALIBRATION_COEFFICIENTS_COMMAND );
34153302 }
34163303 }
3417- }else if (getHardwareVersion ()== HW_ID .SHIMMER_3R ) {
3304+ } else if (getHardwareVersion () == HW_ID .SHIMMER_3R ) {
34183305 writeInstruction (GET_PRESSURE_CALIBRATION_COEFFICIENTS_COMMAND );
34193306 }
34203307 }
@@ -3477,8 +3364,7 @@ public void readBtFwVersion() {
34773364 * @param rate it is a value between 0 and 255; 6 = 1152Hz, 77 = 102.56Hz, 255 = 31.25Hz
34783365 */
34793366 public void writeGyroSamplingRate (int rate ) {
3480- if (getHardwareVersion ()==HW_ID .SHIMMER_3
3481- || getHardwareVersion ()==HW_ID .SHIMMER_3R ){
3367+ if (isShimmerGen3or3R ()){
34823368 mTempIntValue =rate ;
34833369 writeInstruction (new byte []{SET_MPU9150_SAMPLING_RATE_COMMAND , (byte )rate });
34843370 }
@@ -3521,7 +3407,7 @@ public void writeEnabledSensors(long enabledSensors) {
35213407 byte firstByte =(byte )(enabledSensors & 0xFF );
35223408
35233409 //write(new byte[]{SET_SENSORS_COMMAND,(byte) lowByte, highByte});
3524- if (getHardwareVersion ()== HW_ID . SHIMMER_3 || getHardwareVersion ()== HW_ID . SHIMMER_3R ){
3410+ if (isShimmerGen3or3R () ){
35253411 byte thirdByte =(byte )((enabledSensors & 0xFF0000 )>>16 );
35263412 writeInstruction (new byte []{SET_SENSORS_COMMAND ,(byte ) firstByte ,(byte ) secondByte ,(byte ) thirdByte });
35273413 }
@@ -3628,20 +3514,17 @@ public void writeMagSamplingRate(int rate) {
36283514 * Used to retrieve the data rate of the Accelerometer on Shimmer 3
36293515 */
36303516 public void readAccelSamplingRate () {
3631- if (getHardwareVersion ()!=HW_ID .SHIMMER_3 ){
3632- }
3633- else {
3517+ if (isShimmerGen3or3R ()){
36343518 writeInstruction (GET_ACCEL_SAMPLING_RATE_COMMAND );
3635- }
3519+ }
36363520 }
36373521
36383522 /**
36393523 * writeAccelSamplingRate(range) sets the AccelSamplingRate on the Shimmer (version 3) to the value of the input range. Note that when using writesamplingrate this value will be overwritten based on the lowpowerwraccel mode setting.
36403524 * @param rate it is a value between 1 and 7; 1 = 1 Hz; 2 = 10 Hz; 3 = 25 Hz; 4 = 50 Hz; 5 = 100 Hz; 6 = 200 Hz; 7 = 400 Hz
36413525 */
36423526 public void writeAccelSamplingRate (int rate ) {
3643- if (getHardwareVersion ()==HW_ID .SHIMMER_3
3644- || getHardwareVersion ()==HW_ID .SHIMMER_3R ){
3527+ if (isShimmerGen3or3R ()){
36453528 mTempIntValue =rate ;
36463529 writeInstruction (new byte []{SET_ACCEL_SAMPLING_RATE_COMMAND , (byte )rate });
36473530 }
@@ -3993,7 +3876,7 @@ public void readGyroRange() {
39933876 * @param range is a numeric value defining the desired gyroscope range.
39943877 */
39953878 public void writeGyroRange (int range ) {
3996- if (getHardwareVersion ()== HW_ID . SHIMMER_3 || getHardwareVersion ()== HW_ID . SHIMMER_3R ){
3879+ if (isShimmerGen3or3R () ){
39973880 writeInstruction (new byte []{SET_MPU9150_GYRO_RANGE_COMMAND , (byte )range });
39983881 setGyroRange ((int )range );
39993882 }
@@ -4031,8 +3914,7 @@ public void writeShimmerAndSensorsSamplingRate(double rate) {
40313914 int samplingByteValue = (int ) (1024 /getSamplingRateShimmer ()); //the equivalent hex setting
40323915 writeInstruction (new byte []{SET_SAMPLING_RATE_COMMAND , (byte )Math .rint (samplingByteValue ), 0x00 });
40333916 }
4034- else if (getHardwareVersion ()==HW_ID .SHIMMER_3
4035- || getHardwareVersion ()==HW_ID .SHIMMER_3R ) {
3917+ else if (isShimmerGen3or3R ()) {
40363918
40373919 writeMagSamplingRate (getMagRate ());
40383920 try {
@@ -4309,7 +4191,7 @@ public void readGSRRange() {
43094191 * @param range numeric value defining the desired GSR range. Valid range settings are 0 (10kOhm to 56kOhm), 1 (56kOhm to 220kOhm), 2 (220kOhm to 680kOhm), 3 (680kOhm to 4.7MOhm) and 4 (Auto Range).
43104192 */
43114193 public void writeGSRRange (int range ) {
4312- if (getHardwareVersion ()== HW_ID . SHIMMER_3 ){
4194+ if (isShimmerGen3or3R () ){
43134195 if (getFirmwareVersionCode ()!=1 || getFirmwareVersionInternal () >4 ){
43144196 writeInstruction (new byte []{SET_GSR_RANGE_COMMAND , (byte )range });
43154197 }
@@ -4394,7 +4276,7 @@ public void writeMagCalibrationParameters(byte[] calibrationParameters) {
43944276 }
43954277
43964278 public void writeWRAccelCalibrationParameters (byte [] calibrationParameters ) {
4397- if (getHardwareVersion ()== HW_ID . SHIMMER_3 ){
4279+ if (isShimmerGen3or3R () ){
43984280 cmdcalibrationParameters [0 ] = SET_LSM303DLHC_ACCEL_CALIBRATION_COMMAND ;
43994281 System .arraycopy (calibrationParameters , 0 , cmdcalibrationParameters , 1 , 21 );
44004282 writeInstruction (cmdcalibrationParameters );
@@ -5184,7 +5066,7 @@ else if((sensorToCheck & SENSOR_BATT) >0){
51845066 }
51855067 }
51865068
5187- else if (getHardwareVersion ()== HW_ID . SHIMMER_3 ){
5069+ else if (isShimmerGen3or3R () ){
51885070
51895071 if ((sensorToCheck & SENSOR_GSR ) >0 ){
51905072 enabledSensors = disableBit (enabledSensors ,SENSOR_INT_ADC_A1 );
@@ -5262,7 +5144,7 @@ else if((sensorToCheck & SENSOR_INT_ADC_A14) >0){
52625144 //TODO: MN -> replace with sensormap conflict checks? unfinished for Shimmer2R
52635145 public boolean sensorConflictCheck (long enabledSensors ){
52645146 boolean pass =true ;
5265- if (getHardwareVersion ()!=HW_ID .SHIMMER_3 ){
5147+ if (getHardwareVersion ()!=HW_ID .SHIMMER_3 && getHardwareVersion ()!= HW_ID . SHIMMER_3R ){
52665148 if (((enabledSensors & 0xFF )& SENSOR_GYRO ) > 0 ){
52675149 if (((enabledSensors & 0xFF )& SENSOR_EMG ) > 0 ){
52685150 pass =false ;
@@ -5616,7 +5498,7 @@ private long generateSensorBitmapForHardwareControl(long enabledSensors){
56165498 }
56175499 hardwareSensorBitmap = enabledSensors ;
56185500 }
5619- else if (getHardwareVersion ()== HW_ID . SHIMMER_3 ){
5501+ else if (isShimmerGen3or3R () ){
56205502 if (((enabledSensors & 0xFF )& SENSOR_ACCEL ) > 0 ){
56215503 hardwareSensorBitmap = hardwareSensorBitmap |Configuration .Shimmer3 .SensorBitmap .SENSOR_A_ACCEL ;
56225504 }
@@ -5693,7 +5575,7 @@ public void toggleLed() {
56935575 @ Override
56945576 protected void checkBattery (){
56955577 if (mIsStreaming ){
5696- if ((getHardwareVersion ()== HW_ID . SHIMMER_3 || getHardwareVersion ()== HW_ID . SHIMMER_3R ) && getFirmwareVersionCode ()==FW_ID .LOGANDSTREAM ){
5578+ if ((isShimmerGen3or3R () ) && getFirmwareVersionCode ()==FW_ID .LOGANDSTREAM ){
56975579 if (!mWaitForAck ) {
56985580 if (mVSenseBattMA .getMean ()<mLowBattLimit *1000 *0.8 ) {
56995581 if (mCurrentLEDStatus !=2 ) {
0 commit comments