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
40 changes: 33 additions & 7 deletions ShimmerBLE/Shimmer32FeetBLEAPIConsoleAppExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Shimmer32FeetBLEAPIConsoleAppExample
{
class Program
{
static string MSG = "\nPress 'S' to connect with Bluetooth \nPress 'D' to start streaming \nPress 'C' to stop the streaming \nPress 'V' to disconnect with Bluetooth \nPress 'B' to Sync \nPress 'R' to read Op Config \nPress 'A' to enable LN Accel \nPress 'T' to Read Status";
static VerisenseBLEDeviceWindows device;
static Dictionary<string, VerisenseBLEDevice> devices = new Dictionary<string, VerisenseBLEDevice>();
static List<string> uuids = new List<string>()
Expand All @@ -32,7 +33,7 @@ static void Main(string[] args)

static void Run()
{
Console.WriteLine("Press 'S' to connect with Bluetooth \nPress 'D' to start streaming \nPress 'C' to stop the streaming \nPress 'V' to disconnect with Bluetooth \nPress 'B' to Sync \nPress 'R' to read Op Config \nPress 'A' to enable LN Accel");
Console.WriteLine(MSG);
do
{
while (!Console.KeyAvailable)
Expand All @@ -42,6 +43,9 @@ static void Run()
case ConsoleKey.S:
ConnectDevices();
break;
case ConsoleKey.T:
ReadStatus();
break;
case ConsoleKey.D:
StartStreamingDevices();
break;
Expand Down Expand Up @@ -91,7 +95,7 @@ static async void ConnectDevices()
{
Console.WriteLine("Failed to connect device! UUID: " + uuid);
}
Console.WriteLine("\nPress 'S' to connect with Bluetooth \nPress 'D' to start streaming \nPress 'C' to stop the streaming \nPress 'V' to disconnect with Bluetooth \nPress 'B' to Sync \nPress 'R' to read Op Config \nPress 'A' to enable LN Accel");
Console.WriteLine(MSG);
}
else if (devices.ContainsKey(uuid))
{
Expand All @@ -110,6 +114,28 @@ static async void ConnectDevices()
}
}

static async void ReadStatus()
{
foreach (string uuid in uuids)
{
if (devices.ContainsKey(uuid))
{
var device = devices[uuid];
var status = await device.ExecuteRequest(RequestType.ReadStatus2);

if (status != null)
{
Console.WriteLine("Battery Level: " + ((StatusPayload)status).BatteryLevel + "; Battery Percent: " + ((StatusPayload)status).BatteryPercent + "; USB Powered: " + ((StatusPayload)status).UsbPowered + "; Batt Charger Status: " + ((StatusPayload)status).BattChargerStatus.ToString());
}
else
{
Console.WriteLine("Failed to read status");
}
Console.WriteLine("");
}
}
}

static async void ReadOpConfig()
{
foreach (string uuid in uuids)
Expand All @@ -127,7 +153,7 @@ static async void ReadOpConfig()
{
Console.WriteLine("Failed to read operational config");
}
Console.WriteLine("\nPress 'S' to connect with Bluetooth \nPress 'D' to start streaming \nPress 'C' to stop the streaming \nPress 'V' to disconnect with Bluetooth \nPress 'B' to Sync \nPress 'R' to read Op Config \nPress 'A' to enable LN Accel");
Console.WriteLine(MSG);
}
}
}
Expand All @@ -153,7 +179,7 @@ static async void ConfigureDevices()
await device.WriteAndReadOperationalConfiguration(opconfigbytes);

Console.WriteLine("\n--|ACCEL|--" + "\nIsAccelEnabled: " + accelDetection + "\nAccelRate: " + accelRate + "\nAccelMode: " + accelMode + "\nAccelLowPowerMode: " + accelLPMode);
Console.WriteLine("\nPress 'S' to connect with Bluetooth \nPress 'D' to start streaming \nPress 'C' to stop the streaming \nPress 'V' to disconnect with Bluetooth \nPress 'B' to Sync \nPress 'R' to read Op Config \nPress 'A' to enable LN Accel");
Console.WriteLine(MSG);
Console.WriteLine("---------------------------------------------------------------");
}
}
Expand All @@ -178,7 +204,7 @@ static async void StartStreamingDevices()
{
var streamResult = await device.ExecuteRequest(RequestType.StartStreaming);
Console.WriteLine("Stream Status: " + streamResult);
Console.WriteLine("\nPress 'S' to connect with Bluetooth \nPress 'D' to start streaming \nPress 'C' to stop the streaming \nPress 'V' to disconnect with Bluetooth \nPress 'B' to Sync \nPress 'R' to read Op Config \nPress 'A' to enable LN Accel");
Console.WriteLine(MSG);
if (device != null)
{
device.ShimmerBLEEvent -= ShimmerDevice_BLEEvent;
Expand Down Expand Up @@ -209,7 +235,7 @@ static async void StopStreamingDevices()
{
var result = await device.ExecuteRequest(RequestType.StopStreaming);
Console.WriteLine("\nUUID: " + device.Asm_uuid + " stop streaming request \nResult: " + result + "\n");
Console.WriteLine("\nPress 'S' to connect with Bluetooth \nPress 'D' to start streaming \nPress 'C' to stop the streaming \nPress 'V' to disconnect with Bluetooth \nPress 'B' to Sync \nPress 'R' to read Op Config \nPress 'A' to enable LN Accel");
Console.WriteLine(MSG);
}

}
Expand All @@ -227,7 +253,7 @@ static async void DisconnectDevices()
}

