{"action":"created","comment":{"url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/pulls/comments/31298832","id":31298832,"diff_hunk":"@@ -153,9 +153,142 @@\n       </p>\n \n       <section>\n-        <h2>Some examples</h2>\n+        <h2>Examples</h2>\n \n-        <p class=\"issue\">Write Me.</p>\n+        <aside class=\"example\">\n+          <p>\n+            To discover and retrieve data from a standard heart rate monitor,\n+            a website would use code like the following:\n+          </p>\n+          <pre class=\"highlight\">navigator.bluetooth.<a for=\"Bluetooth\">requestDevice</a>({\n+  filters: [{\n+    services: ['heart_rate'],\n+  }]\n+}).then(device => {\n+  window.chosenHeartRateDevice = device;\n+  return device.<a for=\"BluetoothDevice\">connectGATT</a>();\n+})\n+.then(server => server.<a for=\"BluetoothGATTRemoteServer\">getPrimaryService</a>(<a\n+href=\"https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.heart_rate.xml\"\n+>'heart_rate'</a>))\n+.then(service => Promise.all([\n+  service.<a for=\"BluetoothGATTService\">getCharacteristic</a>(<a\n+href=\"https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.body_sensor_location.xml\"\n+>'body_sensor_location'</a>)\n+    .then(handleBodySensorLocationCharacteristic),\n+  service.<a for=\"BluetoothGATTService\">getCharacteristic</a>(<a\n+href=\"https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml\"\n+>'heart_rate_measurement'</a>))\n+   .then(handleHeartRateMeasurementCharacteristic),\n+]));\n+\n+function handleBodySensorLocationCharacteristic(characteristic) {\n+  if (characteristic === null) {\n+    console.log(\"Unknown sensor location.\");\n+    return Promise.resolve();\n+  }\n+  return characteristic.<a for=\"BluetoothGATTCharacteristic\">readValue</a>()\n+  .then(sensorLocationArray => {\n+    let sensorLocation = new Uint8Array(sensorLocationArray)[0];\n+    switch (sensorLocation) {\n+      case 0: return 'Other';\n+      case 1: return 'Chest';\n+      case 2: return 'Wrist';\n+      case 3: return 'Finger';\n+      case 4: return 'Hand';\n+      case 5: return 'Ear Lobe';\n+      case 6: return 'Foot';\n+      default: return 'Unknown';\n+    }\n+  }).then(location => console.log(location));\n+}\n+\n+function handleHeartRateMeasurementCharacteristic(characteristic) {\n+  characteristic.addEventListener('<a>characteristicvaluechanged</a>', onHeartRateChanged);\n+  return characteristic.<a for=\"BluetoothGATTCharacteristic\">startNotifications</a>();\n+}\n+\n+function onHeartRateChanged(event) {\n+  let characteristic = event.target;\n+  console.log(parseHeartRate(characteristic.<a for=\"BluetoothGATTCharacteristic\">value</a>));\n+}</pre>\n+\n+          <p>\n+            <code>parseHeartRate()</code> would be defined using the <a\n+            href=\"https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml\"\n+            >heart_rate_measurement documentation</a> to read the <a>ArrayBuffer</a> stored\n+            in a <a>BluetoothGATTCharacteristic</a>'s\n+            <a for=\"BluetoothGATTCharacteristic\">value</a> field.\n+          </p>\n+\n+          <pre class=\"highlight\">function parseHeartRate(buffer) {\n+  let data = new DataView(buffer);\n+  let flags = data.getUint8(0);\n+  let rate16Bits = flags & 0x1;\n+  let result = {};\n+  let index = 1;\n+  if (rate16Bits) {\n+    result.heartRate = data.getUint16(index, /*littleEndian=*/true);\n+    index += 2;\n+  } else {\n+    result.heartRate = data.getUint8(index);\n+    index += 1;\n+  }\n+  let contactDetected = flags & 0x2;\n+  let contactSensorPresent = flags & 0x4;\n+  if (contactSensorPresent) {\n+    result.contactDetected = !!contactDetected;\n+  }\n+  let energyPresent = flags & 0x8;\n+  if (energyPresent) {\n+    result.energyExpended = data.getUint16(index, /*littleEndian=*/true);\n+    index += 2;\n+  }\n+  let rrIntervalPresent = flags & 0x10;\n+  if (rrIntervalPresent) {\n+    let rrIntervals = [];\n+    for (; index + 1 < data.byteLength; index += 2) {\n+      rrIntervals.push(data.getUint16(index, /*littleEndian=*/true));\n+    }\n+    result.rrIntervals = rrIntervals;\n+  }\n+  return result;\n+}</pre>\n+\n+          <p>\n+            <code>onHeartRateChanged()</code> might log an object like\n+          </p>\n+          <pre class=\"highlight\">{\n+  heartRate: 70,\n+  contactDetected: true,\n+  energyExpended: 750,     // Meaning 750kJ.\n+  rrIntervals: [890, 870]  // Meaning .87s and .85s.\n+}</pre>\n+\n+          <p>\n+            If the heart rate sensor reports the <code>energyExpended</code> field,\n+            the web application can reset its value to <code>0</code> by writing to the\n+            <a href=\"https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_control_point.xml\"\n+               >heart_rate_control_point</a> characteristic:\n+          </p>\n+\n+          <pre class=\"highlight\">function resetEnergyExpended() {\n+  if (!window.chosenHeartRateDevice) {","path":"index.html","position":126,"original_position":126,"commit_id":"db996c09b3d5b10523057aa384d46abd6ba794a6","original_commit_id":"db996c09b3d5b10523057aa384d46abd6ba794a6","user":{"login":"scheib","id":386971,"avatar_url":"https://avatars.githubusercontent.com/u/386971?v=3","gravatar_id":"","url":"https://api.github.com/users/scheib","html_url":"https://github.com/scheib","followers_url":"https://api.github.com/users/scheib/followers","following_url":"https://api.github.com/users/scheib/following{/other_user}","gists_url":"https://api.github.com/users/scheib/gists{/gist_id}","starred_url":"https://api.github.com/users/scheib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scheib/subscriptions","organizations_url":"https://api.github.com/users/scheib/orgs","repos_url":"https://api.github.com/users/scheib/repos","events_url":"https://api.github.com/users/scheib/events{/privacy}","received_events_url":"https://api.github.com/users/scheib/received_events","type":"User","site_admin":false},"body":"Save the heart rate service object and resume from that instead.","created_at":"2015-05-29T04:45:12Z","updated_at":"2015-05-29T04:45:12Z","html_url":"https://github.com/WebBluetoothCG/web-bluetooth/pull/123#discussion_r31298832","pull_request_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/pulls/123","_links":{"self":{"href":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/pulls/comments/31298832"},"html":{"href":"https://github.com/WebBluetoothCG/web-bluetooth/pull/123#discussion_r31298832"},"pull_request":{"href":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/pulls/123"}}},"pull_request":{"url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/pulls/123","id":36461874,"html_url":"https://github.com/WebBluetoothCG/web-bluetooth/pull/123","diff_url":"https://github.com/WebBluetoothCG/web-bluetooth/pull/123.diff","patch_url":"https://github.com/WebBluetoothCG/web-bluetooth/pull/123.patch","issue_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/issues/123","number":123,"state":"open","locked":false,"title":"Add an introductory example, using the Heart Rate Service.","user":{"login":"jyasskin","id":83420,"avatar_url":"https://avatars.githubusercontent.com/u/83420?v=3","gravatar_id":"","url":"https://api.github.com/users/jyasskin","html_url":"https://github.com/jyasskin","followers_url":"https://api.github.com/users/jyasskin/followers","following_url":"https://api.github.com/users/jyasskin/following{/other_user}","gists_url":"https://api.github.com/users/jyasskin/gists{/gist_id}","starred_url":"https://api.github.com/users/jyasskin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jyasskin/subscriptions","organizations_url":"https://api.github.com/users/jyasskin/orgs","repos_url":"https://api.github.com/users/jyasskin/repos","events_url":"https://api.github.com/users/jyasskin/events{/privacy}","received_events_url":"https://api.github.com/users/jyasskin/received_events","type":"User","site_admin":false},"body":"Demo at https://rawgit.com/jyasskin/web-bluetooth-1/example-code/index.html#examples.","created_at":"2015-05-28T23:38:33Z","updated_at":"2015-05-29T04:45:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"23f4d90520cbc0c0f420ab64910c52faa3faf4bc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/pulls/123/commits","review_comments_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/pulls/123/comments","review_comment_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/pulls/comments{/number}","comments_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/issues/123/comments","statuses_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/statuses/db996c09b3d5b10523057aa384d46abd6ba794a6","head":{"label":"jyasskin:example-code","ref":"example-code","sha":"db996c09b3d5b10523057aa384d46abd6ba794a6","user":{"login":"jyasskin","id":83420,"avatar_url":"https://avatars.githubusercontent.com/u/83420?v=3","gravatar_id":"","url":"https://api.github.com/users/jyasskin","html_url":"https://github.com/jyasskin","followers_url":"https://api.github.com/users/jyasskin/followers","following_url":"https://api.github.com/users/jyasskin/following{/other_user}","gists_url":"https://api.github.com/users/jyasskin/gists{/gist_id}","starred_url":"https://api.github.com/users/jyasskin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jyasskin/subscriptions","organizations_url":"https://api.github.com/users/jyasskin/orgs","repos_url":"https://api.github.com/users/jyasskin/repos","events_url":"https://api.github.com/users/jyasskin/events{/privacy}","received_events_url":"https://api.github.com/users/jyasskin/received_events","type":"User","site_admin":false},"repo":{"id":27619379,"name":"web-bluetooth-1","full_name":"jyasskin/web-bluetooth-1","owner":{"login":"jyasskin","id":83420,"avatar_url":"https://avatars.githubusercontent.com/u/83420?v=3","gravatar_id":"","url":"https://api.github.com/users/jyasskin","html_url":"https://github.com/jyasskin","followers_url":"https://api.github.com/users/jyasskin/followers","following_url":"https://api.github.com/users/jyasskin/following{/other_user}","gists_url":"https://api.github.com/users/jyasskin/gists{/gist_id}","starred_url":"https://api.github.com/users/jyasskin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jyasskin/subscriptions","organizations_url":"https://api.github.com/users/jyasskin/orgs","repos_url":"https://api.github.com/users/jyasskin/repos","events_url":"https://api.github.com/users/jyasskin/events{/privacy}","received_events_url":"https://api.github.com/users/jyasskin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jyasskin/web-bluetooth-1","description":"Toward Bluetooth support for the Open Web.","fork":true,"url":"https://api.github.com/repos/jyasskin/web-bluetooth-1","forks_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/forks","keys_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/teams","hooks_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/hooks","issue_events_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/issues/events{/number}","events_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/events","assignees_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/assignees{/user}","branches_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/branches{/branch}","tags_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/tags","blobs_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/statuses/{sha}","languages_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/languages","stargazers_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/stargazers","contributors_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/contributors","subscribers_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/subscribers","subscription_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/subscription","commits_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/contents/{+path}","compare_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/merges","archive_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/downloads","issues_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/issues{/number}","pulls_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/pulls{/number}","milestones_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/milestones{/number}","notifications_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/labels{/name}","releases_url":"https://api.github.com/repos/jyasskin/web-bluetooth-1/releases{/id}","created_at":"2014-12-06T02:31:50Z","updated_at":"2015-04-06T22:30:01Z","pushed_at":"2015-05-29T01:11:10Z","git_url":"git://github.com/jyasskin/web-bluetooth-1.git","ssh_url":"git@github.com:jyasskin/web-bluetooth-1.git","clone_url":"https://github.com/jyasskin/web-bluetooth-1.git","svn_url":"https://github.com/jyasskin/web-bluetooth-1","homepage":"http://www.w3.org/community/web-bluetooth/","size":1093,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"gh-pages"}},"base":{"label":"WebBluetoothCG:gh-pages","ref":"gh-pages","sha":"35c543f5cfd6d8943cc48f71997b7ff1fa92698a","user":{"login":"WebBluetoothCG","id":8389284,"avatar_url":"https://avatars.githubusercontent.com/u/8389284?v=3","gravatar_id":"","url":"https://api.github.com/users/WebBluetoothCG","html_url":"https://github.com/WebBluetoothCG","followers_url":"https://api.github.com/users/WebBluetoothCG/followers","following_url":"https://api.github.com/users/WebBluetoothCG/following{/other_user}","gists_url":"https://api.github.com/users/WebBluetoothCG/gists{/gist_id}","starred_url":"https://api.github.com/users/WebBluetoothCG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WebBluetoothCG/subscriptions","organizations_url":"https://api.github.com/users/WebBluetoothCG/orgs","repos_url":"https://api.github.com/users/WebBluetoothCG/repos","events_url":"https://api.github.com/users/WebBluetoothCG/events{/privacy}","received_events_url":"https://api.github.com/users/WebBluetoothCG/received_events","type":"Organization","site_admin":false},"repo":{"id":22738546,"name":"web-bluetooth","full_name":"WebBluetoothCG/web-bluetooth","owner":{"login":"WebBluetoothCG","id":8389284,"avatar_url":"https://avatars.githubusercontent.com/u/8389284?v=3","gravatar_id":"","url":"https://api.github.com/users/WebBluetoothCG","html_url":"https://github.com/WebBluetoothCG","followers_url":"https://api.github.com/users/WebBluetoothCG/followers","following_url":"https://api.github.com/users/WebBluetoothCG/following{/other_user}","gists_url":"https://api.github.com/users/WebBluetoothCG/gists{/gist_id}","starred_url":"https://api.github.com/users/WebBluetoothCG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WebBluetoothCG/subscriptions","organizations_url":"https://api.github.com/users/WebBluetoothCG/orgs","repos_url":"https://api.github.com/users/WebBluetoothCG/repos","events_url":"https://api.github.com/users/WebBluetoothCG/events{/privacy}","received_events_url":"https://api.github.com/users/WebBluetoothCG/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WebBluetoothCG/web-bluetooth","description":"Toward Bluetooth support for the Open Web.","fork":false,"url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth","forks_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/forks","keys_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/teams","hooks_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/hooks","issue_events_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/issues/events{/number}","events_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/events","assignees_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/assignees{/user}","branches_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/branches{/branch}","tags_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/tags","blobs_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/git/refs{/sha}","trees_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/statuses/{sha}","languages_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/languages","stargazers_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/stargazers","contributors_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/contributors","subscribers_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/subscribers","subscription_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/subscription","commits_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/commits{/sha}","git_commits_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/git/commits{/sha}","comments_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/comments{/number}","issue_comment_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/issues/comments{/number}","contents_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/contents/{+path}","compare_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/merges","archive_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/downloads","issues_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/issues{/number}","pulls_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/pulls{/number}","milestones_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/milestones{/number}","notifications_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/labels{/name}","releases_url":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/releases{/id}","created_at":"2014-08-07T22:33:52Z","updated_at":"2015-05-22T20:13:29Z","pushed_at":"2015-05-29T01:11:38Z","git_url":"git://github.com/WebBluetoothCG/web-bluetooth.git","ssh_url":"git@github.com:WebBluetoothCG/web-bluetooth.git","clone_url":"https://github.com/WebBluetoothCG/web-bluetooth.git","svn_url":"https://github.com/WebBluetoothCG/web-bluetooth","homepage":"http://www.w3.org/community/web-bluetooth/","size":1920,"stargazers_count":43,"watchers_count":43,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":8,"mirror_url":null,"open_issues_count":25,"forks":8,"open_issues":25,"watchers":43,"default_branch":"gh-pages"}},"_links":{"self":{"href":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/pulls/123"},"html":{"href":"https://github.com/WebBluetoothCG/web-bluetooth/pull/123"},"issue":{"href":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/issues/123"},"comments":{"href":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/issues/123/comments"},"review_comments":{"href":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/pulls/123/comments"},"review_comment":{"href":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/pulls/123/commits"},"statuses":{"href":"https://api.github.com/repos/WebBluetoothCG/web-bluetooth/statuses/db996c09b3d5b10523057aa384d46abd6ba794a6"}}}}