Browse Source

added function to delete existing armband

Dennymany 5 years ago
parent
commit
b1f1faf827

+ 5 - 1
SketchAssistant/SketchAssistantWPF/LocalArmbandInterface.cs

@@ -7,7 +7,7 @@ using System.Runtime.InteropServices;
 
 namespace SketchAssistantWPF
 {
-    class LocalArmbandInterface
+    public static class LocalArmbandInterface
     {
 
         [DllImport (@"../Debug/StaticLibMotors.dll", EntryPoint = "?setupArmband@ArmbandInterface@@QAAHXZ",
@@ -26,6 +26,10 @@ namespace SketchAssistantWPF
      CallingConvention = CallingConvention.Cdecl)]
         public static extern void actuate(int motorNumber, double intensity, int duration);
 
+        [DllImport(@"../Debug/StaticLibMotors.dll", EntryPoint = "?deleteArmband@ArmbandInterface@@QAAXXZ",
+     CallingConvention = CallingConvention.Cdecl)]
+        public static extern void deleteArmband();
+
         //public void Vibrate()
 
     }

+ 1 - 1
SketchAssistant/SketchAssistantWPF/MainWindow.xaml

@@ -5,7 +5,7 @@
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d"
-        Title="Sketch Assistant" Height="612" Width="914" SizeChanged="Window_SizeChanged">
+        Title="Sketch Assistant" Height="612" Width="914" SizeChanged="Window_SizeChanged" Closed="Window_Closed">
     <Grid>
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="auto"/>

+ 10 - 0
SketchAssistant/SketchAssistantWPF/MainWindow.xaml.cs

@@ -97,6 +97,16 @@ namespace SketchAssistantWPF
         /*** WINDOW SPECIFIC FUNCTIONS START HERE ***/
         /********************************************/
 
+        /// <summary>
+        /// Window closed event, connected bracelet gets disconnected.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void Window_Closed(object sender, EventArgs e)
+        {
+            LocalArmbandInterface.deleteArmband();
+        }
+
         /// <summary>
         /// Resize Function connected to the form resize event, will refresh the form when it is resized
         /// </summary>

BIN
SketchAssistant/SketchAssistantWPF/StaticLibMotors.dll


+ 12 - 1
SketchAssistant/StaticLib1/ArmbandInterface.cpp

@@ -10,12 +10,14 @@ extern "C" {
 typedef void(__cdecl *InitFunctionType)(BodyActuator*, BodyActuator_Type, char*, int);
 typedef void(__cdecl *StopFunctionType)(BodyActuator*, uint8_t);
 typedef void(__cdecl *StartFunctionType)(BodyActuator*, uint8_t, float);
-typedef void(_cdecl *ActuateFunctionType)(BodyActuator*, uint8_t, double, uint64_t);
+typedef void(__cdecl *ActuateFunctionType)(BodyActuator*, uint8_t, double, uint64_t);
+typedef void(__cdecl *DeleteFunctionType)(BodyActuator*);
 
 static InitFunctionType initFunctionHandle;
 static StartFunctionType startFunctionHandle;
 static StopFunctionType stopFunctionHandle;
 static ActuateFunctionType actuateFunctionHandle;
+static DeleteFunctionType deleteFunctionHandle;
 
 static BodyActuator* armband;
 //static char *port = 
@@ -49,6 +51,11 @@ extern "C" {
 				printf("ERROR: actuate function could not be retrieved");
 				return 4;
 			}
+			deleteFunctionHandle = (DeleteFunctionType)GetProcAddress(lib, "BodyActuator_delete");
+			if (deleteFunctionHandle == NULL) {
+				printf("ERROR: delete function could not be retrieved");
+				return 5;
+			}
 			//strcpy(port, "COM5");
 			setupMotors();
 			//startVibrate(0, 1.0);
@@ -75,3 +82,7 @@ extern "C" {
 			(initFunctionHandle) (armband, BODYACTUATOR_TYPE_EAI, port, 8);
 			printf("armband initialized");
 		}
+
+ void ArmbandInterface::deleteArmband() {
+	 deleteFunctionHandle(armband);
+ }

+ 2 - 0
SketchAssistant/StaticLib1/ArmbandInterface.h

@@ -13,6 +13,7 @@ DllExport int setupArmband();
 DllExport void startVibrate(int tactor, float intensity);
 DllExport void stopVibrate(int tactor);
 DllExport void actuate(int tactor, double intensity, int duration);
+DllExport void deleteArmband();
 
 class ArmbandInterface
 {
@@ -29,5 +30,6 @@ class ArmbandInterface
 		__declspec(dllexport) void __cdecl startVibrate(int tactor, float intensity);
 		__declspec(dllexport) void __cdecl stopVibrate(int tactor);
 		__declspec(dllexport) void __cdecl actuate(int tactor, double intensity, int duration);
+		__declspec(dllexport) void __cdecl deleteArmband();
 		void setupMotors();
 };