Feedback to JS processing

203 views
Skip to first unread message

Garry Doucette

unread,
Nov 8, 2013, 9:16:02 PM11/8/13
to comman...@googlegroups.com
Hi Guys

I'm really enjoying Command Fusion and this is my first post. I have an issue with feedbacks that's got me stumped.

I'm using iViewer v4.0.288 build 288.

I'm trying to have button presses for zones and devices passed onto JS for processing.

I have a list of buttons ZoneList, each button representing a zone. On a sub page called 'Zones' the list properties Header subpage setting is set to 'ZoneList'.

Each button is set to fire a command in my Loopback that sets a variable. For example, the first button is set to the command 'Zone 1 main' which has the 'Command Value' set to activeZone=1.

I've created a feedback 'ActiveZoneLogic' with the regex set to activeZone=(.*) and nothing else, ie, no groups.

I've done exactly the same thing as above for a list of devices except the button fires a command that sets a variable activeDevice to say 'activeDevice=1' and the feedback is called 'ActiveDeviceLogic' and the regex is activeDevice=(.*).

The activeZone and activeDevice variables have been set up in the Token Manager with a value of 0 as default and Persist? is not checked.

In my main.js the userMain function is set as follows:

CF.userMain = function() {
//Watch feedbacks    
    CF.watch(CF.FeedbackMatchedEvent, "Loopback", "ActiveZoneLogic", ZoneLogic);
    CF.watch(CF.FeedbackMatchedEvent, "Loopback", "ActiveDeviceLogic", DeviceLogic);
};

In another script iPadGUI.js I have the two functions:

ZoneLogic = function(feedbackItem,zoneNumber) {
    CF.log("The zone number before regex is: " + zoneNumber)
    zoneNum = zoneNumber.match(/0\=(.*)/);
    CF.log("The zone number after regex is: " + zoneNum[1])
if (zoneNum[1] == 1) {
        CF.setJoins([
            { join:"s10", value:"house80x80.png" },
            { join:"s11", value:"Main" },
            { join:"d1", value:1 },        // show main activities
            { join:"d2", value:0 },        // hide FR activities
            { join:"d3", value:0 },        // hide kitchen activities
            { join:"d4", value:0 },        // hide dining room activities
            { join:"d5", value:0 },        // hide deck activities
            { join:"d6", value:0 }        // hide zones
        ]);
}

snip...

else if (zoneNum[1] == "7") {
        CF.setJoins([
            { join:"s10", value:"Patio_128_128.png" },
            { join:"s11", value:"Deck" },
            { join:"d1", value:0 },        // hide main activities
            { join:"d2", value:0 },        // hide FR activities
            { join:"d3", value:0 },        // hide kitchen activities
            { join:"d4", value:0 },        // hide dining room activities
            { join:"d5", value:1 },        // show deck activities
            { join:"d6", value:0 }        // hide zones
        ]);
}
};

DeviceLogic = function(fbName,deviceNumber) {
        CF.log("device number before regex is " + deviceNumber);
        deviceNum = deviceNumber.match(/0\=(.*)/);
        CF.log("device number after regex is " + deviceNum[1]);
if (deviceNum[1] == "1") {
        CF.setJoin("s14", "WatchTV_280x80.png");
        CF.setJoin("s15", "TV");
}

snip....


else if (deviceNum[1] == "10") {
        CF.setJoin("s14", "voicemail60x60.png");
        CF.setJoin("s15", "Voicemail");
}
};

So my problem is when I hit the button for Zone 1 and set activeZone=1, both the CF.watch functions in my CF.userMain fire causing the DeviceLogic function to also run setting joins 14 and 15 which is not what I want to happen.

Here's the log...


