Search Results

Search found 2 results on 1 pages for 'methodman'.

Page 1/1 | 1 

  • Javascript (using jQuery) in a large Project... organization, passing data, private method, etc.

    - by gaoshan88
    I'm working on a large project that is organized like so: Multiple javascript files are included as needed and most code is wrapped in anonymous functions... // wutang.js //Included Files Go Here // Public stuff var MethodMan; // Private stuff (function() { var someVar1; MethodMan = function(){...}; var APrivateMethod = function(){...}; $(function(){ //jquery page load stuff here $('#meh').click(APrivateMethod); }); })(); I'm wondering about a few things here. Assuming that there are a number of these files included on a page, what has access to what and what is the best way to pass data between the files? For example, I assume that MethodMan() can be accessed by anything on any included page. It is public, yes? var someVar1 is only accessible to the methods inside that particular anonymous function and nowhere else, yes? Also true of var APrivateMethod(), yes? What if I want APrivateMethod() to make something available to some other method in a different anonymous wrapped method in a different included page. What's the best way to pass data between these private, anonymous functions on different included pages? Do I simply have to make whatever I want to use between them public? How about if I want to minimize global variables? What about the following: var PootyTang = function(){ someVar1 = $('#someid').text(); //some stuff }; and in another included file used by that same page I have: var TangyPoot = function(){ someVar1 = $('#someid').text(); //some completely different stuff }; What's the best way to share the value of someVar1 across these anonymous (they are wrapped as the first example) functions?

    Read the article

  • Arduino - AdHoc Network Setup

    - by methodMan
    I`m currently working with an arduino trying to build an adhoc network to which a device can connect to and send web request to. The problem I am currently having is that I can only set up one connection and then when that connection is terminated (client.stop()) all subsequent connections are not picked up by the server, even a curl command just sits there spinning. The first connection I start when I reset the server works fine and I am able to talk to the server; but after that, the arduino can no longer find new clients (even though it's trying with the library given). I`m using the sparkfun library for the wifly shield cloned from github, along with an Arduino Uno. My current code is based off their default example 'WiFly_AdHoc_Example' but I had to remove a few things to get the network to start up which might be the cause of this problem. Here is the .ino file that I am running. #include <SPI.h> #include <WiFly.h> //#include <SoftwareSerial.h> //SoftwareSerial mySerial( 5, 4); //Part from example not used(see below) WiFlyServer server(80); void setup() { Serial.begin(9600); //The code below is from the example but when I run it the WiFly will hang // on Wifly.begin(). Without it the WiFly starts up fine but only works for // one request. //mySerial.begin(9600); //WiFly.setUart(&mySerial); // Tell the WiFly library that we are not //using the SPIUart Serial.println("**************Starting WiFly**************"); // Enable Adhoc mod WiFly.begin(true); Serial.println("WiFly started, creating network."); if (!WiFly.createAdHocNetwork("wifly")) { Serial.print("Failed to create ad hoc network."); while (1) { // Hang on failure. } } Serial.println("Network created"); Serial.print("IP: "); Serial.println(WiFly.ip()); Serial.println("Starting Server..."); server.begin(); Serial.print("Server started, waiting for client."); } void loop() { delay(200); WiFlyClient client = server.available(); if (client) { Serial.println("Client Found."); // a string to store received commands String current_command = ""; while (client.connected()) { if (client.available()) { //Gets a character from the sent request. char c = client.read(); if (c=='#' || c=='\n') //End of extraneous output { current_command = ""; } else if(c!= '\n') { current_command+=c; } if (current_command== "get") { // output the value of each analog input pin for (int i = 0; i < 6; i++) { client.print("analog input "); client.print(i); client.print(" is "); client.print(analogRead(i)); client.println("<br />"); } } else if(current_command== "hello") { client.println("Hello there, I'm still here."); } else if (current_command== "quit") { client.println("Goodbye..."); client.stop(); current_command == ""; break; } else if (current_command == "*OPEN*") { current_command == ""; } } } // give the web browser time to receive the data delay(200); // close the connection client.stop(); } } If anyone understands this better then I (I`m new to arduino) please leave some helpful comments. Or just help me out on getting this little web server up and running so that I can hit it with more then one request. If there is any other helpful information I can provide please let me know. Thanks for reading and hope you can help. EDIT: Using telnet I can successfully connect (the first time) and send commands to the arduino including one to terminate the connection (calls the client.stop() method). But when I try to reconnect though telnet, it says the connection was successful but on the arduino it's still looping thinking the client is still false. WHAT??? I know right, I'm getting mixed messages from telnet vs arduino. None of the commands work obviously since the ardunio is still looping waiting for a client that evaluates to true. I'm gonna take a look at WiFlyServer from the library I imported and see if I can dig up the problem because somehow that server.available() method isn't finding new clients. Noticing a lot of TODO's in the library code.... EDIT: So I found the reason for the problem, it was in WiFlyServer.cpp file from the sparkfun library. The code that was causing the reconnect issue was infact in the server.availible() method. Right at the top of the method, there is a check: // TODO: Ensure no active non-server client connection. if (!WiFly.serverConnectionActive) { activeClient._port = 0; } For some reason when I comment this out, I can reconnect fine and everything works as it should. I will now dive into the library and see if I can fix this, I'm not exactly sure what this is doing but it gets called when the server connection is not active and is somehow blocking subsequent connections. Does anyone have any ideas how I might get to the root of this problem without using this commenting hack? Please help, no-one has commented or answered yet! Don't you want to join in on the fun???

    Read the article

1