|
| 1 | + |
| 2 | +from dumbdisplay.core import * |
| 3 | +from dumbdisplay.layer_graphical import LayerGraphical |
| 4 | +from dumbdisplay.layer_lcd import LayerLcd |
| 5 | + |
| 6 | + |
| 7 | +TOP_HEIGHT = 30 |
| 8 | +WIDTH = 14 |
| 9 | +HEIGHT = 80 |
| 10 | +BORDER = 1 |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +# create DumbDisplay |
| 15 | +if DumbDisplay.runningWithMicropython(): |
| 16 | + # connect using WIFI: |
| 17 | + # assume a _my_secret.py Python script containing |
| 18 | + # WIFI_SSID="SSID" |
| 19 | + # WIFI_PWD="PASSWORD" |
| 20 | + from _my_secret import * |
| 21 | + from dumbdisplay.io_wifi import * |
| 22 | + dd = DumbDisplay(io4Wifi(WIFI_SSID, WIFI_PWD)) |
| 23 | +else: |
| 24 | + # connect using Inet (Python Internet connection) |
| 25 | + from dumbdisplay.io_inet import * |
| 26 | + dd = DumbDisplay(io4Inet()) |
| 27 | + |
| 28 | + |
| 29 | +def SetupKey(octiveOffset: int, noteIdx: int) -> LayerGraphical: |
| 30 | + width = WIDTH - 2 * BORDER |
| 31 | + xOffset = noteIdx * WIDTH / 2 |
| 32 | + #height |
| 33 | + #bgColor |
| 34 | + isSemi = False |
| 35 | + if noteIdx == 1 or noteIdx == 3 or noteIdx == 6 or noteIdx == 8 or noteIdx == 10: |
| 36 | + height = HEIGHT / 2 + 10 |
| 37 | + bgColor = "black" |
| 38 | + isSemi = True |
| 39 | + else: |
| 40 | + height = HEIGHT |
| 41 | + bgColor = "white" |
| 42 | + if noteIdx > 4: |
| 43 | + xOffset += WIDTH / 2 |
| 44 | + customData = chr(ord(" ") + octiveOffset) + chr(ord(" ") + noteIdx) |
| 45 | + #customData[0] = '0' + octiveOffset; |
| 46 | + #customData[1] = '0' + noteIdx; |
| 47 | + #customData[2] = 0; |
| 48 | + keyLayer = LayerGraphical(dd, width, height) |
| 49 | + keyLayer.customData = customData |
| 50 | + keyLayer.backgroundColor(bgColor) |
| 51 | + keyLayer.border(BORDER, "gray") |
| 52 | + keyLayer.padding(0) |
| 53 | + #keyLayer->setFeedbackHandler(FeedbackHandler, "f"); |
| 54 | + if isSemi: |
| 55 | + #dumbdisplay.reorderLayer(keyLayer, "T"); |
| 56 | + pass |
| 57 | + else: |
| 58 | + if noteIdx == 0: |
| 59 | + keyLayer.drawStr(2, HEIGHT - 15, "C", "blue") |
| 60 | + l = WIDTH + octiveOffset * 7 * WIDTH + xOffset |
| 61 | + t = TOP_HEIGHT |
| 62 | + w = width + 2 * BORDER |
| 63 | + h = height + 2 * BORDER |
| 64 | + keyLayer.pinLayer(l, t, w, h) |
| 65 | + return keyLayer |
| 66 | + |
| 67 | +def SetupButton(label: str) -> LayerLcd: |
| 68 | + buttonLayer = LayerLcd(dd, 4, 1) |
| 69 | + buttonLayer.writeLine(label, 0, "C") |
| 70 | + buttonLayer.border(1, "darkgray", "round") |
| 71 | + buttonLayer.noBackgroundColor() |
| 72 | + #buttonLayer.setFeedbackHandler(FeedbackHandler, "f"); |
| 73 | + return buttonLayer |
| 74 | + |
| 75 | +dd.recordLayerSetupCommands() |
| 76 | + |
| 77 | +dd.configPinFrame(9 * WIDTH, TOP_HEIGHT + HEIGHT) |
| 78 | + |
| 79 | +SetupKey(-1, 11) |
| 80 | +for i in range(0, 12): |
| 81 | + SetupKey(0, i) |
| 82 | +SetupKey(1, 0) |
| 83 | + |
| 84 | +playLayer = SetupButton("⏯"); |
| 85 | +restartLayer = SetupButton("⏮"); |
| 86 | +targetLayer = SetupButton("📱"); |
| 87 | + |
| 88 | +dd.pinAutoPinLayers(AutoPin("H", playLayer, restartLayer, targetLayer).build(), 0, 0, 9 * WIDTH, TOP_HEIGHT) |
| 89 | + |
| 90 | +dd.playbackLayerSetupCommands("ddmelody") |
0 commit comments