{"id":1732,"date":"2022-09-24T20:44:44","date_gmt":"2022-09-24T11:44:44","guid":{"rendered":"https:\/\/www.rocher.kyoto.jp\/arbr\/?p=1732"},"modified":"2022-09-27T18:50:29","modified_gmt":"2022-09-27T09:50:29","slug":"webhid-api%e3%82%92%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"https:\/\/www.rocher.kyoto.jp\/arbr\/?p=1732","title":{"rendered":"Web HID API\u3092\u89e6\u3063\u3066\u307f\u305f"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u30e1\u30b8\u30e3\u30fc\u306aCO2\u30bb\u30f3\u30b5\u30fc(ZGm053U)\u306e\u5024\u3092\u62fe\u304a\u3046\u3068\u3057\u305f\u3089HID\u3067\u901a\u4fe1\u3057\u3066\u3044\u308b\u3068\u3044\u3046\u3053\u3068\u3067PC\u7248\u306eChrome\u30fbEdge(\u3042\u3068Opera\u3082\uff1f)\u306a\u3089\u4f7f\u7528\u3067\u304d\u308bWeb HID API\u3092\u4f7f\u3063\u3066\u307f\u305f\u3002\u306a\u304a\u3001\u65b0\u3057\u3081\u306e\u8aad\u307f\u8fbc\u307f\u304c\u516c\u958b\u3055\u308c\u3066\u3044\u308b\u30bf\u30a4\u30d7\u306e\u307f\u5bfe\u5fdc\u3002\uff08\u53e4\u3044\u30bf\u30a4\u30d7\u3060\u3068\u5024\u304c\u6697\u53f7\u5316\u3055\u308c\u3066\u8aad\u307f\u8fbc\u307f\u6a5f\u80fd\u304c\u516c\u958b\u3055\u308c\u3066\u3044\u308b\u308f\u3051\u3067\u306f\u306a\u3044\u306e\u3067\u81ea\u91cd\u3002\u8aad\u307f\u65b9\u306f\u30cd\u30c3\u30c8\u306b\u843d\u3061\u3066\u306f\u3044\u308b\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"twitter-tweet\" data-width=\"550\" data-dnt=\"true\"><p lang=\"ja\" dir=\"ltr\">\u4eba\u6c17CO2\u30bb\u30f3\u30b5\u30fcZGm053U\u306e\u5024\u3092\u30d6\u30e9\u30a6\u30b6(PC\u7248\u306eChrome\/Edge\u9650\u5b9a)\u3067\u898b\u308c\u308b\u4fbf\u5229\u30da\u30fc\u30b8\u66ab\u5b9a\u516c\u958b\u3057\u307e\u3057\u305f\u3002<br>\uff08\u30da\u30fc\u30b8\uff09<a href=\"https:\/\/t.co\/6oxfUVZ3Gl\">https:\/\/t.co\/6oxfUVZ3Gl<\/a><br><br>\uff08\u88fd\u54c1\uff09<a href=\"https:\/\/t.co\/R1bvhZnmRS\">https:\/\/t.co\/R1bvhZnmRS<\/a><br><br>\u4f7f\u3046\u4eba\u591a\u305d\u3046\u3060\u3063\u305f\u3089\u9069\u5b9c\u30d0\u30fc\u30b8\u30e7\u30f3\u30a2\u30c3\u30d7\u3057\u307e\u3059<\/p>&mdash; \u5317\u6751\uff20\u30a8\u30da\u30a2 (@YoshitakeKitamu) <a href=\"https:\/\/twitter.com\/YoshitakeKitamu\/status\/1572776163545870336?ref_src=twsrc%5Etfw\">September 22, 2022<\/a><\/blockquote><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script>\n<\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u65e5\u672c\u3060\u3068CO2mini\u3068\u3057\u3066\u58f2\u3089\u308c\u3066\u3044\u308b\u5927\u4eba\u6c17\u306e\u30e2\u30c7\u30eb\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8aad\u307f\u8fbc\u307f\u7528\u306e\u30da\u30fc\u30b8\u306f<a href=\"https:\/\/www.rocher.kyoto.jp\/zyco2.html\">\u3053\u3061\u3089<\/a><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"twitter-tweet\" data-width=\"550\" data-dnt=\"true\"><p lang=\"ja\" dir=\"ltr\">\u4f7f\u3044\u65b9\u306fpc\u306busb\u7e4b\u3052\u3066\u5024\u53d6\u5f97\u958b\u59cb\u30dc\u30bf\u30f3\u62bc\u3059\u3060\u3051\u3002<br>\u7d42\u4e86\u306f\u304a\u3082\u3080\u308d\u306b\u9589\u3058\u3066\u304f\u3060\u3055\u3044\u3002 <a href=\"https:\/\/t.co\/uQP35oEz6R\">pic.twitter.com\/uQP35oEz6R<\/a><\/p>&mdash; \u5317\u6751\uff20\u30a8\u30da\u30a2 (@YoshitakeKitamu) <a href=\"https:\/\/twitter.com\/YoshitakeKitamu\/status\/1572777194103140354?ref_src=twsrc%5Etfw\">September 22, 2022<\/a><\/blockquote><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script>\n<\/div><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u4eba\u6c17CO2\u30bb\u30f3\u30b5\u30fcZGm053U\u306e\u5024\u3092\u30d6\u30e9\u30a6\u30b6(PC\u7248\u306eChrome\/Edge\u9650\u5b9a)\u3067\u898b\u308c\u308b\u4fbf\u5229\u30da\u30fc\u30b8\u66ab\u5b9a\u516c\u958b\u3057\u307e\u3057\u305f\u3002<\/p><p>\u4f7f\u3046\u4eba\u591a\u305d\u3046\u3060\u3063\u305f\u3089\u9069\u5b9c\u30d0\u30fc\u30b8\u30e7\u30f3\u30a2\u30c3\u30d7\u3057\u307e\u3059<\/p><p>\u4f7f\u3044\u65b9\u306fpc\u306busb\u7e4b\u3052\u3066\u5024\u53d6\u5f97\u958b\u59cb\u30dc\u30bf\u30f3\u62bc\u3059\u3060\u3051\u3002 \u7d42\u4e86\u306f\u304a\u3082\u3080\u308d\u306b\u9589\u3058\u3066\u304f\u3060\u3055\u3044\u3002<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u30b3\u30fc\u30c9\u7684\u306b\u306f\u30b7\u30f3\u30d7\u30eb\u3067\u3001<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">if (&#8220;hid&#8221; in navigator)\u3000\u306b\u3066WebHID\u304c\u4f7f\u7528\u3067\u304d\u308b\u304b\u78ba\u8a8d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const [device] = await navigator.hid.requestDevice({ filters });\u3000\u306b\u3066\u5bfe\u8c61\u30c7\u30d0\u30a4\u30b9\u3092\u53d6\u5f97\u3002CO2\u30bb\u30f3\u30b5\u30fc\u306evendorId: 0x04d9,productId: 0xa052\u306f\u5c11\u3057\u4e0a\u3067\u6307\u5b9a\u3002Windows\u3060\u3068\u30c7\u30d0\u30a4\u30b9\u30de\u30cd\u30fc\u30b8\u30e3\u30fc\u306e\u30d2\u30e5\u30fc\u30de\u30f3\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u30de\u30cd\u30fc\u30b8\u30e3\u30fc\u306b\u305d\u308c\u3063\u307d\u3044\u306e\u304c\u3044\u308b\u306f\u305a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">await device.open().then(() =&gt; {\u3000\u306e\u4e2d\u3067\u63a5\u7d9a\u6642\u306e\u51e6\u7406\u3092\u6307\u5b9a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e2d\u3067\u3084\u3063\u3066\u3044\u308b\u306e\u306fdevice.addEventListener(&#8220;inputreport&#8221;, handleInputReport);\u3068device.sendFeatureReport(0, new Uint8Array([0,0,0,0,0,0,0,0]));<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sendFeatureReport\u306f\u3057\u306a\u3044\u3068\u30bb\u30f3\u30b5\u30fc\u304c\u52d5\u304b\u306a\u3044\u3002\u3053\u306eCO2\u30bb\u30f3\u30b5\u30fc\u306b\u5fc5\u8981\u306a\u9001\u4fe1\u306e\u8d77\u52d5\u6761\u4ef6\u3060\u3068\u601d\u3046\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The&nbsp;<strong><code>sendFeatureReport()<\/code><\/strong>&nbsp;method of the&nbsp;<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/HIDDevice\"><code>HIDDevice<\/code><\/a>&nbsp;interface sends a feature report to the HID device. Feature reports are a way for HID devices and applications to exchange non-standardized HID data.<\/p><cite>https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/HIDDevice\/sendFeatureReport<\/cite><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">addEventListener\u3067\u767b\u9332\u3057\u305ffunction\u5185\u3067\u53d7\u4fe1\u3057\u305fReport(HID\u306e\u901a\u4fe1\u5358\u4f4d\u3089\u3057\u3044)\u3092\u9069\u5b9c\u51e6\u7406\u3002ZGm053U\u306e\u5834\u5408\u306f\u30010\u30d0\u30a4\u30c8\u76ee\u306b\u30c7\u30fc\u30bf\u306e\u7a2e\u985e\u3001received[1] * 256 + received[2]\u3067\u5024\u3002\u30c1\u30a7\u30c3\u30af\u30b5\u30e0\u3068\u304b\u3082\u5165\u3063\u3066\u3044\u308b\u3051\u3069\u3061\u3083\u3093\u3068\u898b\u3066\u306f\u3044\u306a\u3044\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script&gt;\n    const filters = &#91;\n      {\n        vendorId: 0x04d9,\n        productId: 0xa052\n      },\n    ];\n\n    function handleInputReport(e) {\n      let received = new Uint8Array(e.data.buffer);\n      console.log(received);\n      if(received&#91;0]==80){ \/\/ ID 80 \u304cCO2\n        let resultValue =  received&#91;1] * 256 + received&#91;2]; \/\/ \u5024\u3092\u305d\u306e\u307e\u307e\u4fe1\u3058\u308b(\u30c1\u30a7\u30c3\u30af\u30b5\u30e0\u7b49\u306f\u672a\u78ba\u8a8d)\n        document.getElementById(\"co2value\").innerText = resultValue;\n        document.getElementById(\"ppm\").innerText = \"ppm\";\n      }\n    }\n\n    async function checkHID() {\n      if (\"hid\" in navigator) {\n        const &#91;device] = await navigator.hid.requestDevice({ filters });\n        await device.open().then(() =&gt; {\n          device.addEventListener(\"inputreport\", handleInputReport);\n          device.sendFeatureReport(0, new Uint8Array(&#91;0,0,0,0,0,0,0,0])); \/\/ \u5024\u53d6\u5f97\u30b3\u30de\u30f3\u30c9\u9001\u4fe1\u304c\u5fc5\u8981\u306a\u6a21\u69d8\n        })\n      } else {\n        alert(\"USB\u63a5\u7d9a\u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\");\n      }\n    }\n  &lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u30c7\u30fc\u30bf\u9001\u4fe1\u306f\u3057\u3066\u3044\u306a\u3044\u3051\u3069\u3053\u3093\u306a\u611f\u3058\u3089\u3057\u3044\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const enableVibrationData = &#91;1, 0, 1, 64, 64, 0, 1, 64, 64, 0x48, 0x01];\nawait device.sendReport(0x01, new Uint8Array(enableVibrationData));\n\n\/\/ Then, send a command to make the Joy-Con device rumble.\n\/\/ Actual bytes are available in the sample below.\nconst rumbleData = &#91; \/* \u2026 *\/ ];\nawait device.sendReport(0x10, new Uint8Array(rumbleData));<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3042\u3068\u30af\u30ed\u30fc\u30ba\u3082<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>await device.close();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u305d\u306e\u307e\u307e\u5207\u3063\u3066\u3082\u5927\u4e08\u592b\u306e\u3082\u306e\u304c\u591a\u3044\u3068\u601d\u3046\u3051\u3069\u884c\u5100\u306f\u60aa\u3044\u306e\u3067\u3061\u3083\u3093\u3068\u30af\u30ed\u30fc\u30ba\u3057\u305f\u307b\u3046\u304c\u826f\u3044\u3002\uff08\u3051\u3069\u4f5c\u3063\u305f\u30bd\u30fc\u30b9\u3067\u306f\u3084\u3063\u3066\u3044\u306a\u3044\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3061\u306a\u307f\u306b\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u306e\u30dc\u30bf\u30f3\u64cd\u4f5c\u7b49\u5fc5\u9808\u3002\u81ea\u52d5(onload\u3068\u304b)\u3067\u63a5\u7d9a\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u6012\u3089\u308c\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>zyco2.html:52 Uncaught (in promise) DOMException: Failed to execute 'requestDevice' on 'HID': Must be handling a user gesture to show a permission request.<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u30e1\u30b8\u30e3\u30fc\u306aCO2\u30bb\u30f3\u30b5\u30fc(ZGm053U)\u306e\u5024\u3092\u62fe\u304a\u3046\u3068\u3057\u305f\u3089HID\u3067\u901a\u4fe1\u3057\u3066\u3044\u308b\u3068\u3044\u3046\u3053\u3068\u3067PC\u7248\u306eChrome\u30fbEdge(\u3042\u3068Opera\u3082\uff1f)\u306a\u3089\u4f7f\u7528\u3067\u304d\u308bWeb HID API\u3092\u4f7f\u3063\u3066\u307f\u305f\u3002\u306a\u304a\u3001\u65b0\u3057\u3081\u306e\u8aad\u307f\u8fbc\u307f\u304c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76],"tags":[],"class_list":["post-1732","post","type-post","status-publish","format-standard","hentry","category-76"],"_links":{"self":[{"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/posts\/1732","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1732"}],"version-history":[{"count":5,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/posts\/1732\/revisions"}],"predecessor-version":[{"id":1739,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/posts\/1732\/revisions\/1739"}],"wp:attachment":[{"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}