×

INDI Library v2.0.6 is Released (02 Feb 2024)

Bi-monthly release with minor bug fixes and improvements

help with new rain sensor driver

  • Posts: 2247
  • Thank you received: 223
I have a fully working RG11 rain sensor driver at github.com/Trigger-broom-289/indi-RG11-Rain-Sensor
I would like to simplify it, ie: not linked to Weather and add better snooping for my observatory roof box.

Something like the Indi tutorial 5 github.com/indilib/indi/tree/master/libi...amples/tutorial_five

What I can't get to figure out is how to translate the following par of code:
IPState IndiRG11RainSensor::updateWeather()
{
      FILE *in;
      char buff[8];
      if (!(in = popen("gpio read 6", "r")))
      {
        DEBUG(INDI::Logger::DBG_ERROR, "Unable to read GPIO.");
        IPS_ALERT;
      }
 
      fgets(buff, sizeof(buff), in);
      pclose(in);
 
	DEBUGF(INDI::Logger::DBG_SESSION, "GPIO buffer (%s)", buff);
 
        if (atoi(buff) == 0)
            setParameterValue("WEATHER_RAIN", 0);
        else
            setParameterValue("WEATHER_RAIN", 1);
 
    return IPS_OK;
}

to the section "Client is asking us to update a switch" in github.com/indilib/indi/blob/master/libi...ive/raindetector.cpp
ie: there will no longer be the switch on/off like in the tutorial.
I cannot get my head around. Anyone kind enough to point me in the right direction please?
5 years 9 months ago #26820

Please Log in or Create an account to join the conversation.

  • Posts: 2247
  • Thank you received: 223
in tutorial_five/raindetector.cpp
line 100 ~ 103 I see where the switches are being declared:
IUFillSwitch(&RainS[0], "On", "", ISS_OFF);
    IUFillSwitch(&RainS[1], "Off", "", ISS_OFF);
    IUFillSwitchVector(&RainSP, RainS, 2, getDeviceName(), "Control Rain", "", MAIN_CONTROL_TAB, IP_RW, ISR_1OFMANY, 0,
                       IPS_IDLE);

I can remove these 3 lines and the option ON/OFF to trigger a rain condition is no longer available. That's fine.

What I'm struggling with is from line 132.
5 years 9 months ago #26822

Please Log in or Create an account to join the conversation.

  • Posts: 2247
  • Thank you received: 223
I'm going to try to adapt the code from the odroid roof for it.
/**
 * Get the state of the full open limit switch. This function will also switch off the motors as a safety override.
 **/
bool OdroidRoof::getFullOpenedLimitSwitch()
{
  if(wiringPiSetup() == -1)
  printf("ERROR");
 
    DEBUG(INDI::Logger::DBG_SESSION, "Checking fully open switch");
    if (digitalRead(4) != 0) {
        fullOpenLimitSwitch = ISS_ON;
	SetParked(false);
        return true;
    }
    else {
        DEBUG(INDI::Logger::DBG_SESSION, "Fully open switch OFF");
        return false;
    }
}
5 years 9 months ago #26824

Please Log in or Create an account to join the conversation.

Time to create page: 0.216 seconds