Announcement

Collapse
No announcement yet.

No genie report object on USERLED0

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • No genie report object on USERLED0

    EDIT: Problem solved, I replied with my solution...should anyone else be as unobservant as I.

    I have 6 forms, my rtc and 3 sensors are correctly updating the display on the other forms. Everything else is cool. However, now the event handler is reporting every cycle my program runs through. It constantly reads a value of 1, regardless of the userled0 value. What is going on here?

    Code:
    #include <Wire.h>
    #include <DHT.h>
    #include <genieArduino.h>
    #include <math.h>
    
    
    
    #define RESETLINE 4
    #define DHTPIN 2     // Digital pin connected to the DHT sensor
    #define DHT2PIN 3
    #define DHT3PIN 5
    #define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
    #define FANPIN 6
    #define DS3231_I2C_ADDRESS 0x68
    
    bool FANstatus  = false;
    
    double Loadstart;
    double Loadtarget;
    
    int calc;
    double h, t, t2, h2, t3, h3;
    double timestart, timeend, timecur; //NOT REALLY SURE WHAT THIS IS GONNA LOOK LIKE COMING IN
    
    
    Genie genie;
    
    DHT dht(2, DHT22);
    DHT dht2(3, DHT22);
    DHT dht3(5, DHT22);
    
    
    //SETUP =|| //SETUP =|| //SETUP =|| //SETUP =|| //SETUP =|| //SETUP =|| //SETUP =|| //SETUP =||
    //SETUP =|| //SETUP =|| //SETUP =|| //SETUP =|| //SETUP =|| //SETUP =|| //SETUP =|| //SETUP =||
    void setup()
    
    {
      //initialize RTC , communication via I2C (SDA/SCL)
      // setDS3231time();
      //I2C BUS
      Wire.begin();
      Serial.println("i2c initialized");
      //0x68 adress of real time clock mod
      //0x6D   address of relay
    
      //intiailize serial port for debugging purposes
      Serial.begin(9600); //find where it breakslog channel YAY
      Serial1.begin(9600);
      Serial.println("Serial 1 (to display) initialized");
    
      genie.Begin(Serial1);
      Serial.println("initializing genie connevtion via serial 1 ");
      genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events
      Serial.println("initializing genie event handler");
    
    
      //intiailize temperature/humidity sensors
      dht.begin();
      dht2.begin();
      dht3.begin();
    
      //Send reset signal to cordinate microcontroller and display processor.
      pinMode(RESETLINE, OUTPUT);  // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
      digitalWrite(RESETLINE, 0);  // Reset the Display via D4
      delay(100);
      digitalWrite(RESETLINE, 1);  // unReset the Display via D4
      delay (4900);//let the display start up after the reset (This is important)
    
    };
    
    //main looop   //main looop   //main looop   //main looop   //main looop   //main looop   //main looop
    //main looop   //main looop   //main looop   //main looop   //main looop   //main looop   //main looop
    void loop()
    {      
           genie.ReadObject(GENIE_OBJ_USER_LED, 0);
           genie.DoEvents();
           //didn't want to do this, but I'm trying. I
          //  fancontrol();
            
            
      
    
          displayTime();
          delay(90);
          sensorupdate(t, t3, t3, h, h2, h3);
          delay(90);
         // loadcellupdate();
          delay(90);
    
      
    
    
        delay(2000);
    
        Serial.println("FAN CURRENT STATE:");
        Serial.println(FANstatus);
    
    };
    
    void myGenieEventHandler(void)
    { genieFrame Event;
      genie.DequeueEvent(&Event);
    
     if (Event.reportObject.cmd == GENIE_REPORT_OBJ)
      { Serial.println("object event reported from display");
        if (Event.reportObject.object == 0x13)                 // If the Reported Message was from a User LED
        {
          if (Event.reportObject.index == 0)                                 // If UserLed0
          { //FANstatus = genie.GetEventData(&Event);  
            FANstatus = genie.ReadObject(0x13, 0x1E);
            Serial.println("USERLED0 object event read as:");
            Serial.println(FANstatus);
          //  Serial.println(Genie.GetEventData(&Event));
           // FANstatus = Genie.GetEventData(&Event);
            //fancontrol();// not even going to call this function yet, if I can't get the handler to work
          }
        }
      }
        
      //If the cmd received is from a Reported Event (Events triggered from the Events tab of Workshop4 objects) THE FUCKING DISPLAY CAN'T HANDLE ANY DELAYS IN YOUR CODE WHATSOEVER
    //  if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
    //  { Serial.println("genie event reported");
    //    if (Event.reportObject.object == GENIE_OBJ_4DBUTTON) // If a Winbutton was pressed
    //    {  Serial.println("4dtoggle button deteted");
    //      if (Event.reportObject.index == 7) // If Winbutton #0 was pressed  
    //      {
    //        FANnextSTATE = !FANnextSTATE;
    //        Serial.println("fan control button press deteted");
    
          };
      
    
    
    //end main looop  //end main looop  //end main looop  //end main looop  //end main looop  //end main looop
    //end main looop  //end main looop  //end main looop  //end main looop  //end main looop  //end main looop
    
    
    void loadcellupdate()
    { //IF LOAD CELL MASS <= .10*STARTINGMASS THEN STOP TO CHECK.
    
     // FANnextSTATE = FALSE;
    
    };
    
    void sensorupdate (double h, double t, double t2, double h2, double t3, double h3)
    {
      h = dht.readHumidity(); // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
      t = dht.readTemperature(); // Read temperature as Celsius (the default) // Read temperature as Fahrenheit (isFahrenheit = true)
      h2 = dht2.readHumidity(); // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
      t2 = dht2.readTemperature(); // Read temperature as Celsius (the default) // Read temperature as Fahrenheit (isFahrenheit = true)
      h3 = dht3.readHumidity(); // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
      t3 = dht3.readTemperature(); // Read temperature as Celsius (the default) // Read temperature as Fahrenheit (isFahrenheit = true)
    
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, (double)t * 100);
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 3, (double)h * 100);
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, (double)t2 * 100);
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 4, (double)h2 * 100);
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 2, (double)t3 * 100);
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 5, (double)h3 * 100);
    
    };
    
    
    // Convert normal decimal numbers to binary coded decimal
    byte decToBcd(byte val)
    {
      return ( (val / 10 * 16) + (val % 10) );
    };
    
    
    // Convert binary coded decimal to normal decimal numbers
    byte bcdToDec(byte val)
    {
      return ( (val / 16 * 10) + (val % 16) );
    };
    
    
    
    void setDS3231time()
    {
      // ONLY USE TO RESET TIME
      //  Wire.beginTransmission(DS3231_I2C_ADDRESS);
      //  Wire.write(0); // set next input to start at the seconds register
      //  Wire.write(decToBcd(0)); // set seconds
      //  Wire.write(decToBcd(46)); // set minutes
      //  Wire.write(decToBcd(17)); // set hours
      //  Wire.write(decToBcd(3)); // set day of week (1=Sunday, 7=Saturday)
      //  Wire.write(decToBcd(26)); // set date (1 to 31)
      //  Wire.write(decToBcd(3)); // set month
      //  Wire.write(decToBcd(19)); // set year (0 to 99)
      //  Wire.endTransmission();
    };
    
    
    void readDS3231time(
      byte *second,
      byte *minute,
      byte *hour,
      byte *dayOfWeek,
      byte *dayOfMonth,
      byte *month,
      byte *year)
    {
      Wire.beginTransmission(DS3231_I2C_ADDRESS);
      Wire.write(0); // set DS3231 register pointer to 00h
      Wire.endTransmission();
      Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
      // request seven bytes of data from DS3231 starting from register 00h
      *second = bcdToDec(Wire.read() & 0x7f);
      *minute = bcdToDec(Wire.read());
      *hour = bcdToDec(Wire.read() & 0x3f);
      *dayOfWeek = bcdToDec(Wire.read());
      *dayOfMonth = bcdToDec(Wire.read());
      *month = bcdToDec(Wire.read());
      *year = bcdToDec(Wire.read());
      delay(300);
    
    };
    
    void displayTime()
    {
      byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
      String timestring = "NO TIME";
      String datestring = "NO DATE";
      String daysel = "no day";
      // retrieve data from DS3231
      readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
      timestring = (String(hour, DEC) +  ":" + String(minute, DEC) + ":" + String(second, DEC));
      genie.WriteStr(2, (" " + timestring));
      Serial.println(timestring);
      switch (dayOfWeek) {
        case 1:
          daysel = "Sunday";
          break;
        case 2:
          daysel = "Monday";
          break;
        case 3:
          daysel = "Tuesday";
          break;
        case 4:
          daysel = "Wednesday";
          break;
        case 5:
          daysel = "Thursday";
          break;
        case 6:
          daysel = "Friday";
          break;
        case 7:
          daysel = "Saturday";
          break;
      }
      // Serial.println("Date: ");
      datestring = (daysel +  ", " + String(month, DEC) + "/" + String(dayOfMonth, DEC)  + "/" + String(year, DEC));
      genie.WriteStr(1, datestring);
      delay(300);
      Serial.println(datestring);
    };
    
    void fancontrol()
    {
      if (FANstatus == true )
        {  Serial.println("Writing HIGH to FANPIN.");
           digitalWrite(FANPIN, HIGH); // turn the LED on (HIGH is the voltage level)
      } ;
    
      if (FANstatus == false )
        { Serial.println("Writing LOW to FANPIN.");
          digitalWrite(FANPIN, LOW); // turn the LED on (HIGH is the voltage level)
      } ;
    
    
    };
    Last edited by krisb; 6th April 2019, 04:17 PM. Reason: I solved my problem

  • #2
    Found my error. I was setting the FANstatus = a manual read object command. This is why I was constantly getting reported events, AND the value wasn't changing correctly. If anyone is as dumb as me... change this line

    FANstatus = genie.ReadObject(0x13, 0x1E); //bad.... this doesn't return the value.. it reads the object to the event que ...again

    to this

    FANstatus = genie.GetEventData(&Event); //THIS works.

    Comment

    Working...
    X