# cgo 與 channel # 造成讀取 USB 失敗 ## by LSChyi <img src="https://mirrors.creativecommons.org/presskit/buttons/88x31/png/by-sa.png" style="width: 5vw"/> --- ## Who am I - LSChyi (李松錡) - Software Engineer in Glasnostic.Inc, 開發跑在 Kubernetes 上的流量控管元件 - 人體工學鍵盤愛好兼開發者 <img src="https://pretalx.com/media/avatars/20934796_1826606700689294_9133031414090466081_o_LmP2dSB.jpg" style="width:15vw" /> --- 可能說有個瘋子在 COSCUP 2019 lightning talk 上去拿鍵盤打字代替說話比較多人有印象XD --- <img src="https://www.ergokb.tw/free_trial_ExDactyl/rent_1.jpg" style="height: 60vh" /> --- 這就是故事的開端 --- ErgodoxTW <img src="https://www.ergokb.tw/ErgodoxTW_share/cover.jpg" style="height: 60vh" /> --- 可以自己定義每一顆按鍵的功能 <img src="https://www.ergokb.tw/why_I_use_ergodox/first_layer_key_def.png" style="height:50vh" /> --- 做出適合自己的按鍵設定 - 手指減少移動距離 - 減少整個手的移動 --- 越常按的按鍵擺越近(平時放鬆狀態) - 先了解自己常按哪個按鍵 - 那個按鍵功能是什麼? --- 必須要從鍵盤韌體下手 不能只從電腦紀錄什麼功能的按鍵被按壓 <img src="https://www.ergokb.tw/why_I_use_ergodox/first_layer_key_def.png" style="height:50vh" /> --- 基於 Opensource 的鍵盤韌體 [QMK](https://github.com/qmk/qmk_firmware) ![](https://repository-images.githubusercontent.com/27737393/972b4780-87e4-11e9-8a89-f42dee012fd5) --- [HID_listen](https://github.com/PaulStoffregen/hid_listen) ![](https://i.imgur.com/OpHwszm.png) --- ![](https://i.imgur.com/bQ6kHm3.png) --- ![](https://i.imgur.com/YDGk6tS.png) --- Log Format # ErgoKB:4,6,0,1,40\n - colume 4 - row 6 - released (0) - at layer 1 - key code 40 --- Test Driven Development! ![](https://i.imgur.com/zEkKR4R.png) --- Listener ![](https://i.imgur.com/LwWKk7e.png) --- ![](https://i.imgur.com/dV89Bv2.png) --- > ErgoKB:4,6,0ErgoKB:1,8,1,0,66\n --- ![](https://i.imgur.com/DjlMmaw.jpg) --- 難道參數設錯了 tune queue size, etc ![](https://i.imgur.com/DkQC6xV.png) --- CGO call 很貴 reference: [The Cost and Complexity of Cgo](https://www.cockroachlabs.com/blog/the-cost-and-complexity-of-cgo/) ![](https://i.imgur.com/ERTmQbP.png) --- 那在 C 裡面讀到完整的 log 再拋出來吧 ![](https://i.imgur.com/AF1ynOi.png) --- > ErgoKB:4,6,0,1,40\n > ErgoKB:4,6,1,1,40\n --- ![](https://i.imgur.com/UPkB9PD.png) --- ![](https://i.imgur.com/5nC9tu4.png) --- ![](https://i.imgur.com/0GSpybm.png) --- ![](https://i.imgur.com/pW876fC.png) --- ![](https://i.imgur.com/YWisVEa.png) --- ![](https://i.imgur.com/t6CvRRO.png) --- ![](https://i.imgur.com/Dt7enoB.png) --- ![](https://i.imgur.com/nu4CFJ7.png) --- go 的 channel 其實是有 lock 的 即便是 buffered channel 你還是要拿到 lock 才能寫入 --- ![](https://i.imgur.com/zSPbxFA.png) --- ![](https://i.imgur.com/sxrLnur.png) --- <img src="https://i.imgur.com/d44gIz8.png" style="height:60vh" /> --- # Live Demo --- # 結論 - Go 在開發 low level 的 application 目前並不是最佳的 - cgo 的 cost 並不小,但可以透過將適當的邏輯放入 C code 中解決 - channel 其實就隱含了一個 lock,buffered channel 要寫進去還是要拿到這個 lock --- 最新力作 Phoenix Keyboard <img src="https://i.imgur.com/3ylKUdz.jpg" style="height: 50vh" />
{"metaMigratedAt":"2023-06-15T11:17:18.828Z","metaMigratedFrom":"Content","title":"cgo 與 channel","breaks":true,"contributors":"[{\"id\":\"fd9971ad-bfab-44db-9c69-54cd07fe3fc9\",\"add\":3331,\"del\":421}]"}
    531 views