Ejemplo n.º 1
0
void hardware::initializePins()
{
    setBatteryOutput(false);
    setFan(false);
    setBuzzer(0);
    setBalancer(0);

    IO::pinMode(BACKLIGHT_PIN, OUTPUT);
    IO::pinMode(OUTPUT_DISABLE_PIN, OUTPUT);
    IO::pinMode(FAN_PIN, OUTPUT);
    IO::pinMode(BUZZER_PIN, OUTPUT);

    IO::pinMode(BALANCER1_LOAD_PIN, OUTPUT);
    IO::pinMode(BALANCER2_LOAD_PIN, OUTPUT);
    IO::pinMode(BALANCER3_LOAD_PIN, OUTPUT);
    IO::pinMode(BALANCER4_LOAD_PIN, OUTPUT);
    IO::pinMode(BALANCER5_LOAD_PIN, OUTPUT);
    IO::pinMode(BALANCER6_LOAD_PIN, OUTPUT);
#if MAX_BANANCE_CELLS > 6
    IO::pinMode(BALANCER7_LOAD_PIN, OUTPUT);
    IO::pinMode(BALANCER8_LOAD_PIN, OUTPUT);
#endif

#ifdef ENABLE_BALANCER_PWR
    IO::pinMode(BALANCER_PWR_ENABLE_PIN, OUTPUT);
#endif

    IO::pinMode(SMPS_VALUE_PIN, OUTPUT);
    IO::pinMode(SMPS_DISABLE_PIN, OUTPUT);
    IO::pinMode(DISCHARGE_VALUE_PIN, OUTPUT);
    IO::pinMode(DISCHARGE_DISABLE_PIN, OUTPUT);
}
Ejemplo n.º 2
0
void hardware::init()
{
    analogReference(EXTERNAL);
    pinMode(OUTPUT_DISABLE_PIN, OUTPUT);

    pinMode(DISCHARGE_VALUE_PIN, OUTPUT);
    pinMode(DISCHARGE_DISABLE_PIN, OUTPUT);

    pinMode(SMPS_VALUE0_PIN, OUTPUT);
    pinMode(SMPS_VALUE1_PIN, OUTPUT);
    pinMode(SMPS_DISABLE_PIN, OUTPUT);

    pinMode(BUZZER_PIN, OUTPUT);

    pinMode(BALANCER1_LOAD_PIN, OUTPUT);
    pinMode(BALANCER2_LOAD_PIN, OUTPUT);
    pinMode(BALANCER3_LOAD_PIN, OUTPUT);
    pinMode(BALANCER4_LOAD_PIN, OUTPUT);
    pinMode(BALANCER5_LOAD_PIN, OUTPUT);
    pinMode(BALANCER6_LOAD_PIN, OUTPUT);

    pinMode(MUX_ADR0_PIN, OUTPUT);
    pinMode(MUX_ADR1_PIN, OUTPUT);
    pinMode(MUX_ADR2_PIN, OUTPUT);
    pinMode(MUX0_Z_D_PIN, INPUT);

    setBatteryOutput(false);
    setFan(false);
    setBuzzer(0);

    lcd.begin(LCD_COLUMNS, LCD_LINES);
    timer.init();

    TimerOne::initialize();
}
AirTerminalSingleDuctParallelPIUReheat::AirTerminalSingleDuctParallelPIUReheat( const Model& model,
                                                                                Schedule & schedule,
                                                                                HVACComponent & fan,
                                                                                HVACComponent & reheatCoil )
  : StraightComponent(AirTerminalSingleDuctParallelPIUReheat::iddObjectType(),model)
{
  OS_ASSERT(getImpl<detail::AirTerminalSingleDuctParallelPIUReheat_Impl>());

  bool test = setAvailabilitySchedule(schedule);
  if (!test) {
    remove();
    LOG_AND_THROW("Could not construct " << briefDescription() << ", because could not set its "
        << "availability schedule to " << schedule.briefDescription() << ".");
  }

  setFan(fan);

  setReheatCoil(reheatCoil);

  autosizeMaximumHotWaterorSteamFlowRate();

  setMinimumHotWaterorSteamFlowRate(0.0);

  setConvergenceTolerance(0.001);

  autosizeMaximumPrimaryAirFlowRate();

  autosizeMaximumSecondaryAirFlowRate();

  autosizeMinimumPrimaryAirFlowFraction();

  autosizeFanOnFlowFraction();
}
Ejemplo n.º 4
0
void hardware::init()
{
    analogReference(EXTERNAL);
    pinMode(BACKLIGHT_PIN, OUTPUT);
    pinMode(OUTPUT_DISABLE_PIN, OUTPUT);
    pinMode(FAN_PIN, OUTPUT);
    pinMode(BUZZER_PIN, OUTPUT);

    pinMode(SMPS_VALUE_PIN, OUTPUT);
    pinMode(SMPS_DISABLE_PIN, OUTPUT);
    pinMode(DISCHARGE_VALUE_PIN, OUTPUT);
    pinMode(DISCHARGE_DISABLE_PIN, OUTPUT);

    pinMode(BALANCER1_LOAD_PIN, OUTPUT);
    pinMode(BALANCER2_LOAD_PIN, OUTPUT);
    pinMode(BALANCER3_LOAD_PIN, OUTPUT);
    pinMode(BALANCER4_LOAD_PIN, OUTPUT);
    pinMode(BALANCER5_LOAD_PIN, OUTPUT);
    pinMode(BALANCER6_LOAD_PIN, OUTPUT);

    pinMode(MUX_ADR0_PIN, OUTPUT);
    pinMode(MUX_ADR1_PIN, OUTPUT);
    pinMode(MUX_ADR2_PIN, OUTPUT);
    pinMode(MUX0_Z_D_PIN, INPUT);
    pinMode(MUX1_Z_D_PIN, INPUT);

    setBatteryOutput(false);
    setFan(false);
    hardware::setBuzzer(0);

    lcd.begin(LCD_COLUMNS, LCD_LINES);
    timer.init();

    Timer1.initialize(TIMER1_PERIOD_MICROSECONDS);         // initialize timer1, and set a 1/2 second period
}
Ejemplo n.º 5
0
void hardware::initialize()
{
    IO::pinMode(BACKLIGHT_PIN, OUTPUT);
    IO::pinMode(OUTPUT_DISABLE_PIN, OUTPUT);
    IO::pinMode(FAN_PIN, OUTPUT);
    IO::pinMode(BUZZER_PIN, OUTPUT);

    IO::pinMode(BALANCER1_LOAD_PIN, OUTPUT);
    IO::pinMode(BALANCER2_LOAD_PIN, OUTPUT);
    IO::pinMode(BALANCER3_LOAD_PIN, OUTPUT);
    IO::pinMode(BALANCER4_LOAD_PIN, OUTPUT);
    IO::pinMode(BALANCER5_LOAD_PIN, OUTPUT);
    IO::pinMode(BALANCER6_LOAD_PIN, OUTPUT);
#if MAX_BANANCE_CELLS > 6
    IO::pinMode(BALANCER7_LOAD_PIN, OUTPUT);
    IO::pinMode(BALANCER8_LOAD_PIN, OUTPUT);
#endif

#ifdef ENABLE_BALANCER_PWR
    IO::pinMode(BALANCER_PWR_ENABLE_PIN, OUTPUT);
#endif

    IO::pinMode(SMPS_VALUE_PIN, OUTPUT);
    IO::pinMode(SMPS_DISABLE_PIN, OUTPUT);
    IO::pinMode(DISCHARGE_VALUE_PIN, OUTPUT);
    IO::pinMode(DISCHARGE_DISABLE_PIN, OUTPUT);

    setBatteryOutput(false);
    setFan(false);
    setBuzzer(0);
    setBalancer(0);

    lcd.begin(LCD_COLUMNS, LCD_LINES);
//    Timer1.initialize(TIMER1_PERIOD_MICROSECONDS);         // initialize timer1, and set a 1/2 second period
    Timer1::initialize();
    adc::initialize();
}
Ejemplo n.º 6
0
void Cyberhawk::setRobotState(kRobotStates state) {
	printf("Changing state to %i ...", state);
	switch(state) {
	case RS_DEFAULT: // allows for a smooth transition between autonomous and teleop, should not be needed anywhere else
		vics[VI_ELEVATOR]->Set(.3);  //puts elevator at bottom
		while(switches[SW_ELEVATOR]->Get() == 0);
		vics[VI_ELEVATOR]->Set(0);
		
		setAdjustableStates(true, true, true, true);  //resets shit
		
		for(int i = 2; i < 6; i++) dnoids[i].setToDefaultValue();  //reset noids
		for(unsigned int i = 0; i < vics.size(); i++) vics[i]->Set(0);  //reset more shit
		for(unsigned int i = 0; i < drive.size(); i++) drive[i]->Set(0);
		for(unsigned int i = 0; i < spikes.size(); i++) spikes[i]->Set(Relay::kOff);
		for(unsigned int i = 0; i < encoders.size(); i++) encoders[i]->Reset();
		setFan(FAN_DOWN);  //put fan down
		cshooter.Reset();  //reset shooter counter
		break;
		
	case RS_DRIVING_OFF: // offensive driving state
		vics[VI_ELEVATOR]->Set(.3);  //lower elevator
		while(switches[SW_ELEVATOR]->Get() == 0);
		vics[VI_ELEVATOR]->Set(0);
		
		setAdjustableStates(true, true, false, false);  //gate, fork, firing pin, elevator
		setFan(FAN_DOWN);
		dnoids[DSO_FIRINGPIN].setValue(false);  //turn off firing pin
		break;
		
	case RS_DRIVING_DEF: // defensive driving state
		vics[VI_ELEVATOR]->Set(.3);  //lower elevator (again)
		while(switches[SW_ELEVATOR]->Get() == 0);
		vics[VI_ELEVATOR]->Set(0);
		
		setAdjustableStates(false, false, false, false);  //you cant do shit
		setFan(FAN_UP);
		
		dnoids[DSO_GATE].setValue(false);  //nothing works
		dnoids[DSO_FORK].setValue(false);
		dnoids[DSO_FIRINGPIN].setValue(false);
		break;
		
	case RS_SHOOTING: // shooting state
		setAdjustableStates(false, false, true, true);  //cant control gate or fork
		setFan(FAN_DOWN);  //lower fan
		
		dnoids[DSO_GATE].setValue(false);  //turn off gate
		dnoids[DSO_FORK].setValue(false);  //turn off fork
		break;
		
	case RS_LOADING: // loading state
		vics[VI_ELEVATOR]->Set(.3);  //drop elevator
		while(switches[SW_ELEVATOR]->Get() == 0);
		vics[VI_ELEVATOR]->Set(0);
		
		setAdjustableStates(false, false, false, false);  //cant do shit
		setFan(FAN_MIDDLE);  //OMG ITS IN THE MIDDLE
		
		dnoids[DSO_GATE].setValue(false);  //boring
		dnoids[DSO_FORK].setValue(false);  //boring
		dnoids[DSO_FIRINGPIN].setValue(true);  //keeps from falling down
		break;
		
	default:
		cerr.write("FATAL ERROR IN STATE SHIFTING\n");  //YOU REALLY F****D UP
		break;
	}
	currentRobotState = state;
	printf("Finished changing state.\n");
}
Ejemplo n.º 7
0
// POST set params as "fanmode=1"
void HVAC::setVar(String sCmd, int val)
{
  if(m_EE.bLock) return;

  switch( CmdIdx( sCmd, cSCmds ) )
  {
    case 0:     // fanmode
      if(val == 2) // "freshen"
      {
        if(m_bRunning || m_furnaceFan || m_bFanMode) // don't run if system or fan is running
          break;
        m_fanPostTimer = m_EE.fanCycleTime; // use the post fan timer to shut off
        fanSwitch(true);
      }
      else setFan( (val) ? true:false);
      break;
    case 1:     // mode
      setMode( val );
      break;
    case 2:     // heatmode
      setHeatMode( val );
      break;
    case 3:     // resettotal
      resetTotal();
      break;
    case 4:
      resetFilter();
      break;
    case 5:     // fanpostdelay
      m_EE.fanPostDelay[digitalRead(P_REV)] = constrain(val, 0, 60*5); // Limit 0 to 5 minutes
      break;
    case 6:     // cyclemin
      m_EE.cycleMin = constrain(val, 60, 60*20); // Limit 1 to 20 minutes
      break;
    case 7:     // cyclemax
      m_EE.cycleMax = constrain(val, 60*2, 60*60); // Limit 2 to 60 minutes
      break;
    case 8:     // idlemin
      m_EE.idleMin = constrain(val, 60, 60*30); // Limit 1 to 30 minutes
      break;
    case 9:    // cyclethresh
      m_EE.cycleThresh = constrain(val, 5, 50); // Limit 0.5 to 5.0 degrees
      break;
    case 10:    // cooltempl
      setTemp(Mode_Cool, val, 0);
      m_bRecheck = true; // faster update
      break;
    case 11:    // cooltemph
      setTemp(Mode_Cool, val, 1);
      m_bRecheck = true;
      break;
    case 12:    // heattempl
      setTemp(Mode_Heat, val, 0);
      m_bRecheck = true;
      break;
    case 13:    // heattemph
      setTemp(Mode_Heat, val, 1);
      m_bRecheck = true;
      break;
    case 14:    // eheatthresh
      m_EE.eHeatThresh = constrain(val, 5, 50); // Limit 5 to 50 degrees F
      break;
    case 15:    // override
      if(val == 0)    // cancel
      {
        m_ovrTemp = 0;
        m_overrideTimer = 0;
      }
      else
      {
        m_ovrTemp = constrain(val, -90, 90); // Limit to -9.0 to +9.0 degrees F
        m_overrideTimer = m_EE.overrideTime;
      }
      m_bRecheck = true;
      break;
    case 16:    // overridetime
      m_EE.overrideTime = constrain(val, 60*1, 60*60*6); // Limit 1 min to 6 hours
      break;
    case 17: // humidmode
      m_EE.humidMode = constrain(val, HM_Off, HM_Auto2);
      break;
    case 18: // humidl
      m_EE.rhLevel[0] = constrain(val, 300, 900); // no idea really
      break;
    case 19: // humidh
      m_EE.rhLevel[1] = constrain(val, 300, 900);
      break;
    case 20: // adj
      m_EE.adj = constrain(val, -30, 30); // calibrate can only be +/-3.0
      break;
    case 21:     // fanPretime
      m_EE.fanPreTime[m_EE.Mode == Mode_Heat] = constrain(val, 0, 60*5); // Limit 0 to 5 minutes
      break;
    case 22: // fancycletime
      m_EE.fanCycleTime = val;
      break;
    case 23: // rmtflgs  0xC=(RF_RL|RF_RH) = use remote, 0x3=(RFML|RF_MH)= use main, 0xF = use both averaged
      m_RemoteFlags = val;
      break;
    case 24: // awaytime
      m_EE.awayTime = val; // no limit
      break;
    case 25: // awaydelta
      if(m_EE.Mode == Mode_Heat)
        m_EE.awayDelta[1] = constrain(val, -150, 0); // Limit to -15 degrees (heat away) target is constrained in calcTargetTemp
      else
        m_EE.awayDelta[0] = constrain(val, 0, 150); // Limit +15 degrees (cool away)
      break;
    case 26: // away (uses the override feature)
      if(val) // away
      {
        m_overrideTimer = m_EE.awayTime * 60; // convert minutes to seconds
        m_ovrTemp = m_EE.awayDelta[m_EE.Mode == Mode_Heat];
        m_bAway = true;
      }
      else // back
      {
        m_ovrTemp = 0;
        m_overrideTimer = 0;
        m_bAway = false;
      }
      break;
  }
}
Ejemplo n.º 8
0
/*
 * The Connection Handler for each client
 *********************************************************************************
 */
