{"action":"created","issue":{"url":"https://api.github.com/repos/cnlohr/libsurvive/issues/4","repository_url":"https://api.github.com/repos/cnlohr/libsurvive","labels_url":"https://api.github.com/repos/cnlohr/libsurvive/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/cnlohr/libsurvive/issues/4/comments","events_url":"https://api.github.com/repos/cnlohr/libsurvive/issues/4/events","html_url":"https://github.com/cnlohr/libsurvive/issues/4","id":195984304,"number":4,"title":"Improve Light Disambiguator","user":{"login":"cnlohr","id":2748168,"avatar_url":"https://avatars.githubusercontent.com/u/2748168?v=3","gravatar_id":"","url":"https://api.github.com/users/cnlohr","html_url":"https://github.com/cnlohr","followers_url":"https://api.github.com/users/cnlohr/followers","following_url":"https://api.github.com/users/cnlohr/following{/other_user}","gists_url":"https://api.github.com/users/cnlohr/gists{/gist_id}","starred_url":"https://api.github.com/users/cnlohr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cnlohr/subscriptions","organizations_url":"https://api.github.com/users/cnlohr/orgs","repos_url":"https://api.github.com/users/cnlohr/repos","events_url":"https://api.github.com/users/cnlohr/events{/privacy}","received_events_url":"https://api.github.com/users/cnlohr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":23,"created_at":"2016-12-16T05:33:13Z","updated_at":"2016-12-20T20:28:11Z","closed_at":null,"body":"The light disambiguator is right now very poor.  Located in survive_process.c it is rather simplistic, and something terrible happens when you power on the watchmen controllers.\r\n\r\nWould anyone mind taking a whack at this to help me out?\r\n\r\n```\r\nstatic void handle_lightcap( struct SurviveObject * so, struct LightcapElement * le )\r\n{\r\n\tstruct SurviveContext * ct = so->ctx;\r\n\r\n\tif( le->type != 0xfe || le->length < 50 ) return;\r\n\t//le->timestamp += (le->length/2);\r\n\r\n\tif( le->length > 2100 ) //Pulse longer indicates a sync pulse.\r\n\t{\r\n\t\tint32_t deltat = (uint32_t)le->timestamp - (uint32_t)ct->last_photo_time;\r\n\t\tif( deltat > 2000 || deltat < -2000 )\t\t//New pulse. (may be inverted)\r\n\t\t{\r\n\t\t\tif( le->timestamp - ct->last_photo_time > 80000 )\r\n\t\t\t{\r\n\t\t\t\tct->last_photo_time = le->timestamp;\r\n\t\t\t\tct->total_photo_time = 0;\r\n\t\t\t\tct->total_photos = 0;\r\n\t\t\t\tct->total_pulsecode_time = 0;\r\n\t\t\t\tct->lightproc( so, le->sensor_id, -1, 0, le->timestamp, deltat );\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tct->total_pulsecode_time += le->length;\r\n\t\t\tct->total_photo_time += deltat;\r\n\t\t\tct->total_photos++;\r\n\t\t}\r\n\t}\r\n\telse if( le->length < 1200 && le->length > 40 && ct->total_photos )\r\n\t{\r\n\t\tint32_t dl = (ct->total_photo_time/ct->total_photos);\r\n\t\tint32_t tpco = (ct->total_pulsecode_time/ct->total_photos);\r\n\t\t//Adding length \r\n\t\tint32_t offset_from = le->timestamp - dl - ct->last_photo_time + le->length/2;\r\n\r\n\t\t//Long pulse-code from IR flood.\r\n\t\t//Make sure it fits nicely into a divisible-by-500 time.\r\n\t\tint32_t acode = (tpco+125)/250;\r\n\t\tif( acode & 1 ) return;\r\n\t\tacode>>=1;\r\n\t\tacode -= 6;\r\n\r\n\t\tif( offset_from < 380000 )\r\n\t\t{\r\n\t\t\tct->lightproc( so, le->sensor_id, acode, offset_from, le->timestamp, le->length );\r\n\t\t}\r\n\t}\r\n\telse\r\n\t{\r\n\t\t//Runt pulse.\r\n\t}\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/cnlohr/libsurvive/issues/comments/268349856","html_url":"https://github.com/cnlohr/libsurvive/issues/4#issuecomment-268349856","issue_url":"https://api.github.com/repos/cnlohr/libsurvive/issues/4","id":268349856,"user":{"login":"jpicht","id":4610188,"avatar_url":"https://avatars.githubusercontent.com/u/4610188?v=3","gravatar_id":"","url":"https://api.github.com/users/jpicht","html_url":"https://github.com/jpicht","followers_url":"https://api.github.com/users/jpicht/followers","following_url":"https://api.github.com/users/jpicht/following{/other_user}","gists_url":"https://api.github.com/users/jpicht/gists{/gist_id}","starred_url":"https://api.github.com/users/jpicht/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpicht/subscriptions","organizations_url":"https://api.github.com/users/jpicht/orgs","repos_url":"https://api.github.com/users/jpicht/repos","events_url":"https://api.github.com/users/jpicht/events{/privacy}","received_events_url":"https://api.github.com/users/jpicht/received_events","type":"User","site_admin":false},"created_at":"2016-12-20T20:28:11Z","updated_at":"2016-12-20T20:28:11Z","body":"The pulses in a batch seem to be ordered by the falling edge (timestamp + length) instead of the leading edge."}}
{"actor":{"display_login":"jpicht"}}