-
Notifications
You must be signed in to change notification settings - Fork 6
Lighting
CAUTION: this page is working in progress and will be modified frequently. (at least, it will be translate into English)
本裝置乃是 ISSC 為了測試 Automation IO 功能製作
- 使用 BM77SPP
- 支援 Automation IO Service
- Digital IO - 以七個 LED 燈作為指示
- Analog IO - 以一個 RGB 三色 LED 燈作為指示

關於 Automation IO 的資訊可以在 Bluetooth.org 的網站找到,目前為止尚在制定 Specification,因此該頁面需要先登入帳號才能閱讀。
相關的 UUID 如下
| UUID | Description |
|---|---|
| 0x1815 | Automation IO Service |
| 0x2A56 | Digital Input Characteristic |
| 0x2A57 | Digital Output Characteristic |
| 0x2A58 | Analog Input Characteristic |
| 0x2A59 | Analog Output Characteristic |
| 0x2A5A | Aggregate Input Characteristic |
以及 ISSC Proprietary
| UUID | Description |
|---|---|
| 49535343-6C1F-401D-BAA3-EC966D1A3AA1 | ISSC Proprietary Digital Input Description Characteristic |
| 49535343-F82E-4B2B-847C-DBEA67318E35 | ISSC Proprietary Digital Output Description Characteristic |
| 49535343-A742-442B-9D20-24C6709FBD16 | ISSC Proprietary Analog Output1 Description Characteristic |
| 49535343-B011-4081-9C96-C3990D17A69E | ISSC Proprietary Analog Input1 Description Characteristic |
透過 Digital Input / Output 控制七個 LED 燈的亮滅,下圖為七個燈全亮的狀態

會使用到的 UUID 如下
- 1815 - Automation IO Service
- 2A57 - Digital Out
對 Automation IO Service 裡的 Digital Out Characteristic 寫入兩個 byte 長度的數值,即可控制七個 LED 燈。每個 LED 燈使用 2 bits,可參考 org.bluetooth.characteristic.digital_output(需登入)
- 0b 01 - 燈亮
- 0b 00 - 燈滅
LED 燈對應的 Value Index 為
| LED Number | Index |
|---|---|
| 0 | 5 |
| 1 | 3 |
| 2 | 2 |
| 3 | 6 |
| 4 | 1 |
| 5 | 0 |
| 6 | 4 |
展開成 byte array 的圖示如下
| byte [0] | byte [1] |
|---|---|
| #### - LED3 - LED0 - LED6 | LED1 - LED2 - LED4 - LED5 |
| bit 7,6 - bit 5,4 - bit 3,2 - bit 1,0 | bit 7,6 - bit 5,4 - bit 3,2 - bit 1,0 |
舉例來說
char value[] = {0b00010000, 0b00010000};
將此值寫入 Digital Output 的 Characteristic,便是點亮 LED 3 與 LED 2,其餘 LED 燈皆熄滅
透過 Analog IO 能夠控制 RGB 三色燈的顏色,對 Lighting 的裝置而言,紅綠藍三色各有 10 階程度的明亮,因此可以顯示 10 * 10 * 10 = 1000 種顏色。

三色燈的控制比較複雜,使用 PWM 來控制,改變顏色的方式是控制 RGB 三色不同程度的明亮。主要的操作邏輯為
- 在 ISSC Proprietary 的 Characteristic 寫入數值,決定 RGB 三個顏色的燈,何者該亮,何者該滅
- 對 R 的 Characteristic 寫入明亮程度 - 如果需要點亮紅色
- 對 G 的 Characteristic 寫入明亮程度 - 如果需要點亮綠色
- 對 B 的 Characteristic 寫入明亮程度 - 如果需要點亮藍色
也就是說,要改變一次顏色,最多會寫出四次 Characteristic,最少會寫出一次(全關)。
舉例來說
- if (R, G, B) = (5, 2, 4)
- 設定 R=on, G = on, B = on
- 寫出 R 的 level
- 寫出 G 的 level
- 寫出 B 的 level
- if (R, G, B) = (0, 2, 4)
- 設定 R=off, G = on, B = on
- 寫出 G 的 level
- 寫出 B 的 level
- if (R, G, B) = (0, 2, 0)
- 設定 R=off, G = on, B = off
- 寫出 G 的 level
- if (R, G, B) = (0, 0, 4)
- 設定 R=off, G = off, B = on
- 寫出 B 的 level
- if (R, G, B) = (0, 0, 0)
- 設定 R=off, G = off, B = off
注意:根據 Lighting 裝置的實作,如果設定某個顏色為 off,後續卻寫入該顏色的 level,仍然會打開該顏色並調整至對應亮度
會用到的 UUID 有
- 1815 - Automation IO Service
- 2A59 - Analog Output Characteristic
- 49535343-A742-442B-9D20-24C6709FBD16 - ISSC Proprietary Analog Output Description Characteristic
注意:在 Lighting 的實作上,三個 Analog Output Characteristic 的 UUID 皆相同,從 Service Table 裡頭的 Characteristic 順序分別對應到 R G B (根據目前的測試,寫出數值到 UUID 重複的不同 Characteristic,會使得系統 callback 的回應不正確)
要設定 RGB 的開關,使用到 ISSC Proprietary Analog Output Description Characteristic,該 Characteristic 的有 4 bytes,在 Byte 1 裡頭指定 RGB 的開關,1 為開,0 為關。使用 Lighting 的時候固定都將 Top Value 設定為 0x9F
| byte[ 0 ] | byte[ 1 ] | byte[ 2 ] | byte[ 3 ] |
|---|---|---|---|
| Reserved | _____RGB | Top Value | |
| 0x00 | 11111 bit 2,1,0 | 0x9f | 0x00 |
舉例來說
char foo[] = {0x00, 0b11111001, 0x9f, 0x00}; // R=off, G=off, B=on
char bar[] = {0x00, 0xfb, 0x9f, 0x00}; // R=off, G=on, B=on
決定開關之後,接著就是要寫入明暗的程度,也就是 Duty Cycle,Duty Cycle 設定愈大則愈暗(FIXME: Why? Please comment),設定的值有 9 階,從最暗 Level=1(0x8F),較亮 Level=2(0x7F),更亮 Level=3(0x6F)....到最亮 Level=9(0x0F)。(若要完全關閉,就是不設定明暗程度,而在 Set RGB 的時候關掉)
- 0x8F
- 0x7F
- 0x6F
- 0x5F
- 0x4F
- 0x3F
- 0x2F
- 0x1F
- 0x0F
Analog Output 的資料格式請參考 org.bluetooth.characteristic.analog_output (需登入), 16 bits 的整數即 2 bytes,所以寫入的欄位是
| byte[ 0 ] | byte[ 1 ] |
|---|---|
| Duty | 0x00 |
舉例來說
- 0x8F00 - 最暗
- 0x0F00 - 最亮
綜合前述舉出一些例子
- 設定 (R, G, B) = (0, 1, 9)
- 0x00, 0xfe, 0x9f, 0x00
- 0x8f, 0x00 - write to G
- 0x0f, 0x00 - write to B
- 設定 (R, G, B) = (9, 2, 0)
- 0x00, 0xfb, 0x9f, 0x00
- 0x0f, 0x00 - write to R
- 0x8f, 0x00 - write to G
- 設定 (R, G, B) = (1, 9, 9)
- 0x00, 0xff, 0x9f, 0x00
- 0x8f, 0x00 - write to R
- 0x0f, 0x00 - write to G
- 0x0f, 0x00 - write to B