void *connectionHandler(void *socket_desc) {
    //Get the socket descriptor
    int sock = *(int*)socket_desc;
    int read_size;
	int buffersize = 255;
    
    char * client_message[2000];
	
	clientIsConnected = true;
	setUpdateDisplay(true);
	
    //Send some messages to the client
    //strcmp(message,"Welcome to Raspberry Pi gbmon2\n");
    //write(sock , message , strlen(message));
    //Receive a message from client
    while( (read_size = recv(sock , client_message , 2000 , 0)) > 0 ){
        //end of string marker
		
		char * buffer = (char*)malloc(buffersize);
		
        sprintf(buffer,"Received Command: *%s*", client_message);
        debugPrint(true, true, buffer, true, "SERVER");
		
		// usage
        if((strcmp(client_message, "usage") == 0) || (strcmp(client_message, "help") == 0)){
            debugPrint(true, false, "usage", false,"");
            write(sock,"Available Commands:\n   getVersion \t\t- returns version\n   getServerTime \t- returns current server time\0\n   getWifiStrength \t- returns current wifi signal strength\n   getTemperature \t- returns current temperature\n   getHumidity \t- returns current humidity\n   getFan \t- returns current fan status \n\n setFan \t- toggle fan On or Off\0",400);
        }
		
		// getServerTime
        if(strcmp(client_message, "getServerTime") == 0) {
            sprintf(buffer,"Sending Response: *%s*", getTime());
            debugPrint(true, true, buffer, true, "SERVER");
            write(sock,getTime(),30);
			
        }
		
		// getVersion
        if(strcmp(client_message, "getVersion") == 0) {
            sprintf(buffer,"Sending Response: *%s*", getVersion());
            debugPrint(true, true, buffer, true, "SERVER");
            write(sock,getVersion(),3);
        }
		
		// getWifiStrength
		if(strcmp(client_message, "getWifiStrength") == 0) {
            sprintf(buffer,"Sending Response: *%d*", getWifiStrength());
            debugPrint(true, true, buffer, true, "SERVER");
            write(sock,getWifiStrength(),3);
        }
		
		// getTemperature
		if(strcmp(client_message, "getTemperature") == 0) {
            sprintf(buffer,"Sending Response: *%s*", getTemperature());
            debugPrint(true, true, buffer, true, "SERVER");
            write(sock,getTemperature(),4);
        }
		
		// getHumidity
		if(strcmp(client_message, "getHumidity") == 0) {
            sprintf(buffer,"Sending Response: *%s*", getHumidity());
            debugPrint(true, true, buffer, true, "SERVER");
            write(sock,getHumidity(),4);
        }
		
		// getFan
		if(strcmp(client_message, "getFan") == 0) {
			sprintf(buffer,"Sending Response: *%s*", getFanAsString());
            debugPrint(true, true, buffer, true, "SERVER");
			write(sock,getFanAsString(),2);
        }
		
		// setFan
		if(strcmp(client_message, "setFan") == 0) {
            sprintf(buffer,"Sending Response: *%d*", setFan());
            debugPrint(true, true, buffer, true, "SERVER");
            write(sock,getFanAsString(),2);
        }
		
        /*
         if(strcmp(client_message, "getHumidity") == 0) {
         printf(">>> getHumidity \n");
         char tmp[4];
         sprintf(tmp,"%.1f\0",measure.humidity);
         //send(sock, &measure.humidity, sizeof(float),0);
         //write(sock,&measure.humidity, sizeof(float));
         write(sock,tmp,4);
         }
         if(strcmp(client_message, "getTemperature") == 0) {
         printf(">>> getTemperature \n");
         char tmp[4];
         sprintf(tmp,"%.1f\0",measure.temperature[0]);
         write(sock,tmp,4);
         }
         if(strcmp(client_message, "getAll") == 0) {
         if (debug==2) {
         printf(">>> getAll\n");
         }
         char tmp[255];
         sprintf(tmp,"%s\0",getAllJSON());
         write(sock,tmp,strlen(tmp));
         //n = write(sock,measure.humidity,6);
         }
         if(strcmp(client_message, "makePic") == 0) {
         printf(">>> makePic \n");
         char shellCommand [100];
         struct tm *t ;
         time_t tim ;
         char buf2[32];
         tim = time (NULL) ;
         t = localtime (&tim) ;
         sprintf (buf2,"%02d-%02d-%04d.jpg", t->tm_mday, t->tm_mon + 1, t->tm_year+1900);
         sprintf(shellCommand,"raspistill -o /home/pi/.gbmon/pics/%s",buf2);
         //printf("CAM command: %s",shellCommand);
         FILE * pp ;
         //char shellCommand[] = buf;
         pp = popen(shellCommand, "r");
         if (pp != NULL) {
         while (1) {
         char *line;
         char buf[1000];
         line = fgets(buf, sizeof buf, pp);
         if (line == NULL) break;
         if (line[0] == 'd') printf("%s", line); // line includes '\n'
         }
         pclose(pp);
         }
         sprintf(shellCommand,"sshpass -p 'alpine' scp /home/pi/.gbmon/pics/%s [email protected]:./Sites/MacServer/gbmon/pics/",buf2);
         pp = popen(shellCommand, "r");
         pclose(pp);
         write(sock,"Picture updated\0",20);
         }
         */
        //client_message[read_size] = '\0';
        //Send the message back to client
        //write(sock , client_message , strlen(client_message));
        //clear the message buffer
		
		free(buffer);
        read_size=1;
        memset(client_message, 0, 2000);
    }
    if(read_size == 0) {
        debugPrint(true, true, "Client disconnected", true, "SERVER");
        fflush(stdout);
		// DIsplay UPdate
		clientIsConnected = false;
		setUpdateDisplay(true);
		
    } else if(read_size == -1) {
        perror("recv failed");
    }
    return 0;
}