14:25:12> SCRIPT: The zone number before regex is: 0=1
14:25:12> SCRIPT: The zone number after regex is: 1
14:25:12> Loopback matched feedback ActiveZoneLogic
14:25:12> SCRIPT: device number before regex is 0=1
14:25:12> SCRIPT: device number after regex is 1
14:25:12> Loopback matched feedback ActiveDeviceLogic
14:25:12> s10 = house80x80.png
14:25:12> s11 = Main
14:25:12> d1 = 1
14:25:12> d2 = 0
14:25:12> d3 = 0
14:25:12> d4 = 0
14:25:12> d5 = 0
14:25:12> d6 = 0
14:25:12> s14 = WatchTV_280x80.png
14:25:12> s15 = TV

The "Loopback matched feedback ActiveDeviceLogic" shouldn't be happening. I know I'm doing something wrong but I just can't see it.

Any suggestions or guidance would be most appreciated!

Garry

Jarrod Bell

unread,
Nov 8, 2013, 10:26:58 PM11/8/13
to comman...@googlegroups.com
My first thought is maybe try making the regex more strict, eg:
activeDevice=(\d+)
activeZone=(\d+)

You could even remove the + from each if there is always going to be less than 10 (ie. always one digit).

The reason I would try this is to ensure the (.*) in your regex isn't being too greedy and for some reason allowing a capture that you didn't intend.

Otherwise, I cannot see anything obviously wrong, so please do send the entire project archive (just zip the folder) to support at commandfusion dot com

Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Barry Gordon

unread,
Nov 8, 2013, 11:46:23 PM11/8/13
to comman...@googlegroups.com

If I understand what you are trying to do  correctly, I do not understand why you are using a regex and feedback at all. I have many similar instances as you have but handle them directly with a call to the JS function.

 

On the action for the button in the list I directly call a JS function presenting enough information in the arguments I pass on the call to allow the function to operate. One of the things you would pass is germane to which button if there are more than one button in a list item relating to different process (perhaps 2 buttons, one for zone and one for  device), the list index at which that button is located.  For example the zone number might be related to the list index. i.e the button at list index 0 is for zone 1, the button at list index 1 is for zone 2, and in general the button for list index n is for zone n+1,

 

ergo on the JS action for a button you might have the call to the zoneLogic function as

                 zonelogic(listIndex);

 

the zoneLogic function  might then look like:

 

ZoneLogic = function(zoneNum) { // zoneNum is the list index which is 1 less than the zone number and is an integer
    CF.log("The zone is: " + (zoneNum+1))

    switch (zoneNum)

    { case 0:   //  the list index is 0 so the zone number is 1

        CF.setJoins([
            { join:"s10", value:"house80x80.png" },
            { join:"s11", value:"Main" },
            { join:"d1", value:1 },        // show main activities
            { join:"d2", value:0 },        // hide FR activities
            { join:"d3", value:0 },        // hide kitchen activities
            { join:"d4", value:0 },        // hide dining room activities
            { join:"d5", value:0 },        // hide deck activities
            { join:"d6", value:0 }        // hide zones
        ]);

            return;

       case 1:    //  the list index is 1 so the zone number is 2

            whatever code is needed for zone 2

            return;

            .

            .

            .

       case 6:    //  the list index is 6 so the zone number is 7

            whatever code is needed for zone 7

            return;

    };

};

 

 

 

 

 

 

if (zoneNum[1] == 1) {
        CF.setJoins([
            { join:"s10", value:"house80x80.png" },
            { join:"s11", value:"Main" },
            { join:"d1", value:1 },        // show main activities
            { join:"d2", value:0 },        // hide FR activities
            { join:"d3", value:0 },        // hide kitchen activities
            { join:"d4", value:0 },        // hide dining room activities
            { join:"d5", value:0 },        // hide deck activities
            { join:"d6", value:0 }        // hide zones
        ]);
}

snip...

 

I suspect this might be more efficient than doing the watch, and the feedback

--

Garry Doucette

unread,
Nov 9, 2013, 3:56:26 PM11/9/13
to comman...@googlegroups.com
Jarrod and Barry

I appreciate you taking the time.

One thing I have learned very well so far about Command Fusion is that there can be many different ways to accomplish the same thing.

You've given me some more ideas to push me along the learning curve.

Thanks

Garry
Reply all
Reply to author
Forward
0 new messages