{"action":"created","comment":{"url":"https://api.github.com/repos/solettaproject/soletta/pulls/comments/36223176","id":36223176,"diff_hunk":"@@ -0,0 +1,154 @@\n+/*\n+ * This file is part of the Soletta Project\n+ *\n+ * Copyright (C) 2015 Intel Corporation. All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ *\n+ *   * Redistributions of source code must retain the above copyright\n+ *     notice, this list of conditions and the following disclaimer.\n+ *   * Redistributions in binary form must reproduce the above copyright\n+ *     notice, this list of conditions and the following disclaimer in\n+ *     the documentation and/or other materials provided with the\n+ *     distribution.\n+ *   * Neither the name of Intel Corporation nor the names of its\n+ *     contributors may be used to endorse or promote products derived\n+ *     from this software without specific prior written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <limits.h>\n+#include <stdbool.h>\n+#include <stdint.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <string.h>\n+#include <sys/stat.h>\n+\n+#define SOL_LOG_DOMAIN &_log_domain\n+#include \"sol-log-internal.h\"\n+SOL_LOG_INTERNAL_DECLARE_STATIC(_log_domain, \"aio\");\n+\n+#include \"sol-aio.h\"\n+\n+#define AIO_BASE_PATH \"/sys/bus/iio/devices\"\n+\n+#define AIO_PATH(dst, device, pin) \\\n+    snprintf(dst, sizeof(dst), AIO_BASE_PATH \"/iio:device%d/in_voltage%d_raw\", device, pin)\n+\n+#define AIO_DEV_PATH(dst, device) \\\n+    snprintf(dst, sizeof(dst), AIO_BASE_PATH \"/iio:device%d\", device)\n+\n+struct sol_aio {\n+    FILE *fp;\n+    int device;\n+    int pin;\n+    unsigned int mask;\n+};\n+\n+static bool\n+_aio_open_fd(struct sol_aio *aio)\n+{\n+    int len;\n+    char path[PATH_MAX];\n+\n+    len = AIO_PATH(path, aio->device, aio->pin);\n+    if (len < 0 || len > PATH_MAX)\n+        return false;\n+\n+    aio->fp = fopen(path, \"re\");\n+    if (!aio->fp)\n+        return false;\n+    setvbuf(aio->fp, NULL, _IONBF, 0);\n+\n+    return true;\n+}\n+\n+struct sol_aio *\n+sol_aio_open_raw(const int device, const int pin, const unsigned int precision)\n+{\n+    int len;\n+    char path[PATH_MAX];\n+    struct stat st;\n+    struct sol_aio *aio;\n+\n+    SOL_LOG_INTERNAL_INIT_ONCE;\n+\n+    if (!precision) {\n+        SOL_WRN(\"aio #%d,%d: Invalid precision value=%d. Precision needs to be different of zero.\",\n+            device, pin, precision);\n+        return NULL;\n+    }\n+\n+    len = AIO_DEV_PATH(path, device);\n+    if (len < 0 || len > PATH_MAX || stat(path, &st)) {\n+        SOL_WRN(\"aio #%d,%d: aio device %d does not exist\", device, pin, device);\n+        return NULL;\n+    }\n+\n+    len = AIO_PATH(path, device, pin);\n+    if (len < 0 || len > PATH_MAX || stat(path, &st)) {","path":"src/lib/io/sol-aio-linux.c","position":103,"original_position":103,"commit_id":"1884fef58a4de79635b80f86cfb741938002a190","original_commit_id":"1884fef58a4de79635b80f86cfb741938002a190","user":{"login":"mbelluzzo","id":1584229,"avatar_url":"https://avatars.githubusercontent.com/u/1584229?v=3","gravatar_id":"","url":"https://api.github.com/users/mbelluzzo","html_url":"https://github.com/mbelluzzo","followers_url":"https://api.github.com/users/mbelluzzo/followers","following_url":"https://api.github.com/users/mbelluzzo/following{/other_user}","gists_url":"https://api.github.com/users/mbelluzzo/gists{/gist_id}","starred_url":"https://api.github.com/users/mbelluzzo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbelluzzo/subscriptions","organizations_url":"https://api.github.com/users/mbelluzzo/orgs","repos_url":"https://api.github.com/users/mbelluzzo/repos","events_url":"https://api.github.com/users/mbelluzzo/events{/privacy}","received_events_url":"https://api.github.com/users/mbelluzzo/received_events","type":"User","site_admin":false},"body":"It may be a good Idea to change this for the export part of gpio as well. Today we first use stat to see if its exported and open after that. We should try to open, try to export if fails and try open again. Is that right?","created_at":"2015-08-04T18:22:10Z","updated_at":"2015-08-04T18:22:10Z","html_url":"https://github.com/solettaproject/soletta/pull/422#discussion_r36223176","pull_request_url":"https://api.github.com/repos/solettaproject/soletta/pulls/422","_links":{"self":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/comments/36223176"},"html":{"href":"https://github.com/solettaproject/soletta/pull/422#discussion_r36223176"},"pull_request":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/422"}}},"pull_request":{"url":"https://api.github.com/repos/solettaproject/soletta/pulls/422","id":41502049,"html_url":"https://github.com/solettaproject/soletta/pull/422","diff_url":"https://github.com/solettaproject/soletta/pull/422.diff","patch_url":"https://github.com/solettaproject/soletta/pull/422.patch","issue_url":"https://api.github.com/repos/solettaproject/soletta/issues/422","number":422,"state":"open","locked":false,"title":"sol-aio: Add C API to handle Analog I/O (V3)","user":{"login":"mbelluzzo","id":1584229,"avatar_url":"https://avatars.githubusercontent.com/u/1584229?v=3","gravatar_id":"","url":"https://api.github.com/users/mbelluzzo","html_url":"https://github.com/mbelluzzo","followers_url":"https://api.github.com/users/mbelluzzo/followers","following_url":"https://api.github.com/users/mbelluzzo/following{/other_user}","gists_url":"https://api.github.com/users/mbelluzzo/gists{/gist_id}","starred_url":"https://api.github.com/users/mbelluzzo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbelluzzo/subscriptions","organizations_url":"https://api.github.com/users/mbelluzzo/orgs","repos_url":"https://api.github.com/users/mbelluzzo/repos","events_url":"https://api.github.com/users/mbelluzzo/events{/privacy}","received_events_url":"https://api.github.com/users/mbelluzzo/received_events","type":"User","site_admin":false},"body":"Tested on RIOT using dummy native API and Galileo.\r\n\r\nApplied suggested changes from V2 and V1","created_at":"2015-08-03T19:43:06Z","updated_at":"2015-08-04T18:22:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"381880987d2e29482f03bf5924c9238b2b53a405","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/solettaproject/soletta/pulls/422/commits","review_comments_url":"https://api.github.com/repos/solettaproject/soletta/pulls/422/comments","review_comment_url":"https://api.github.com/repos/solettaproject/soletta/pulls/comments{/number}","comments_url":"https://api.github.com/repos/solettaproject/soletta/issues/422/comments","statuses_url":"https://api.github.com/repos/solettaproject/soletta/statuses/1884fef58a4de79635b80f86cfb741938002a190","head":{"label":"mbelluzzo:pin-mux-aio-v2","ref":"pin-mux-aio-v2","sha":"1884fef58a4de79635b80f86cfb741938002a190","user":{"login":"mbelluzzo","id":1584229,"avatar_url":"https://avatars.githubusercontent.com/u/1584229?v=3","gravatar_id":"","url":"https://api.github.com/users/mbelluzzo","html_url":"https://github.com/mbelluzzo","followers_url":"https://api.github.com/users/mbelluzzo/followers","following_url":"https://api.github.com/users/mbelluzzo/following{/other_user}","gists_url":"https://api.github.com/users/mbelluzzo/gists{/gist_id}","starred_url":"https://api.github.com/users/mbelluzzo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbelluzzo/subscriptions","organizations_url":"https://api.github.com/users/mbelluzzo/orgs","repos_url":"https://api.github.com/users/mbelluzzo/repos","events_url":"https://api.github.com/users/mbelluzzo/events{/privacy}","received_events_url":"https://api.github.com/users/mbelluzzo/received_events","type":"User","site_admin":false},"repo":{"id":37611036,"name":"soletta","full_name":"mbelluzzo/soletta","owner":{"login":"mbelluzzo","id":1584229,"avatar_url":"https://avatars.githubusercontent.com/u/1584229?v=3","gravatar_id":"","url":"https://api.github.com/users/mbelluzzo","html_url":"https://github.com/mbelluzzo","followers_url":"https://api.github.com/users/mbelluzzo/followers","following_url":"https://api.github.com/users/mbelluzzo/following{/other_user}","gists_url":"https://api.github.com/users/mbelluzzo/gists{/gist_id}","starred_url":"https://api.github.com/users/mbelluzzo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbelluzzo/subscriptions","organizations_url":"https://api.github.com/users/mbelluzzo/orgs","repos_url":"https://api.github.com/users/mbelluzzo/repos","events_url":"https://api.github.com/users/mbelluzzo/events{/privacy}","received_events_url":"https://api.github.com/users/mbelluzzo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mbelluzzo/soletta","description":"Soletta Project is a framework for making IoT devices.  With Soletta Project's libraries developers can easily write software for devices that control actuators/sensors and communicate using standard technologies. It enables adding smartness even on the smallest edge devices.  Portable and scalable, it abstracts details of hardware and OS, enabling developers to reuse their code and knowledge on different targets.","fork":true,"url":"https://api.github.com/repos/mbelluzzo/soletta","forks_url":"https://api.github.com/repos/mbelluzzo/soletta/forks","keys_url":"https://api.github.com/repos/mbelluzzo/soletta/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mbelluzzo/soletta/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mbelluzzo/soletta/teams","hooks_url":"https://api.github.com/repos/mbelluzzo/soletta/hooks","issue_events_url":"https://api.github.com/repos/mbelluzzo/soletta/issues/events{/number}","events_url":"https://api.github.com/repos/mbelluzzo/soletta/events","assignees_url":"https://api.github.com/repos/mbelluzzo/soletta/assignees{/user}","branches_url":"https://api.github.com/repos/mbelluzzo/soletta/branches{/branch}","tags_url":"https://api.github.com/repos/mbelluzzo/soletta/tags","blobs_url":"https://api.github.com/repos/mbelluzzo/soletta/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mbelluzzo/soletta/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mbelluzzo/soletta/git/refs{/sha}","trees_url":"https://api.github.com/repos/mbelluzzo/soletta/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mbelluzzo/soletta/statuses/{sha}","languages_url":"https://api.github.com/repos/mbelluzzo/soletta/languages","stargazers_url":"https://api.github.com/repos/mbelluzzo/soletta/stargazers","contributors_url":"https://api.github.com/repos/mbelluzzo/soletta/contributors","subscribers_url":"https://api.github.com/repos/mbelluzzo/soletta/subscribers","subscription_url":"https://api.github.com/repos/mbelluzzo/soletta/subscription","commits_url":"https://api.github.com/repos/mbelluzzo/soletta/commits{/sha}","git_commits_url":"https://api.github.com/repos/mbelluzzo/soletta/git/commits{/sha}","comments_url":"https://api.github.com/repos/mbelluzzo/soletta/comments{/number}","issue_comment_url":"https://api.github.com/repos/mbelluzzo/soletta/issues/comments{/number}","contents_url":"https://api.github.com/repos/mbelluzzo/soletta/contents/{+path}","compare_url":"https://api.github.com/repos/mbelluzzo/soletta/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mbelluzzo/soletta/merges","archive_url":"https://api.github.com/repos/mbelluzzo/soletta/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mbelluzzo/soletta/downloads","issues_url":"https://api.github.com/repos/mbelluzzo/soletta/issues{/number}","pulls_url":"https://api.github.com/repos/mbelluzzo/soletta/pulls{/number}","milestones_url":"https://api.github.com/repos/mbelluzzo/soletta/milestones{/number}","notifications_url":"https://api.github.com/repos/mbelluzzo/soletta/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mbelluzzo/soletta/labels{/name}","releases_url":"https://api.github.com/repos/mbelluzzo/soletta/releases{/id}","created_at":"2015-06-17T17:48:32Z","updated_at":"2015-06-17T17:48:33Z","pushed_at":"2015-08-03T19:40:01Z","git_url":"git://github.com/mbelluzzo/soletta.git","ssh_url":"git@github.com:mbelluzzo/soletta.git","clone_url":"https://github.com/mbelluzzo/soletta.git","svn_url":"https://github.com/mbelluzzo/soletta","homepage":"","size":2435,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"solettaproject:master","ref":"master","sha":"1778ffffd8ae251b57212517dddb78f6f69e6e45","user":{"login":"solettaproject","id":12736897,"avatar_url":"https://avatars.githubusercontent.com/u/12736897?v=3","gravatar_id":"","url":"https://api.github.com/users/solettaproject","html_url":"https://github.com/solettaproject","followers_url":"https://api.github.com/users/solettaproject/followers","following_url":"https://api.github.com/users/solettaproject/following{/other_user}","gists_url":"https://api.github.com/users/solettaproject/gists{/gist_id}","starred_url":"https://api.github.com/users/solettaproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solettaproject/subscriptions","organizations_url":"https://api.github.com/users/solettaproject/orgs","repos_url":"https://api.github.com/users/solettaproject/repos","events_url":"https://api.github.com/users/solettaproject/events{/privacy}","received_events_url":"https://api.github.com/users/solettaproject/received_events","type":"Organization","site_admin":false},"repo":{"id":37087063,"name":"soletta","full_name":"solettaproject/soletta","owner":{"login":"solettaproject","id":12736897,"avatar_url":"https://avatars.githubusercontent.com/u/12736897?v=3","gravatar_id":"","url":"https://api.github.com/users/solettaproject","html_url":"https://github.com/solettaproject","followers_url":"https://api.github.com/users/solettaproject/followers","following_url":"https://api.github.com/users/solettaproject/following{/other_user}","gists_url":"https://api.github.com/users/solettaproject/gists{/gist_id}","starred_url":"https://api.github.com/users/solettaproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solettaproject/subscriptions","organizations_url":"https://api.github.com/users/solettaproject/orgs","repos_url":"https://api.github.com/users/solettaproject/repos","events_url":"https://api.github.com/users/solettaproject/events{/privacy}","received_events_url":"https://api.github.com/users/solettaproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/solettaproject/soletta","description":"Soletta Project is a framework for making IoT devices.  With Soletta Project's libraries developers can easily write software for devices that control actuators/sensors and communicate using standard technologies. It enables adding smartness even on the smallest edge devices.  ","fork":false,"url":"https://api.github.com/repos/solettaproject/soletta","forks_url":"https://api.github.com/repos/solettaproject/soletta/forks","keys_url":"https://api.github.com/repos/solettaproject/soletta/keys{/key_id}","collaborators_url":"https://api.github.com/repos/solettaproject/soletta/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/solettaproject/soletta/teams","hooks_url":"https://api.github.com/repos/solettaproject/soletta/hooks","issue_events_url":"https://api.github.com/repos/solettaproject/soletta/issues/events{/number}","events_url":"https://api.github.com/repos/solettaproject/soletta/events","assignees_url":"https://api.github.com/repos/solettaproject/soletta/assignees{/user}","branches_url":"https://api.github.com/repos/solettaproject/soletta/branches{/branch}","tags_url":"https://api.github.com/repos/solettaproject/soletta/tags","blobs_url":"https://api.github.com/repos/solettaproject/soletta/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/solettaproject/soletta/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/solettaproject/soletta/git/refs{/sha}","trees_url":"https://api.github.com/repos/solettaproject/soletta/git/trees{/sha}","statuses_url":"https://api.github.com/repos/solettaproject/soletta/statuses/{sha}","languages_url":"https://api.github.com/repos/solettaproject/soletta/languages","stargazers_url":"https://api.github.com/repos/solettaproject/soletta/stargazers","contributors_url":"https://api.github.com/repos/solettaproject/soletta/contributors","subscribers_url":"https://api.github.com/repos/solettaproject/soletta/subscribers","subscription_url":"https://api.github.com/repos/solettaproject/soletta/subscription","commits_url":"https://api.github.com/repos/solettaproject/soletta/commits{/sha}","git_commits_url":"https://api.github.com/repos/solettaproject/soletta/git/commits{/sha}","comments_url":"https://api.github.com/repos/solettaproject/soletta/comments{/number}","issue_comment_url":"https://api.github.com/repos/solettaproject/soletta/issues/comments{/number}","contents_url":"https://api.github.com/repos/solettaproject/soletta/contents/{+path}","compare_url":"https://api.github.com/repos/solettaproject/soletta/compare/{base}...{head}","merges_url":"https://api.github.com/repos/solettaproject/soletta/merges","archive_url":"https://api.github.com/repos/solettaproject/soletta/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/solettaproject/soletta/downloads","issues_url":"https://api.github.com/repos/solettaproject/soletta/issues{/number}","pulls_url":"https://api.github.com/repos/solettaproject/soletta/pulls{/number}","milestones_url":"https://api.github.com/repos/solettaproject/soletta/milestones{/number}","notifications_url":"https://api.github.com/repos/solettaproject/soletta/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/solettaproject/soletta/labels{/name}","releases_url":"https://api.github.com/repos/solettaproject/soletta/releases{/id}","created_at":"2015-06-08T19:13:18Z","updated_at":"2015-07-12T18:54:34Z","pushed_at":"2015-08-04T18:11:13Z","git_url":"git://github.com/solettaproject/soletta.git","ssh_url":"git@github.com:solettaproject/soletta.git","clone_url":"https://github.com/solettaproject/soletta.git","svn_url":"https://github.com/solettaproject/soletta","homepage":"","size":6231,"stargazers_count":39,"watchers_count":39,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":27,"forks":31,"open_issues":27,"watchers":39,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/422"},"html":{"href":"https://github.com/solettaproject/soletta/pull/422"},"issue":{"href":"https://api.github.com/repos/solettaproject/soletta/issues/422"},"comments":{"href":"https://api.github.com/repos/solettaproject/soletta/issues/422/comments"},"review_comments":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/422/comments"},"review_comment":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/422/commits"},"statuses":{"href":"https://api.github.com/repos/solettaproject/soletta/statuses/1884fef58a4de79635b80f86cfb741938002a190"}}}}