{"id":394,"date":"2014-12-14T18:32:09","date_gmt":"2014-12-14T17:32:09","guid":{"rendered":"http:\/\/dev.flauschig.ch\/wordpress\/?p=394"},"modified":"2014-12-14T18:35:41","modified_gmt":"2014-12-14T17:35:41","slug":"logitech-arx-example-with-c","status":"publish","type":"post","link":"http:\/\/dev.flauschig.ch\/wordpress\/?p=394","title":{"rendered":"Logitech Arx example with C#"},"content":{"rendered":"<p>Today I started playing around with the <a href=\"http:\/\/gaming.logitech.com\/de-ch\/developers\" target=\"_blank\">Logitech Arx Control SDK<\/a>.<\/p>\n<p>You can actually use it without any hardware, just install the newse <a href=\"http:\/\/www.logitech.com\/support\/gaming-software\" target=\"_blank\">Logitech Gaming Software<\/a> and start using it.<\/p>\n<p>To finally use it in C#, an appropriate wrapper is already provided.<\/p>\n<p>All you need to add is the following class to import the calls:<\/p>\n<pre class=\"lang:c# decode:true \" >public static class LogitechArx\r\n{\r\n\tpublic const int LOGI_ARX_ORIENTATION_PORTRAIT = 0x01;\r\n\tpublic const int LOGI_ARX_ORIENTATION_LANDSCAPE = 0x10;\r\n\tpublic const int LOGI_ARX_EVENT_FOCUS_ACTIVE = 0x01;\r\n\tpublic const int LOGI_ARX_EVENT_FOCUS_INACTIVE = 0x02;\r\n\tpublic const int LOGI_ARX_EVENT_TAP_ON_TAG = 0x04;\r\n\tpublic const int LOGI_ARX_EVENT_MOBILEDEVICE_ARRIVAL = 0x08;\r\n\tpublic const int LOGI_ARX_EVENT_MOBILEDEVICE_REMOVAL = 0x10;\r\n\tpublic const int LOGI_ARX_DEVICETYPE_IPHONE = 0x01;\r\n\tpublic const int LOGI_ARX_DEVICETYPE_IPAD = 0x02;\r\n\tpublic const int LOGI_ARX_DEVICETYPE_ANDROID_SMALL = 0x03;\r\n\tpublic const int LOGI_ARX_DEVICETYPE_ANDROID_NORMAL = 0x04;\r\n\tpublic const int LOGI_ARX_DEVICETYPE_ANDROID_LARGE = 0x05;\r\n\tpublic const int LOGI_ARX_DEVICETYPE_ANDROID_XLARGE = 0x06;\r\n\tpublic const int LOGI_ARX_DEVICETYPE_ANDROID_OTHER = 0x07;\r\n\r\n\t[UnmanagedFunctionPointer(CallingConvention.Cdecl)]\r\n\tpublic delegate void logiArxCB(int eventType, int eventValue, [MarshalAs(UnmanagedType.LPWStr)]String eventArg, IntPtr context);\r\n\r\n\tpublic struct logiArxCbContext\r\n\t{\r\n\t\tpublic logiArxCB arxCallBack;\r\n\t\tpublic IntPtr arxContext;\r\n\t}\r\n\r\n\t[DllImport(\"LogitechGArxControlEnginesWrapper.dll\", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]\r\n\tpublic static extern bool LogiArxInit(String identifier, String friendlyName, ref logiArxCbContext callback);\r\n\t[DllImport(\"LogitechGArxControlEnginesWrapper.dll\", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]\r\n\tpublic static extern bool LogiArxAddFileAs(String filePath, String fileName, String mimeType = \"\");\r\n\t[DllImport(\"LogitechGArxControlEnginesWrapper.dll\", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]\r\n\tpublic static extern bool LogiArxAddContentAs(byte[] content, int size, String fileName, String mimeType = \"\");\r\n\t[DllImport(\"LogitechGArxControlEnginesWrapper.dll\", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]\r\n\tpublic static extern bool LogiArxAddUTF8StringAs(String stringContent, String fileName, String mimeType = \"\");\r\n\t[DllImport(\"LogitechGArxControlEnginesWrapper.dll\", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]\r\n\tpublic static extern bool LogiArxAddImageFromBitmap(byte[] bitmap, int width, int height, String fileName);\r\n\t[DllImport(\"LogitechGArxControlEnginesWrapper.dll\", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]\r\n\tpublic static extern bool LogiArxSetIndex(String fileName);\r\n\t[DllImport(\"LogitechGArxControlEnginesWrapper.dll\", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]\r\n\tpublic static extern bool LogiArxSetTagPropertyById(String tagId, String prop, String newValue);\r\n\t[DllImport(\"LogitechGArxControlEnginesWrapper.dll\", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]\r\n\tpublic static extern bool LogiArxSetTagsPropertyByClass(String tagsClass, String prop, String newValue);\r\n\t[DllImport(\"LogitechGArxControlEnginesWrapper.dll\", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]\r\n\tpublic static extern bool LogiArxSetTagContentById(String tagId, String newContent);\r\n\t[DllImport(\"LogitechGArxControlEnginesWrapper.dll\", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]\r\n\tpublic static extern bool LogiArxSetTagsContentByClass(String tagsClass, String newContent);\r\n\t[DllImport(\"LogitechGArxControlEnginesWrapper.dll\", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]\r\n\tpublic static extern int LogiArxGetLastError();\r\n\t[DllImport(\"LogitechGArxControlEnginesWrapper.dll\", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]\r\n\tpublic static extern void LogiArxShutdown();\r\n}<\/pre>\n<p>Now you can use it in any c# application!<\/p>\n<p>Here are some snippets which help you with it:<\/p>\n<pre class=\"lang:c# decode:true \" title=\"Attach to the Arx\" >LogitechArx.logiArxCbContext contextCallback;\r\ncontextCallback.arxCallBack = new LogitechArx.logiArxCB(SDKCallback);\r\ncontextCallback.arxContext = System.IntPtr.Zero;\r\nbool retVal = LogitechArx.LogiArxInit(\"your.company.appname\", \"AppName\", ref contextCallback);\r\nif (!retVal)\r\n{\r\n\tint retCode = LogitechArx.LogiArxGetLastError();\r\n\tConsole.WriteLine(\"Loading sdk failed: \"+ retCode);\r\n}<\/pre>\n<pre class=\"lang:c# decode:true \" title=\"Callback of the Arx\" >static void ArxCallback(int eventType, int eventValue, String eventArg, IntPtr context)\r\n{\r\n\tif (eventType == LogitechArx.LOGI_ARX_EVENT_MOBILEDEVICE_ARRIVAL)\r\n\t{\r\n\t\t\/\/ Send your files here\r\n\t}\r\n\telse if (eventType == LogitechArx.LOGI_ARX_EVENT_MOBILEDEVICE_REMOVAL)\r\n\t{\r\n\t\t\/\/ Device disconnected\r\n\t}\r\n\telse if (eventType == LogitechArx.LOGI_ARX_EVENT_TAP_ON_TAG)\r\n\t{\r\n\t\tif (eventArg == \"myBtn\")\r\n\t\t{\r\n\t\t\t\/\/ Do something on this input\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<pre class=\"lang:c# decode:true \" title=\"Adding a file to the Arx\" >LogitechArx.LogiArxAddFileAs(@\"Resources\\index.html\", \"index.html\");<\/pre>\n<pre class=\"lang:c# decode:true \" title=\"Set the index to a file (important!)\" >LogitechArx.LogiArxSetIndex(\"index.html\");<\/pre>\n<p>To also add an icon, just set the icon in your application as you do usually. It should automatically work in Arx as well (it seems to take the icon from the .exe file).<\/p>\n<p>This might help getting you started. I&#8217;ll post more on this topic later.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I started playing around with the Logitech Arx Control SDK. You can actually use it without any hardware, just install the newse Logitech Gaming Software and start using it. To finally use it in C#, an appropriate wrapper is already provided. All you need to add is the following class to import the calls: &hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4,3],"tags":[131,132,133],"class_list":{"0":"entry","1":"post","2":"publish","3":"author-roemer","4":"post-394","6":"format-standard","7":"category-csharp","8":"category-programming","9":"post_tag-arx","10":"post_tag-logitech","11":"post_tag-sdk"},"acf":[],"views":4620,"_links":{"self":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/394"}],"collection":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=394"}],"version-history":[{"count":0,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/394\/revisions"}],"wp:attachment":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=394"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}