{"action":"created","issue":{"url":"https://api.github.com/repos/fivdi/i2c-bus/issues/29","repository_url":"https://api.github.com/repos/fivdi/i2c-bus","labels_url":"https://api.github.com/repos/fivdi/i2c-bus/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/fivdi/i2c-bus/issues/29/comments","events_url":"https://api.github.com/repos/fivdi/i2c-bus/issues/29/events","html_url":"https://github.com/fivdi/i2c-bus/issues/29","id":195939706,"number":29,"title":"ic2-bus.js written as es6 class with promise methods","user":{"login":"dkebler","id":1316185,"avatar_url":"https://avatars.githubusercontent.com/u/1316185?v=3","gravatar_id":"","url":"https://api.github.com/users/dkebler","html_url":"https://github.com/dkebler","followers_url":"https://api.github.com/users/dkebler/followers","following_url":"https://api.github.com/users/dkebler/following{/other_user}","gists_url":"https://api.github.com/users/dkebler/gists{/gist_id}","starred_url":"https://api.github.com/users/dkebler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkebler/subscriptions","organizations_url":"https://api.github.com/users/dkebler/orgs","repos_url":"https://api.github.com/users/dkebler/repos","events_url":"https://api.github.com/users/dkebler/events{/privacy}","received_events_url":"https://api.github.com/users/dkebler/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2016-12-15T23:03:11Z","updated_at":"2016-12-29T20:29:37Z","closed_at":null,"body":"I wanted to use your prototype cb methods as promises and with a bit of fiddling I got bluebird promisifyAll to do that.   \r\n\r\n```\r\nconst i2c = require('i2c-bus'),\r\n      pA = require('bluebird').promisifyAll\r\n\r\nclass Bus {\r\n       constructor(busnum) {\r\n       this.bus = pA(i2c.open(busnum,()=>{}),{suffix: \"_p\",multiArgs: true})\r\n     }\r\n\r\n// add promisifed i2c-bus methods to the class\r\nscan(){ return this.bus.scan_p()}\r\n\r\n// TODO add that same for any any other prototype methods I'll need to use.\r\n}\r\n```\r\nthen\r\n```\r\nconst Bus = require('./lib/class/Bus'),\r\n    _u = require('uci-utils')\r\n\r\nlet bus1 = new Bus(1)\r\n\r\n// console.log('\\n',bus1)\r\n\r\nbus1.scan().then(devs => {\r\n      console.log('devices: ', devs[0].map(_u.dec2hex))  \r\n     // note: response dev is nested array, probably as a result of promisfy multiArgs? \r\n\r\n  }).catch(err=>{console.log(err)})\r\n```\r\n\r\nAs you can see I'm kinda writing a Bus class on top of your Bus class to make this work...seems kinda clunky and nonDRY and I'm having to load the entire BB library to do it and promisfy even your sync methods which is silly.\r\n\r\nWhat I can't live without is your bound C library but I would like to fork the main module (i2c-bus.js) and write it as a proper es6 class (given node now supports that directly) with methods all returning promises and probably dropping the sync methods all together.  \r\n\r\n**So I'm willing to write an alternative class/promise module. Are you willing to give me some input/clarification I will need to do that?**  For example I'm a bit puzzled by the use of the _peripherals key in the constructor.  Initially you have it as an empty array it then gets populated later by the prototype methods??  I'm pretty clueless on the whole binding/gyp/nan...etc. thing so I'd be just trying to use the prototype methods in the existing code more or less as is.\r\n\r\nAnyway I could do this a separate file/module/class say i2c-pbus.js/pBus.  Users could alternatively load this new module (class) that would keep backward compatibility for those using it now.   Normally I'd make just make my own personal fork but I'm happy with your C library and not being a C programmer I'm going to want the advantage of your maintenance on that.  \r\n\r\nJust so you know I looked into wiring-pi node and the other i2c bus library at npm.  The first one is a kitchen sink and not well maintained and the second won't even compile on my RPI3 and is also kinda crusty.  So ic2-bus is dakind.  Thx.\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/fivdi/i2c-bus/issues/comments/269688770","html_url":"https://github.com/fivdi/i2c-bus/issues/29#issuecomment-269688770","issue_url":"https://api.github.com/repos/fivdi/i2c-bus/issues/29","id":269688770,"user":{"login":"dkebler","id":1316185,"avatar_url":"https://avatars.githubusercontent.com/u/1316185?v=3","gravatar_id":"","url":"https://api.github.com/users/dkebler","html_url":"https://github.com/dkebler","followers_url":"https://api.github.com/users/dkebler/followers","following_url":"https://api.github.com/users/dkebler/following{/other_user}","gists_url":"https://api.github.com/users/dkebler/gists{/gist_id}","starred_url":"https://api.github.com/users/dkebler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkebler/subscriptions","organizations_url":"https://api.github.com/users/dkebler/orgs","repos_url":"https://api.github.com/users/dkebler/repos","events_url":"https://api.github.com/users/dkebler/events{/privacy}","received_events_url":"https://api.github.com/users/dkebler/received_events","type":"User","site_admin":false},"created_at":"2016-12-29T20:29:37Z","updated_at":"2016-12-29T20:29:37Z","body":"Not that I can really read C code but it seems as though you have a C method/function corresponding to each js prototype method.  I have looked a few other libraries  for I2c and wondering why you didn't just write a couple  \"raw\"  read, write functions and bind just those functions, creating all the rest as classes/extensions (and controlling concurrency) within node.  Was there some speed benefit?  In such an architecture it would be easier for folks like me to contribute and modify and for you mak the C code maintenance more trivial. \r\n\r\nFor example In my code I am controlling concurrency with a queue.  But as I poke around in your C code it seems it might be already doing that?  So why not just do that in node."}}
{"actor":{"display_login":"dkebler"}}