Console.WriteLine("\nUUID: " + device.Asm_uuid + " attempt disconnect \nResult: " + result + "\nNew BLE Status: " + device.GetVerisenseBLEState());
Console.WriteLine("\nPress 'S' to connect with Bluetooth \nPress 'D' to start streaming \nPress 'C' to stop the streaming \nPress 'V' to disconnect with Bluetooth \nPress 'B' to Sync \nPress 'R' to read Op Config \nPress 'A' to enable LN Accel");
Console.WriteLine(MSG);
}

//Remove disconnected devices from the Dictionary
Expand Down
30 changes: 30 additions & 0 deletions ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#region Read Request props

protected byte[] ReadStatusRequest = new byte[] { 0x11, 0x00, 0x00 };
protected byte[] ReadStatusRequest2 = new byte[] { 0x1C, 0x00, 0x00 };
protected byte[] ReadDataRequest = new byte[] { 0x12, 0x00, 0x00 };
protected byte[] StreamDataRequest = new byte[] { 0x2A, 0x01, 0x00, 0x01 };
protected byte[] StopStreamRequest = new byte[] { 0x2A, 0x01, 0x00, 0x02 };
Expand All @@ -100,6 +101,7 @@
protected byte[] ReadEventLog = new byte[] { 0x29, 0x01, 0x00, 0x10 };
protected byte[] ResetSensor = new byte[] { 0x29, 0x01, 0x00, 0x13 };


#endregion

#region Response Props
Expand Down Expand Up @@ -432,6 +434,29 @@
RequestTCS.TrySetResult(false);
}

break;
case 0x3C:
var statusData2 = new StatusPayload();
var statusResult2 = statusData2.ProcessPayload(ResponseBuffer, SyncMode);
if (statusResult2)
{
Status = statusData2;

if (ShimmerBLEEvent != null)
{
ShimmerBLEEvent.Invoke(null, new ShimmerBLEEventData { ASMID = Asm_uuid.ToString(), CurrentEvent = VerisenseBLEEvent.RequestResponse, ObjMsg = RequestType.ReadStatus2 });
}
RequestTCS.TrySetResult(true);
}
else
{
if (ShimmerBLEEvent != null)
{
ShimmerBLEEvent.Invoke(null, new ShimmerBLEEventData { ASMID = Asm_uuid.ToString(), CurrentEvent = VerisenseBLEEvent.RequestResponseFail, ObjMsg = RequestType.ReadStatus2 });
}
RequestTCS.TrySetResult(false);
}

break;
case 0x33:
var prodData = new ProdConfigPayload();
Expand Down Expand Up @@ -704,6 +729,9 @@
case RequestType.ReadStatus:
request = ReadStatusRequest;
break;
case RequestType.ReadStatus2:
request = ReadStatusRequest2;
break;
case RequestType.ReadProductionConfig:
request = ReadProdConfigRequest;
break;
Expand Down Expand Up @@ -822,6 +850,8 @@
{
case RequestType.ReadStatus:
return Status;
case RequestType.ReadStatus2:
return Status;
case RequestType.ReadProductionConfig:
return ProdConfig;
case RequestType.ReadOperationalConfig:
Expand Down Expand Up @@ -1856,7 +1886,7 @@
stream.Close();
}
}
catch (IOException ex)

Check warning on line 1889 in ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used
{
//the file is unavailable because it is:
//still being written to
Expand All @@ -1880,7 +1910,7 @@
{
WritePayloadToBinFile();

} catch (Exception ex)

Check warning on line 1913 in ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used
{
DataTCS.TrySetResult(false);
return;
Expand Down
3 changes: 2 additions & 1 deletion ShimmerBLE/ShimmerBLEAPI/Models/BasePayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public enum RequestType
StopStreaming = 100,
EraseData = 29,
ReadEventLog = 30,
Reset = 31
Reset = 31,
ReadStatus2 = 28

}

Expand Down
Loading