Ejemplo n.º 1
0
        /// <summary>
        /// Constructor, initalizes all the needed elements
        /// </summary>
        /// <param name="display"></param>
        /// <param name="button"></param>
        /// <param name="joystick"></param>
        public ModeSelection(Gadgeteer.Modules.Module.DisplayModule display, Gadgeteer.Modules.GHIElectronics.Joystick joystick, EventHandler handler)
        {
            this.display = display;
            this.joystick = joystick;
            this.pos_joystick = new Gadgeteer.Modules.GHIElectronics.Joystick.Position();
            display.SimpleGraphics.Clear();

            inputFinished = handler;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Default constructor for MasterMind class. Initializes variables
        /// </summary>
        /// <param name="display">display module</param>
        /// <param name="joystick">joystick module</param>
        /// <param name="button">button module</param>
        /// <param name="led">led module</param>
        public MasterMind(Gadgeteer.Modules.Module.DisplayModule display, Gadgeteer.Modules.GHIElectronics.Joystick joystick,
            Gadgeteer.Modules.GHIElectronics.Button button, Gadgeteer.Modules.GHIElectronics.MulticolorLED led)
        {
            //storing device referenceslocally ingame logic.
            this.display = display;
            this.joystick = joystick;
            this.led = led;
            this.button = button;

            //game restart button
            button.ButtonPressed += button_ButtonPressed;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// constructor - set up the input
 /// </summary>
 /// <param name="x"> x coordinate where to draw the input mask</param>
 /// <param name="y">y coordinate where to draw the input mask</param>
 /// <param name="radius"> how big the input mask should be</param>
 /// <param name="display"> display module</param>
 /// <param name="joystick"> joystick module</param>
 /// <param name="finishedHandler"> event handler which indicates if an input was finished</param>
 public ColorCodeInput(int x, int y, int radius, Gadgeteer.Modules.Module.DisplayModule display, Gadgeteer.Modules.GHIElectronics.Joystick joystick, EventHandler finishedHandler)
 {
     this.pos_x = x;
     this.pos_y = y;
     this.radius = radius;
     this.display = display;
     this.joystick = joystick;
     this.pos_code = 0;
     this.finishedHandler = finishedHandler;
     this.code = new ColorCode();
     this.view = new ColorCodeView(pos_x,pos_y,radius,display,code);
     this.pos_joystick = new Joystick.Position();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// constructor, gets all peripherals needed for the UI
        /// </summary>
        /// <param name="inputFinished">an EventHandler which will be called when the input in a round is completed successfully</param>
        public GameView(MasterMind masterMind, Gadgeteer.Modules.Module.DisplayModule display, Gadgeteer.Modules.GHIElectronics.Joystick joystick, 
            Gadgeteer.Modules.GHIElectronics.MulticolorLED led, EventHandler inputFinished)
        {
            this.masterMind = masterMind;

            //store Gadgeteer device references for later use
            this.display = display;
            this.joystick = joystick;
            this.led = led;

            //event handler which will be invoked when the user finished his input..we just pass this to the current ColorCodeInput
            this.inputFinished = inputFinished;

            //start with the first round!
            display.SimpleGraphics.Clear();
            display.SimpleGraphics.DisplayText("Mastermind - good luck!", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.White, CODE_X_POS, WELCOME_Y_POS);
            createColorCodeInput(0);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a HomeOS device library instance supporting assocation with HomeOS hubs, using wifi, serial or storage devices (USB host, SD card)
        /// to transfer credentials.
        /// </summary>
        /// <param name="manufacturer">A string identifying the manufacturer, e.g. "Microsoft Research"</param>
        /// <param name="deviceTypeIdentifier">A string identifying the device type, e.g. "MoistureSensor"</param>
        /// <param name="setupWifiAuthCode">The authentication code used for wifi setup networks to prove that the caller has physical access to this device (it should be written on the device)</param>
        /// <param name="wifi">The instance of the wifi module.  Cannot be null.</param>
        /// <param name="led">The instance of an LED module to show the wifi connection state.  Can be null.  The LED will not be controlled if the doNotControlLed delegate returns true.</param>
        /// <param name="display">The instance of a display module to show the wifi connection state.  Can be null.  The display will not be controlled if the doNotControlLed delegate returns true.</param>
        /// <param name="serialPort">The serial port to use to receive wifi network credentials.  Can be null.</param>
        /// <param name="doNotManageWifi">A delegate specifying when NOT to manage wifi, e.g. allowing the program to stop wifi scanning and assocation for a time.  Can be null.</param>
        /// <param name="doNotControlScreen">A delegate specifying when NOT to control the screen (i.e. if your program wants to control the screen)</param>
        /// <param name="doNotControlLed">A delegate specifying when NOT to control the led (i.e. if your program wants to control the led)</param>
        /// <param name="enableWifiSetupNetworks">Enable wifi-based discovery using "setup" network</param>
        /// <param name="doUDPDiscovery">Listens and responds to UDP packets from HomeOS trying to discover this device, over both "setup" and home networks.  If this is off, the device will still beacon periodically over UDP.  Normally leave it on.</param>
        public HomeOSGadgeteerDevice(
            string manufacturer,
            string deviceTypeIdentifier,
            string setupWifiAuthCode,

            GTM.GHIElectronics.WiFi_RS21 wifi,
            GTM.GHIElectronics.MulticolorLed led = null,
            GTM.Module.DisplayModule display     = null,
            string serialPort               = null,
            BoolDelegate doNotManageWifi    = null,
            BoolDelegate doNotControlScreen = null,
            BoolDelegate doNotControlLed    = null,

            bool enableWifiSetupNetworks = true,
            bool doUDPDiscovery          = true

            )
        {
            if (manufacturer == null)
            {
                throw new ArgumentNullException("manufacturer");
            }
            if (deviceTypeIdentifier == null)
            {
                throw new ArgumentNullException("deviceTypeIdentifier");
            }
            if (setupWifiAuthCode == null)
            {
                throw new ArgumentNullException("setupAuthCode");
            }
            if (wifi == null)
            {
                throw new ArgumentNullException("wifi");
            }
            this.wifi    = wifi;
            this.led     = led;
            this.display = display;
            if (display != null)
            {
                display.SimpleGraphics.AutoRedraw = false;
            }

            if (serialPort != null)
            {
                new Thread(() => SerialReadThread(serialPort)).Start();
            }

            this.SkipWifiTimer      = doNotManageWifi ?? defaultFalse;
            this.DoNotControlScreen = doNotControlScreen ?? defaultFalse;
            this.DoNotControlLed    = doNotControlLed ?? defaultFalse;

            this.DoUDPDiscovery     = doUDPDiscovery;
            EnableWifiSetupNetworks = enableWifiSetupNetworks;
            this.SetupAuthCode      = setupWifiAuthCode;
            this.TypeIdentifier     = deviceTypeIdentifier;
            this.Manufacturer       = manufacturer;

            wifi.Interface.NetworkInterface.EnableDhcp();
            wifi.Interface.WirelessConnectivityChanged += Interface_WirelessConnectivityChanged;
            wifi.Interface.NetworkAddressChanged       += Interface_NetworkAddressChanged;

            if (!wifi.Interface.IsOpen)
            {
                wifi.Interface.Open();
            }
            NetworkInterfaceExtension.AssignNetworkingStackTo(wifi.Interface);


            Thread thread = new Thread(DiscoveryThread);

            thread.Start();

            LoadData();

            wifiTimer       = new GT.Timer(WifiScanPeriod);
            wifiTimer.Tick += wifiTimer_Tick;
            wifiTimer.Start();

            WebServer.SetupWebEvent(webPath).WebEventReceived += new WebEvent.ReceivedWebEventHandler(CredentialsWebEventReceived);

            SetLed();
            SetScreen();

            GT.Program.BeginInvoke(new VoidDelegate(() => wifiTimer_Tick(wifiTimer)), null);
        }
        /// <summary>
        /// Creates a HomeOS device library instance supporting assocation with HomeOS hubs, using wifi, serial or storage devices (USB host, SD card) 
        /// to transfer credentials.   
        /// </summary>
        /// <param name="manufacturer">A string identifying the manufacturer, e.g. "Microsoft Research"</param>
        /// <param name="deviceTypeIdentifier">A string identifying the device type, e.g. "MoistureSensor"</param>
        /// <param name="setupWifiAuthCode">The authentication code used for wifi setup networks to prove that the caller has physical access to this device (it should be written on the device)</param>
        /// <param name="wifi">The instance of the wifi module.  Cannot be null.</param>
        /// <param name="led">The instance of an LED module to show the wifi connection state.  Can be null.  The LED will not be controlled if the doNotControlLed delegate returns true.</param>
        /// <param name="display">The instance of a display module to show the wifi connection state.  Can be null.  The display will not be controlled if the doNotControlLed delegate returns true.</param>
        /// <param name="serialPort">The serial port to use to receive wifi network credentials.  Can be null.</param>
        /// <param name="doNotManageWifi">A delegate specifying when NOT to manage wifi, e.g. allowing the program to stop wifi scanning and assocation for a time.  Can be null.</param>
        /// <param name="doNotControlScreen">A delegate specifying when NOT to control the screen (i.e. if your program wants to control the screen)</param>
        /// <param name="doNotControlLed">A delegate specifying when NOT to control the led (i.e. if your program wants to control the led)</param>
        /// <param name="enableWifiSetupNetworks">Enable wifi-based discovery using "setup" network</param>
        /// <param name="doUDPDiscovery">Listens and responds to UDP packets from HomeOS trying to discover this device, over both "setup" and home networks.  If this is off, the device will still beacon periodically over UDP.  Normally leave it on.</param>
        public HomeOSGadgeteerDevice(
            string manufacturer,
            string deviceTypeIdentifier,
            string setupWifiAuthCode,

            GTM.GHIElectronics.WiFi_RS21 wifi,
            GTM.GHIElectronics.MulticolorLed led = null,
            GTM.Module.DisplayModule display = null,
            string serialPort = null,
            BoolDelegate doNotManageWifi = null,
            BoolDelegate doNotControlScreen = null,
            BoolDelegate doNotControlLed = null,

            bool enableWifiSetupNetworks = true,
            bool doUDPDiscovery = true

            )
        {
            if (manufacturer == null) throw new ArgumentNullException("manufacturer");
            if (deviceTypeIdentifier == null) throw new ArgumentNullException("deviceTypeIdentifier");
            if (setupWifiAuthCode == null) throw new ArgumentNullException("setupAuthCode");
            if (wifi == null) throw new ArgumentNullException("wifi");
            this.wifi = wifi;
            this.led = led;
            this.display = display;
            if (display != null)
            {
                display.SimpleGraphics.AutoRedraw = false;
            }

            if (serialPort != null)
            {
                new Thread(() => SerialReadThread(serialPort)).Start();
            }

            this.SkipWifiTimer = doNotManageWifi ?? defaultFalse;
            this.DoNotControlScreen = doNotControlScreen ?? defaultFalse;
            this.DoNotControlLed = doNotControlLed ?? defaultFalse;

            this.DoUDPDiscovery = doUDPDiscovery;
            EnableWifiSetupNetworks = enableWifiSetupNetworks;
            this.SetupAuthCode = setupWifiAuthCode;
            this.TypeIdentifier = deviceTypeIdentifier;
            this.Manufacturer = manufacturer;

            wifi.Interface.NetworkInterface.EnableDhcp();
            wifi.Interface.WirelessConnectivityChanged += Interface_WirelessConnectivityChanged;
            wifi.Interface.NetworkAddressChanged += Interface_NetworkAddressChanged;

            if (!wifi.Interface.IsOpen)
                wifi.Interface.Open();
            NetworkInterfaceExtension.AssignNetworkingStackTo(wifi.Interface);


            Thread thread = new Thread(DiscoveryThread);
            thread.Start();

            LoadData();

            wifiTimer = new GT.Timer(WifiScanPeriod);
            wifiTimer.Tick += wifiTimer_Tick;
            wifiTimer.Start();

            WebServer.SetupWebEvent(webPath).WebEventReceived += new WebEvent.ReceivedWebEventHandler(CredentialsWebEventReceived);

            SetLed();
            SetScreen();

            GT.Program.BeginInvoke(new VoidDelegate(() => wifiTimer_Tick(wifiTimer)), null);
        }