Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to add extra arguments #5

Open
Ws2812B opened this issue Sep 2, 2017 · 0 comments
Open

Failing to add extra arguments #5

Ws2812B opened this issue Sep 2, 2017 · 0 comments

Comments

@Ws2812B
Copy link

Ws2812B commented Sep 2, 2017

I feel kind of stupid of asking this because it's probably very easy to add extra arguments and i'm just to stupid. I just can't figure out, what is wrong with my code.

I tried to add an extra argument to define the delay value of an animation out of my previous issue. So i copied the bool loadRGBValues(ESP8266WebServer &server, uint8_t *rgb) and modified it to THIS:

bool loadDelay(ESP8266WebServer &server, uint8_t d)
  {
    bool valid = false;
      if(server.hasArg("d"))
      {
        int value = server.arg("d").toInt();
        if(value < 0 || value > 25)
        {
          String message = "Illegal value:\n\n";
          message += "\nOnly values 0 to 25 are allowed.";
          server.send(200, "text/plain", message);
          return false;
        }
        d = value;
		
	  }
	  Serial.println(d);
    return true;
  } 

Modifications:
-removed the loop, because only one argument exists
-changed stuff like uin8_t *rgb to uint8_t d
-Added Serial.println(d) because it doesn't work. Later more of this line.
I added this to LedFunction.h.

Then I tried to use this bool like this in the class of the animation:

  virtual bool init(ESP8266WebServer &server)
  {
    if(!loadDelay(server, delval)){
	return false;   }else{  Serial.println(delval); } //later more of the Serial.println
  }

-delval is the variable, i want to be defined by the argument
But the animation doesn't act like delval equals the argument d=something.
This is confirmed by the SerialMonitor.
It shows this:

HTTP server started
5
15

by requesting IP/rainbow2(command of animation)?d=5?fade=500
delval is initialized to 15 in Test.h. That's why it delivers 15. But that just means delval doesn't get changed but bool loadDelay(ESP8266WebServer &server, uint8_t d) is executed because otherwise the 5 wouldn`t show up in the Serial Monitor. But why does delval doesn't change to 5 or the argument in the link?

If I use the bool loadRGBValues(ESP8266WebServer &server, uint8_t *rgb) and use the "r" argument value by using rgb[0] to define delval(variable I want to define by an extra argument) it works.

I just don't understand, why it doesn't work.
Thank you if you read it until this point and know, what I'm doing wrong and can help me.
Thanks in Advance.

The whole relevant Code:

  1. Class of the animation
  2. Part in main sketch
  3. Part in LedFunction.h
-------------------------------------------------1--------------------------------------------------
/*
Released under Creative Commons Attribution 4.0
by bitluni 2016
https://creativecommons.org/licenses/by/4.0/
Attribution means you can use it however you like as long you
mention that it's base on my stuff.
I'll be pleased if you'd do it by sharing http://youtube.com/bitlunislab
*/

#include "LedFunction.h"
#include <Adafruit_NeoPixel.h>

class rainbow2: public LedFunction
{	
  public:
  
  Adafruit_NeoPixel stripp = Adafruit_NeoPixel(77, D4, NEO_GRB + NEO_KHZ800);

	int j = 0;
    uint8_t delval = 15;
	
	uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return stripp.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return stripp.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return stripp.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

  // Returns the Red component of a 32-bit color
    uint8_t Red(uint32_t color)
    {
        return (color >> 16) & 0xFF;
    }
 
    // Returns the Green component of a 32-bit color
    uint8_t Green(uint32_t color)
    {
        return (color >> 8) & 0xFF;
    }
 
    // Returns the Blue component of a 32-bit color
    uint8_t Blue(uint32_t color)
    {
        return color & 0xFF;
    }
	
  rainbow2()
  { 
  }

  virtual bool init(ESP8266WebServer &server)
  {
    if(!loadDelay(server, delval)){
	return false; } else {	Serial.println(delval);	}
  }
  
  virtual void render()
  {
	j++; if(j>256){j=0;}
	delay(delval);
	for(int i = 0; i < state->count; i++) {
      state->setRgb(i, Red(Wheel(((i * 256 / stripp.numPixels()) + j) & 255)),Green(Wheel(((i * 256 / stripp.numPixels()) + j) & 255)),Blue(Wheel(((i * 256 / stripp.numPixels()) + j) & 255)));
	}
  }
};

-------------------------------------------------2---------------------------------------------------------

  server.on("/rainbow2", [](){
    server.send(200, "text/plain", "rainbow2");
    rainbow2 *f = new rainbow2();
    f->init(server);
    checkFadeAndSetLedFunction(f);
  });

-------------------------------------------------3---------------------------------------------------------

  bool loadDelay(ESP8266WebServer &server, uint8_t d)
  {
    bool valid = false;
      if(server.hasArg("d"))
      {
        int value = server.arg("d").toInt();
        if(value < 0 || value > 25)
        {
          String message = "Illegal value:\n\n";
          message += "\nOnly values 0 to 25 are allowed. 0 is off and 255 is 100% lit.";
          server.send(200, "text/plain", message);
          return false;
        }
        d = value;
		
	  }
	  Serial.println(d);
    return true;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant