Skip to content

Commit ddb9dca

Browse files
committed
fixup and cleanup of pinmux, added tooltips, added colors
1 parent 6296c71 commit ddb9dca

7 files changed

Lines changed: 308 additions & 111 deletions

File tree

qml/Functions.js

Lines changed: 134 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ function loadPinmux()
4444
pin.overlay = ""
4545
pin.gpioDirection = "unmodidied"
4646
pin.gpioValue = "unmodified"
47+
pin.kernelPinNumber = 0
48+
pin.pruPinNumber = 0
4749
}
4850
}
4951

@@ -104,6 +106,12 @@ function loadPinmux()
104106
case "CAPE":
105107
targetPin.overlay = functionsData[0]
106108
break;
109+
case "PRU":
110+
targetPin.pruPinNumber = parseInt(functionsData[0])
111+
break;
112+
case "GPIO":
113+
targetPin.kernelPinNumber = parseInt(functionsData[0])
114+
break;
107115
default:
108116
}
109117

@@ -157,12 +165,17 @@ function loadConfig(fileName)
157165

158166
var overlays = []
159167
overlaySelector.clearSelection() // clear selected overlays
168+
documentTitle = ""
160169

161170
for (var i = 0; i < lines.length; ++i)
162171
{
163172
var line = lines[i]
173+
var titleText = "# title: "
164174

165-
if ((line.length === 0) || (line[0] === "#")) // skip empty and comment lines
175+
if (line.indexOf(titleText) === 0) // get the document title
176+
documentTitle = line.substring(titleText.length)
177+
178+
if ((line.length === 0) || (line[0] === "#")) // skip empty and comment lines
166179
continue;
167180

168181
var lineDataRaw = line.split(" ")
@@ -206,30 +219,79 @@ function loadConfig(fileName)
206219
var targetPin = portList[port-8].pinList[pin-1]
207220

208221
//right hand value
209-
if ((lineData[1] === "in") || (lineData[1] === "input"))
210-
{
222+
switch (lineData[1].toLowerCase()) {
223+
case "in":
224+
case "input":
211225
targetPin.type = "gpio"
212226
targetPin.gpioDirection = "in"
213-
}
214-
else if ((lineData[1] === "out") || (lineData[1] === "output"))
215-
{
227+
break;
228+
case "out":
229+
case "output":
216230
targetPin.type = "gpio"
217231
targetPin.gpioDirection = "out"
218-
}
219-
else if ((lineData[1] === "hi") || (lineData[1] === "high") || (lineData[1] === "1"))
220-
{
232+
break;
233+
case "hi":
234+
case "high":
235+
case "1":
221236
targetPin.type = "gpio"
222237
targetPin.gpioDirection = "out"
223238
targetPin.gpioValue = "high"
224-
}
225-
else if ((lineData[1] === "lo") || (lineData[1] === "low") || (lineData[1] === "0"))
226-
{
239+
break;
240+
case "lo":
241+
case "low":
242+
case "0":
227243
targetPin.type = "gpio"
228244
targetPin.gpioDirection = "out"
229245
targetPin.gpioValue = "low"
230-
}
231-
else
232-
{
246+
break;
247+
case "in+":
248+
case "input+":
249+
targetPin.type = "gpio_pu"
250+
targetPin.gpioDirection = "in"
251+
break;
252+
case "in-":
253+
case "input-":
254+
targetPin.type = "gpio_pd"
255+
targetPin.gpioDirection = "in"
256+
break
257+
case "out+":
258+
case "output+":
259+
targetPin.type = "gpio_pu"
260+
targetPin.gpioDirection = "out"
261+
break;
262+
case "out-":
263+
case "output-":
264+
targetPin.type = "gpio_pd"
265+
targetPin.gpioDirection = "out"
266+
break;
267+
case "hi+":
268+
case "high+":
269+
case "1+":
270+
targetPin.type = "gpio_pu"
271+
targetPin.gpioDirection = "out"
272+
targetPin.gpioValue = "high"
273+
break;
274+
case "hi-":
275+
case "high-":
276+
case "1-":
277+
targetPin.type = "gpio_pd"
278+
targetPin.gpioDirection = "out"
279+
targetPin.gpioValue = "high"
280+
break;
281+
case "lo+":
282+
case "low+":
283+
case "0+":
284+
targetPin.type = "gpio_pu"
285+
targetPin.gpioDirection = "out"
286+
targetPin.gpioValue = "low"
287+
break;
288+
case "lo-":
289+
case "low-":
290+
case "0-":
291+
targetPin.type = "gpio_pd"
292+
targetPin.gpioDirection = "out"
293+
targetPin.gpioValue = "low"
294+
default:
233295
targetPin.type = lineData[1]
234296
}
235297

@@ -253,6 +315,7 @@ function saveConfig(fileName) {
253315
var data = ""
254316

255317
data += "# File generated with BB pin configurator\n"
318+
data += "# title: " + documentTitle + "\n"
256319

257320
// exporting overlays
258321
for (var i = 0; i < overlaySelector.output.length; ++i)
@@ -292,6 +355,36 @@ function saveConfig(fileName) {
292355
command += "gpio"
293356
}
294357
}
358+
else if (sourcePin.type === "gpio_pu")
359+
{
360+
if ((sourcePin.gpioValue !== "unmodified") && (sourcePin.gpioDirection === "out"))
361+
{
362+
command += sourcePin.gpioValue + "+"
363+
}
364+
else if (sourcePin.gpioDirection !== "unmodified")
365+
{
366+
command += sourcePin.gpioDirection + "+"
367+
}
368+
else
369+
{
370+
command += "gpio_pu"
371+
}
372+
}
373+
else if (sourcePin.type === "gpio_pd")
374+
{
375+
if ((sourcePin.gpioValue !== "unmodified") && (sourcePin.gpioDirection === "out"))
376+
{
377+
command += sourcePin.gpioValue + "-"
378+
}
379+
else if (sourcePin.gpioDirection !== "unmodified")
380+
{
381+
command += sourcePin.gpioDirection + "-"
382+
}
383+
else
384+
{
385+
command += "gpio_pd"
386+
}
387+
}
295388
else
296389
{
297390
command += sourcePin.type
@@ -315,3 +408,29 @@ function saveConfig(fileName) {
315408
console.log("file error")
316409
}
317410
}
411+
412+
function rgb2hsv (color) {
413+
var computedH = 0;
414+
var computedS = 0;
415+
var computedV = 0;
416+
var r = color.r;
417+
var g = color.g;
418+
var b = color.b;
419+
420+
var minRGB = Math.min(r,Math.min(g,b));
421+
var maxRGB = Math.max(r,Math.max(g,b));
422+
423+
// Black-gray-white
424+
if (minRGB === maxRGB) {
425+
computedV = minRGB;
426+
return {h: 0, s: 0, v: computedV};
427+
}
428+
429+
// Colors other than black-gray-white:
430+
var d = (r === minRGB) ? g-b : ((b === minRGB) ? r-g : b-r);
431+
var h = (r === minRGB) ? 3 : ((b === minRGB) ? 1 : 5);
432+
computedH = 60*(h - d/(maxRGB - minRGB));
433+
computedS = (maxRGB - minRGB)/maxRGB;
434+
computedV = maxRGB;
435+
return {h: computedH, s: computedS, v: computedV};
436+
}

qml/Pin.qml

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
import QtQuick 2.0
2121
import QtQuick.Controls 1.1
2222
import QtQuick.Controls.Styles 1.1
23+
import "Functions.js" as Functions
2324

24-
Rectangle {
25+
Item {
2526
property string defaultFunction: "GPIO" // function when cape is not loded
2627
property var functions: ["GPIO", "I2C", "UART"] // pinmux functions
2728
property var info: ["gpio1_0", "gpio1_0", "i2c1_cs", "uart0_sck"] // info to default function and pinmux functions
@@ -36,30 +37,35 @@ Rectangle {
3637
property var gpioDirections: ["unmodified", "in", "out"]
3738
property string gpioValue: "unmodified" // startup gpio value
3839
property var gpioValues: ["unmodifed", "low", "high"]
39-
property int number: 0 // number of the pin
40+
property int pinNumber: 0 // number of the pin
41+
property int portNumber: 0
42+
property int pruPinNumber: 0
43+
property int kernelPinNumber: 0
4044
property var colorMap: [["GPIO", "red"], ["I2C", "blue"], ["UART", "green"]] // current avtive color map
4145
property alias numberVisible: numberText.visible // visibility of the number
4246
property string description: "Test" // descriptive text for the pin
4347
property bool editable: getEditable() // editability of the pin
4448
property var textInput: leftTextInput.visible? leftTextInput: rightTextInput // currently active text input
4549
property string infoText: getInfoText() // info text for the pin
4650
property int configMode: 0 // active config mode: 0=function, 1=gpio dir, 2=gpio value
47-
property double uneditableOpacitiy: (configMode == 0)?1.0:0.2
51+
property double uneditableOpacitiy: (configMode == 0)?(displayUneditablePins?1.0:0.1):0.2
52+
property bool rightSide: ((main.pinNumber % 2) == 0)
53+
54+
property bool displayUneditablePins: true
55+
4856

4957
signal previewEntered(string type)
5058
signal previewExited()
5159

5260
id: main
5361
width: 100
5462
height: 62
55-
color: getColor()
56-
opacity: (editable || previewActive || (previewEnabled && previewType == ""))?1.0:uneditableOpacitiy
5763

5864
function getEditable() {
5965
switch (configMode) {
6066
case 0: return pinmuxActive
61-
case 1: return (type === "gpio")
62-
case 2: return ((type === "gpio") && (gpioDirection === "out"))
67+
case 1: return ((type === "gpio") || (type === "gpio_pu") || (type === "gpio_pd"))
68+
case 2: return (((type === "gpio") || (type === "gpio_pu") || (type === "gpio_pd")) && (gpioDirection === "out"))
6369
default: return false
6470
}
6571
}
@@ -123,13 +129,44 @@ Rectangle {
123129
return false;
124130
}
125131

132+
ToolTip {
133+
anchors.left: rightSide?parent.right:undefined
134+
anchors.leftMargin: parent.width*0.8
135+
anchors.right: !rightSide?parent.left:undefined
136+
anchors.rightMargin: anchors.leftMargin
137+
width: childrenRect.width + main.width
138+
height: childrenRect.height + main.width
139+
color: "white"
140+
border.color: "black"
141+
142+
visible: (comboBox.hovered || mouseArea.containsMouse) && !(previewEnabled && (previewType == ""))
143+
z: 1000
144+
145+
Text {
146+
x: main.width/2
147+
y: main.width/2
148+
font.pixelSize: rightInfoText.font.pixelSize
149+
text: "<b>P" + portNumber + "_" + pinNumber + "</b><br>" +
150+
infoText + " (" + (pinmuxActive?type:defaultFunction) + ")" +
151+
((kernelPinNumber != 0)?"<br>" + qsTr("Kernel Pin: ") + kernelPinNumber:"") +
152+
((pruPinNumber != 0)?"<br>" + qsTr("PRU Pin; ") + pruPinNumber:"")
153+
}
154+
}
155+
156+
Rectangle {
157+
id: pinRect
158+
anchors.fill: parent
159+
color: getColor()
160+
opacity: (editable || previewActive || (previewEnabled && previewType == ""))?1.0:uneditableOpacitiy
161+
}
162+
126163
Text {
127164
id: numberText
128165
anchors.fill: parent
129-
color: "white"
166+
color: ((pinRect.opacity > 0.5) && (pinRect.color.r+pinRect.color.g+pinRect.color.b) < 2.0)?"white":"black"
130167
horizontalAlignment: Text.AlignHCenter
131168
verticalAlignment: Text.AlignVCenter
132-
text: main.number
169+
text: main.pinNumber
133170
font.bold: true
134171
font.pixelSize: parent.width*0.6
135172
}
@@ -226,11 +263,12 @@ Rectangle {
226263
anchors.verticalCenter: parent.verticalCenter
227264
anchors.left: parent.right
228265
anchors.leftMargin: parent.width * 0.8
229-
width: parent.width*6
266+
width: parent.width*8
230267
horizontalAlignment: TextInput.AlignLeft
231268
font.pixelSize: parent.width*0.9
232-
visible: !previewActive && ((main.number % 2) == 0)
269+
visible: !previewActive && main.rightSide
233270
readOnly: !main.editable
271+
selectByMouse: true
234272

235273
MouseArea {
236274
anchors.fill: parent
@@ -261,20 +299,21 @@ Rectangle {
261299
width: rightTextInput.width
262300
horizontalAlignment: rightTextInput.horizontalAlignment
263301
font: rightTextInput.font
264-
visible: previewActive && ((main.number % 2) == 0)
302+
visible: previewActive && main.rightSide
265303
text: main.infoText
266304
}
267305

268306
TextInput {
269307
id: leftTextInput
270308
anchors.verticalCenter: parent.verticalCenter
271309
anchors.right: parent.left
272-
anchors.rightMargin: parent.width * 0.8
273-
width: parent.width*6
310+
anchors.rightMargin: rightTextInput.anchors.leftMargin
311+
width: rightTextInput.width
274312
horizontalAlignment: TextInput.AlignRight
275-
font.pixelSize: parent.width*0.9
276-
visible: !previewActive && ((main.number % 2) == 1)
313+
font.pixelSize: rightTextInput.font.pixelSize
314+
visible: !previewActive && !main.rightSide
277315
readOnly: !main.editable
316+
selectByMouse: true
278317

279318
MouseArea {
280319
anchors.fill: parent
@@ -305,15 +344,16 @@ Rectangle {
305344
width: leftTextInput.width
306345
horizontalAlignment: leftTextInput.horizontalAlignment
307346
font: leftTextInput.font
308-
visible: previewActive && ((main.number % 2) == 1)
347+
visible: previewActive && !main.rightSide
309348
text: main.infoText
310349
}
311350

312351
MouseArea {
352+
id: mouseArea
313353
anchors.fill: parent
314354
cursorShape: main.editable? Qt.PointingHandCursor: Qt.ArrowCursor
315-
enabled: previewEnabled && (previewType == "")
316-
hoverEnabled: true
355+
enabled: (previewEnabled && (previewType == "")) || !editable
356+
hoverEnabled: enabled
317357
onHoveredChanged: {
318358
if (containsMouse)
319359
{

0 commit comments

Comments
 (0)