Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: noob question: Using hardware in the puremvc Air application (best practice?)  (Read 6821 times)
ortenheim
Newbie
*
Posts: 1


View Profile Email
« on: February 25, 2010, 05:52:59 »

Hi, i am new to PureMVC but love it already! however i suspect my implementation isnt the greatest.

I am trying to implement hardware into the application and wonder what is the best practice for this? I want to connect the event of a card to specific mediators. The problem is phidgets uses an implementation with eventlisteners that are global, thus i need to access into these and try to find where i am in the application at the moment and thus accessing different methods as follows. Also i feel i am getting more and more away from puremvc implementation.

I have phidget hardware and its implementation in my looks like this:

  • i have put the connection to phidgets as a helper
  • phidget is created in the applicationfacade
  • when tag is found  it traces the current index in my viewstack
  • a phidget manager method (org.pmc.views.managers) recieves the current viewstack and then runs a method (getting data or other behavior)
:
package org.pmvc.helpers
{
import com.phidgets.*;
import com.phidgets.events.*;

import mx.core.Application;

import org.pmvc.view.MyViewMediator;

public class PhidgetHelper {

private var phid:PhidgetRFID;

public function PhidgetHelper(){

phid = new PhidgetRFID();

phid.addEventListener(PhidgetEvent.CONNECT, onConnect);
phid.addEventListener(PhidgetEvent.DISCONNECT, onDisconnect);
phid.addEventListener(PhidgetEvent.DETACH, onDetach);
phid.addEventListener(PhidgetEvent.ATTACH, onAttach);
phid.addEventListener(PhidgetErrorEvent.ERROR, onError);
phid.addEventListener(PhidgetDataEvent.TAG, onTag);
phid.addEventListener(PhidgetDataEvent.TAG_LOST, onTagLoss);
phid.addEventListener(PhidgetDataEvent.OUTPUT_CHANGE, onOutputChange);

phid.open("localhost", 5001);
}

private function onError(evt:PhidgetErrorEvent):void {
trace(evt);
trace("version = " + phid.Version);
}
private function onAttach(evt:PhidgetEvent):void{
trace(evt);
phid.Antenna = true;
}
private function onDetach(evt:PhidgetEvent):void{
trace(evt);
}
private function onConnect(evt:PhidgetEvent):void{
trace(evt);
}
private function onDisconnect(evt:PhidgetEvent):void{
trace(evt);
}
private function onTag(evt:PhidgetDataEvent):void{
trace(evt);
phid.LED = true;
var iStack:Number = Application.application.vwStack.selectedIndex.toString();
trace("current state: " + iStack);

switch(iStack)
{
case(0):
break;
case(1):
trace("phidget active on state 1");
                                        //phidgetmanager implementation 1
break;
case(2):
trace("phidget active on state 2");
                                        //phidgetmanager implementation 2
break;
}

}
private function onTagLoss(evt:PhidgetDataEvent):void{
trace(evt);
phid.LED = false;
}
private function onOutputChange(evt:PhidgetDataEvent):void{
trace(evt);
}
}
}

How can i build this using best practice? (some events from phidgets need to be global and others (ontag, ontagloss) need to be specific for each mediator.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: February 25, 2010, 10:47:27 »

I think I'd put the connection to Phidgets in a Proxy. There I would listen for whatever events it sends, globally or otherwise and dispatch them as notifications along with the information they contain. Now it doesn't matter if an event is 'global', it's all been normalized and your mediators just show interest in the notifications they need to hear.

-=Cliff>
Logged
Pages: [1]
Print