View Single Post
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, Espaņa
#5
Okay, thanks Fuzzi for your input, with a few glasses of wine and a couple of neatly rolled magical smoking sticks, I have arrived at a place where the code works, it ain't pretty, but hey, for now, this is for personal use

Right, taking some of your advice and code, I came up with this (this is a snippet of a very long single page);

This works, although it's bulky, untidy and repetitive, but my UI now has 40 fully functioning buttons (rectangles)

Code:
            // First row of 10, consists of rectangle, mouse and label
                Row { id: row; anchors.horizontalCenter: parent.horizontalCenter; spacing: 45
                    Rectangle { id: brightUp; width: 80; height: 80; radius: 40; color: "white"
                    MouseArea {
                        id: mouse
                        anchors.fill: brightUp
                        onClicked: {
                            getData()
                            function getData(url) {
                                var xhttp = new XMLHttpRequest()
                                xhttp.onreadystatechange = function(myxhttp) {
                                    if (xhttp.readyState == 4 && xhttp.status == 200) {
                                        led.opacity = 1.0
                                        timer.start()
                                    }
                                    return function() {
                                        if(myxhttp.readyState === 4) callback(myxhttp)
                                    }
                                }
                                xhttp.open("GET", "http://192.168.4.1/ir?code=16726725")
                                xhttp.send('')
                            }
                        }
                        // Stop/start the repeater
                        onPressed: {
                            console.log("Repeat triggered")
                            pressTimer.start()
                    }
                    // This timer is purely to time the flashing of a virtual LED on my app's UI
                    Timer {
                        id: timer
                        interval: 50
                        repeat: true
                        running: false
                        onTriggered: {
                            led.opacity = 0.0
                        }
                    } // This timer is for repeating a held mouse click
                    Timer {
                        id: pressTimer
                        interval: 200
                        running: mouse.pressed
                        repeat: true
                        onTriggered: {
                            timer.start()
                            mouse.clicked(mouse)
                            console.log("Repeat started")
                        }
                    }

                    // Other stuff . . .
Now, it is time to look at slimming down this 1000 line page into modules/other files.

I also note that there is a github page for RGB IR WIFI control, but it meant uploading new unknown code to my NodeMCU and for now, I'm happy with the way my set up works, albeit, as previously stated; bulky, untidy....in dire need or refinement, but for who?, it works!

Thanks for your input Fuzzillogic, much appreciated.

Regards,
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..

Last edited by Markkyboy; 2019-08-18 at 16:57.
 

The Following 4 Users Say Thank You to Markkyboy For This Useful Post: