Ejemplo n.º 1
0
int main(void) {
	const int N = 7;

	int min, max, fall, tmin=0, tmax=0, tfall=0;
	int i;
	for(i=1; i<=N; i++) {
		printf("Tag %d:\n", i);
		printf("\nTagestiefsttemperatur (in Grad Celsius): ");
		min = readTemp();
		printf("\nTageshoechstemperatur (in Grad Celsius): ");
		max = readTemp();
		printf("\nNiederschlagsmenge (in mm): ");
		scanf("%d", &fall);
		printf("\n");

		if(max>tmax) tmax = max;

		if(tmin==0) tmin = max;
		if(min<tmin) tmin = min;
		tfall+=fall;
	}

	printf("Ergebnisse:\n");
	printf("Tiefsttemperatur der Woche: %d Grad Celsuis\n", tmin);
	printf("Hoechsttemperatur der Woche: %d Grad Celsuis\n", tmax);
	printf("Gesamtniederschlagsmenge der Woche: %d mm\n", tfall);

	return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
int main(void)
{
	usartInit();
	printf("*--------------------------------------------------- *\r\n");
	printf("*-------------------DS18B20 experiment-------------- *\r\n");
	printf("*--------------------------------------------------- *\r\n");

	while(1)
	{
		printf("Temperture:%d.%d¡æ\n\r ",readTemp()/100,readTemp()%100);
		_delay_ms(1000);
	}
}
Ejemplo n.º 3
0
/*! **********************************************************************
 * Function: configureRange(void)
 *
 * Include: Range.h
 *
 * Description: Configures the Range module
 *
 * Arguments: None
 *
 * Returns: None
 *************************************************************************/
void configureRange(void)
{
    unsigned char config;

    INIT_PIN = 0;

    //Enable global interrupts and interrupt priority
    INT_SETUP()

    readTemp();

    //Make sure the AD is configured
    configureAD();

    CCP1_INPT = 1;
    INIT_TRIS = 0;  //Make the INIT

    //Open  Timer
    config = T1_16BIT_RW & T1_SOURCE_INT & T1_OSC1EN_OFF & T1_PS_1_1 & T1_SYNC_EXT_OFF &TIMER_INT_ON;
    OpenTimer1(config);

    config = CAPTURE_INT_ON & CAP_EVERY_RISE_EDGE;

    //CloseCapture1, which will clear any interrupt flags etc
    CloseCapture1();

    //Open the input capture on compare1
    OpenCapture1(config);
}
Ejemplo n.º 4
0
/*
 *  ======== main ========
 */
void loop()
{
	unsigned char SlaveAddress; 			//Contains device address
	unsigned char command;	  			//Contains the access command
	unsigned int data;		  			//Contains data value
           // Activate Grace-generated configuration
	headPhoneGpio_init();
	SlaveAddress = SA << 1;						//Set device address
	command = RAM_Access | RAM_To; //Form RAM access command + RAM address
	//P1DIR &= ~0x01;
	mdelay(300);
	//interrupt_init();
	iic_gpio_init();
	WakeUpSensor();
	timer_init();
	// >>>>> Fill-in user code here <<<<<
	//_BIS_SR(LPM0_bits + GIE);
	for (;;) {
		data=readTemp();//MemRead((MLX90615_ADDR>>1),0x27);
		if(data!=-1)
		{
			data=data * 2 - 27315;
			buffer[0]=TOKEN_CMD_OBJ_TMP;
			buffer[1]=(data>>8)&0xff;
			buffer[2]=(data)&0xff;

			buffer[3]=~(buffer[0]+buffer[1]+buffer[2])-1;
			sendBytes(buffer,4);
		}

		//	readTemp();
	}
Ejemplo n.º 5
0
/**
 * Adjust the frequency according to the current temperature.
 * Returns the number of seconds to wait until the next adjustment.
 */
void Throttle::adjust()
{
	int temp = readTemp();
	std::vector<int>::iterator new_freq = freqs.end();

	DEBUG_PRINT("[Throttle] Temperature: " << (float)temp/1000 << "°C");

	// slowly reset stabilize counter
	if (stabilize > 0) --stabilize;
	if (stabilize < 0) ++stabilize;

	// If the temperature exceeds a threshold, find the next best frequency.
	if (temp > temp_max && stabilize >= 0) {
		new_freq = std::lower_bound(freqs.begin(), freqs.end(), freq);
		if (new_freq == freqs.begin())
			return;     // There is nothing we can do.
		else
			--new_freq;
		stabilize = -wait_after_adjust;
	}
	if (temp < temp_min && stabilize <= 0) {
		new_freq = std::upper_bound(freqs.begin(), freqs.end(), freq);
		stabilize = wait_after_adjust;
	}

	// Have we found one? Then adjust.
	if (new_freq != freqs.end()) {
		freq = *new_freq;
		writeFreq();
	}
}
Ejemplo n.º 6
0
/******************************************************************************
 * @fn          sendReport
 *
 * @brief       Send sensor report
 *
 * @param       none
 *              
 * @return      none
 */
static void sendReport(void)
{
  uint8 pData[SENSOR_REPORT_LENGTH];
  static uint8 reportNr=0;
  uint8 txOptions;
  
  // Read and report temperature value
  pData[SENSOR_TEMP_OFFSET] =  readTemp();
  
  // Read and report voltage value
  pData[SENSOR_VOLTAGE_OFFSET] = readVoltage(); 
    
  pData[SENSOR_PARENT_OFFSET] =  HI_UINT16(parentShortAddr);
  pData[SENSOR_PARENT_OFFSET + 1] =  LO_UINT16(parentShortAddr);
  
  // Set ACK request on each ACK_INTERVAL report
  // If a report failed, set ACK request on next report
  if ( ++reportNr<ACK_REQ_INTERVAL && reportFailureNr==0 ) 
  {
    txOptions = AF_TX_OPTIONS_NONE;
  }
  else 
  {
    txOptions = AF_MSG_ACK_REQUEST;
    reportNr = 0;
  }
  // Destination address 0xFFFE: Destination address is sent to previously
  // established binding for the commandId.
  zb_SendDataRequest( 0xFFFE, SENSOR_REPORT_CMD_ID, SENSOR_REPORT_LENGTH, pData, 0, txOptions, 0 );
}
Ejemplo n.º 7
0
void Timer1ISR (void)
{
	volatile static uint32_t cont_sens_ir=0;
	cont_sens_ir++;

	//faccio girare il motore del sensore di temperatura
	if(cont_sens_ir >= 7)
	{
		cont_sens_ir = 0;
		//controllo il pwm e di conseguenza l'angolo pwm=10->90°
		if(servo->delta_2 == 10)
		{
			servo->delta_2 = 5;
			pwmPowerA7(servo, -90 );
		}
		else
		{
			servo->delta_2 = 10;
			pwmPowerA7(servo, 90 );
		}
	}

	//adesso occorre leggere il sensore, passandogli l'opportuno puntatore
	readTemp(TEMPptr);
	/// occorre confrontare la temperatura con il valore di default letto all'inizio.
	if ((int)(TEMPptr->Temp) > 3 * TEMPptr->T_tar )
	{
		/// c'e' un ferito
		// TODO:
		/// mettere il codice

	}

}
Ejemplo n.º 8
0
/*!
 * Display the Show Temperature serial message
 */
static void dispTempSerialMessage(void)
{
    int temp = readTemp();
    sendROM("\t");
    sendROM(showTemp1);
    transmit(intToAscii(temp));
    sendROM(showTemp2);
}
Ejemplo n.º 9
0
/***************************************************************************
 PUBLIC FUNCTIONS
 ***************************************************************************/
void Adafruit_LSM9DS0::read()
{
  /* Read all the sensors. */
  readAccel();
  readMag();
  readGyro();
  readTemp();
}
Ejemplo n.º 10
0
void HomeScreen::displayTemp() {
#if DBG
  Serial.print("HomeScreen::displayTemp: ");
  Serial.println(tNow);
#endif
  float temp = readTemp(TEMP_F);
  displayTemp(TEMP_F, temp);
}
Ejemplo n.º 11
0
void OnGetTEMP(u_char param_len, const char * parametres, u_char * rep_len, char * reponse)
{
    *rep_len = sprintf(reponse,"%f",readTemp());
    if (*rep_len < 0)
    {
        *rep_len = sprintf(reponse,"%c",205);
    }
}
Ejemplo n.º 12
0
int main(void){

	SystemInit();
	InitSystick();
	initTempSensor();

	while(1)                             
	{
		readTemp();
	}

	return 0;
}
Ejemplo n.º 13
0
void protocole_temp(int socket_s)
{
    float temperature;
    char message[256];
    int dim;

    temperature = readTemp();
    dim = sprintf(message,"T = %f degrees\n",temperature);
    printf("%s",message);

    message[dim] = 0;
    send(socket_s , message, dim, 0);
}
Ejemplo n.º 14
0
int main(void){
  
  DDRD &= ~(1 << PD0); //button
  PORTD |= (1 << PD0); //pullup

  DDRC |= 0b00111111; //anodes + segments a, b and c
  DDRD |= 0b11111000; //segments d, e, f, g and led
    
  anodesOff;
  displayOn = 1; //display is on
      
  /* setup 16 bits timer1 for reading temperature
  with 1024 prescaler running at 1MHz with overflow interrupt
  1MHz / 1024 = 976.5625Hz
  976.56 / 0.1 Hz = 9765.6
  */
    
  OCR1A = 30000; //about once very 30 seconds w00t w00t 16 bits!
  TCCR1B |= (1<<WGM12); //CTC OCR1A
  TCCR1B |= (1<<CS12) | (1<<CS10); //1024 prescale 
  TIMSK = (1 << OCIE1A); //trigger interrupt on overflow

  /* setup timer2 for multiplexing 
  Timer 2 is an 8 bit timer, we'll set it with 1024 prescale with CTC mode 
  on OCR2 = 5;
  */

  OCR2 = 5;
  TCCR2 |= (1<<WGM21); //CTC mode
  TCCR2 |= (1<<CS20) | (1<<CS21) | (1<<CS22); //1024 
  TIMSK |= (1 << OCIE2); //trigger interrupt on overflow
  
  //uart_init((UART_BAUD_SELECT((BAUD),F_CPU)));
  sei(); //turn on interrupts
  
  /*
  for (uint8_t i=0; i<10; i++){
    display[0] = display[1] = display[2] = i;
    _delay_ms(300);
  }
  */
  search_sensors(); //populate gSensorIDs
  readTemp();
  
  while(1){
    set_sleep_mode(SLEEP_MODE_IDLE);
    sleep_enable();
    sleep_mode();
  }
  return 1; //never reached, but compiler longs for it.
}
Ejemplo n.º 15
0
/******************************************************************************
 * @fn          sendReport
 *
 * @brief       Send sensor report
 *
 * @param       none
 *
 * @return      none
 */
static void sendReport(void)
{
  uint8 pData[SENSOR_REPORT_LENGTH];
  static uint8 reportNr = 0;
  uint8 txOptions;

  // Read and report temperature value
  pData[SENSOR_TEMP_OFFSET] = readTemp();

  // Read and report voltage value
  pData[SENSOR_VOLTAGE_OFFSET] = readVoltage();

  pData[SENSOR_PARENT_OFFSET] =  HI_UINT16(parentShortAddr);
  pData[SENSOR_PARENT_OFFSET + 1] =  LO_UINT16(parentShortAddr);
  pData[BUTTON_PARENT_OFFSET+1] = MCU_IO_GET(0,1);
 // HalUARTWrite(HAL_UART_PORT_0,pData,SENSOR_REPORT_LENGTH);
 // HalUARTWrite(HAL_UART_PORT_1,pData,SENSOR_REPORT_LENGTH);
  int test = MCU_IO_GET(0,1);
  if( MCU_IO_GET(0,1) > 0){
    MCU_IO_SET_LOW(0, 0);
  } else {
    MCU_IO_SET_HIGH(0, 0);
  }
  MCU_IO_SET_LOW(0, 1);
  // Set ACK request on each ACK_INTERVAL report
  // If a report failed, set ACK request on next report
  if ( ++reportNr<ACK_REQ_INTERVAL && reportFailureNr == 0 )
  {
    txOptions = AF_TX_OPTIONS_NONE;
  }
  else
  {
    txOptions = AF_MSG_ACK_REQUEST;
    reportNr = 0;
  }
  // Destination address 0xFFFE: Destination address is sent to previously
  // established binding for the commandId.
  //printf("%i %i",pData[SENSOR_TEMP_OFFSET],oldValue);
  if(timeDone >= 60000){
     timeDone += 1;
  }
  if(pData[SENSOR_TEMP_OFFSET] != oldValue && timeDone >= 60000){
    oldValue = pData[SENSOR_TEMP_OFFSET];
    zb_SendDataRequest( 0xFFFE, SENSOR_REPORT_CMD_ID, SENSOR_REPORT_LENGTH, pData, 0, txOptions, 0 );
    timeDone = 0;
  } else {
    timeDone += myReportPeriod;
  }
}
// run once in main loop, handles reading pin vals
// setting heater on/off
void SlowCooker::loop(){
  m_lastLidState = m_lidState;
  m_lidState = digitalRead(m_lidSwitchPin);
  m_currentTemp = readTemp(); // float in C

  if(m_state == STATE_NOT_COOKING)
    return;
  
  if(calcHeaterState()){
    if(!m_heaterActive){
      Serial.println(F("Turning Heater On"));
      m_heaterOnTime = millis();
    }
    setHeaterState(true);
  }else{
    if(m_heaterActive){
      Serial.println(F("Turning Heater Off"));
      m_heaterOnTime = millis();
    }
    setHeaterState(false);
  }
  
  
  // check if cook is finished based on start time.
  // if cook time is zero then it will run forever!!!
  if(m_cookTime != 0){
    long sLeft = (m_cookTime * 60) - ((millis() - m_timeCookStarted)/1000);
    if(sLeft <= 0){
      stopCook();
      m_eventCallback(EVENT_COOK_END);
    }
  }

  // send event if lid has been opened or closed.
  if(m_lastLidState && !m_lidState){
    m_eventCallback(EVENT_LID_CLOSED);
  }else if(!m_lastLidState && m_lidState){
    m_eventCallback(EVENT_LID_OPENED);
  }

}
Ejemplo n.º 17
0
void loop() {
  counter++;
  // 120 * 2000 - this should be about 2 min, but not sure how long ArduinoOTA.handle() takes...
  readTemp();
  display.clear();
  display.setFont(Just_Another_Hand_Plain_48);
  display.setTextAlignment(TEXT_ALIGN_CENTER);
  int fInt = round(f);
  String outS = String(fInt);
  outS += "°F";
  display.drawString(64,16, outS);
  display.display();
  
  
  if (counter > 120) {
    Serial.println("posting value...");
    postValues();
    counter = 0;
  }
  ArduinoOTA.handle();
  delay(2000);
}
Ejemplo n.º 18
0
void main()
{
    byte i;
    long l;

    initBus();
    initADC();
    initI2C();

#ifdef HAS_UART
    initInterruptUarts();
#endif


    for(i=0; i<16; i++)
        cfgRegs[i] = 65;

    byte i2cErrCount = 0;

    while(1)
    {
        byte rx = readTemp(0x9E);

        /* Read error */
        if(rx == 255)
        {
            if(i2cErrCount < 10)
                i2cErrCount++;
            else
                myTemperature = 255;

            initI2C();
        } else
        {
            i2cErrCount = 0;
            myTemperature = rx;
        }
    }
}
Ejemplo n.º 19
0
void setup() {
  Serial.begin(115200);
  Serial.println("Booting");

  setupWifi();

  ArduinoOTA.onStart([]() {
    Serial.println("Start");
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("End Failed");
  });
  ArduinoOTA.begin();
  Serial.println("Ready OTA");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  
  setupTempSensor();
  setupOled();
  delay(2000);
  ThingSpeak.begin(client);
  delay(100);
  
  readTemp();
  postValues();
  
}
Ejemplo n.º 20
0
static int handle_get_temp(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo)
{
    char tmp[30];
    sprintf(tmp,"%d",readTemp());
    return coap_make_response(scratch, outpkt, (const uint8_t *)&tmp, strlen(tmp), id_hi, id_lo, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN);
}
Ejemplo n.º 21
0
void main()
{
    byte writeIndex = 0;
    byte i;
    long l;
    TRISB = 0xFFFF;         /* All inputs */

    LAT_BATT1_CTL = BATT_ENABLE;
    LAT_BATT2_CTL = BATT_ENABLE;
    LAT_BATT3_CTL = BATT_ENABLE;
    LAT_BATT4_CTL = BATT_ENABLE;
#ifdef BBR2
    LAT_BATT5_CTL = ~BATT_ENABLE;
#else
    LAT_BATT5_CTL = BATT_ENABLE;
#endif
    LAT_BATT6_CTL = BATT_ENABLE;

    TRIS_BATT1_CTL = TRIS_OUT;
    TRIS_BATT2_CTL = TRIS_OUT;
    TRIS_BATT3_CTL = TRIS_OUT;
    TRIS_BATT4_CTL = TRIS_OUT;
#ifdef BBR2
    TRIS_BATT5_CTL = TRIS_IN;
#else
    TRIS_BATT5_CTL = TRIS_OUT;
#endif
    TRIS_BATT6_CTL = TRIS_OUT;

    TRIS_BATT1 = TRIS_IN;
    TRIS_BATT2 = TRIS_IN;
    TRIS_BATT3 = TRIS_IN;
    TRIS_BATT4 = TRIS_IN;
    TRIS_BATT5 = TRIS_IN;
    TRIS_BATT6 = TRIS_IN;

    TRIS_WTRSEN = TRIS_IN;

    LAT_PWRKILL = ~PWRKILL_ON;
    TRIS_PWRKILL = TRIS_OUT;

    TRIS_LED_STA = TRIS_OUT;
    TRIS_LED_BATTLOW = TRIS_OUT;

    LAT_LED_STA = LED_ON;
    LAT_LED_BATTLOW = LED_ON;


    initBus();
    LAT_LED_STA = LED_ON;
    LAT_LED_BATTLOW = ~LED_ON;

  //  while(1);

    initADC();
    initI2C();

    initBattlowLight();

#ifdef HAS_UART
    initInterruptUarts();
#endif

    for(l=0; l<50000; l++);

    LAT_LED_STA = LED_ON;
    LAT_LED_BATTLOW = ~LED_ON;

    for(l=0; l<50000; l++);

//     LAT_PWRKILL = PWRKILL_ON;

    LAT_LED_STA = ~LED_ON;

    for(i=0; i<16; i++)
        cfgRegs[i] = 65;


    byte i2cErrCount = 0;

    while(1)
    {
//         checkBus();
        /* Give it a second */
//        for(l=0; l<10000; l++);

        byte rx = readTemp(0x9E);

        /* Read error */
        if(rx == 255)
        {
            if(i2cErrCount < 10)
                i2cErrCount++;
            else
                myTemperature = 255;

            initI2C();
        } else
        {
            i2cErrCount = 0;
            myTemperature = rx;
        }

        static const byte vADCs[]={ADC_B1V, ADC_B2V, ADC_B3V, ADC_B4V, ADC_B5V, ADC_B6V, ADC_26V};

        /* Measure battery voltages */
        for(i=0; i < 7; i++) {
#ifdef BBR2
            /* There is no fifth battery in BBR2, so skip it */
            if(i == 4) { vBatt[4]= 0; continue; }
#endif
            setADC(vADCs[i]);
            vBatt[i] = applyCalibration(readADC(), CAL_V_A, CAL_V_B);
        }

        /* Maintain running averages of the I sensors */
        for(i=0; i < BATT_COUNT; i++) {
#ifdef BBR2
            /* There is no fifth battery in BBR2, so skip it */
            if(i == 4) { iADCVal[4][writeIndex] = 0; continue; }
#endif
            setADC(iADCs[i]);
            iADCVal[i][writeIndex] = readADC();
        }
        writeIndex++;

        if(writeIndex >= IHISTORY_SIZE)
            writeIndex = 0;

        /* Calculate running averages of the battery currents */
        for(i=0; i < BATT_COUNT; i++) {
#ifdef BBR2
            /* There is no fifth battery in BBR2, so skip it. */
            if(i == 4) { iBatt[4] = 0; continue; }
#endif
            iBatt[i] = applyCalibration(avgRow(i), CAL_I12V_A, CAL_I12V_B);
        }
    }
}
Ejemplo n.º 22
0
int main(int argc, char ** argv)
{
    if(argc < 2 || ((argc == 2) && (strcmp(argv[1], "-h") == 0) ))
    {
        printf("LCD-related Commands:\n");
        printf("\t-c (clear screen)\n");
        printf("\t-t line1 line2\n");
        printf("\t-bloff (backlight on)\n");
        printf("\t-blon (backlight off)\n");
        printf("\t-blfl (backlight flash)\n");

        printf("\nSafety commands:\n");
        printf("\t-safe (disable thrusters)\n");
        printf("\t-unsafe (enable thrusters)\n");
        printf("\t-safe [n] (safe thruster n)\n");
        printf("\t-unsafe [n] (unsafe thruster n)\n");
        printf("\t-diagon  (runtime diagnostics on)\n");
        printf("\t-diagoff (runtime diagnostics off)\n");
        printf("\t-tstop (send zero speed command)\n");

        printf("\nPower commands:\n");
        printf("\t-hardkill  (kill power)\n");
        printf("\t-extpower  (switch to external power source)\n");
        printf("\t-intpower  (switch to batteries)\n");
        printf("\t-batton n (enable battery n)\n");
        printf("\t-battoff n  (disable battery n)\n");
        printf("\t-setovr a b  (configure overcurrent parameters)\n");
        printf("\t-readovr  (read overcurrent parameters)\n");
        printf("\t-setspeed a b c d e f  (set speeds)\n");

        printf("\nSonar commands:\n");
        printf("\t-bfstart (starts the Blackfin processor)\n");
        printf("\t-bfstop (stops the Blackfin processor)\n");
        printf("\t-bfreset (reboots the Blackfin processor)\n");
        printf("\t-sonar (retrieve latest sonar telemetry)\n");
        
        printf("\nOther commands:\n");
        printf("\t-check (crude system check)\n");
        printf("\t-status (show sensor readings)\n");
        printf("\t-baron (enable bar outputs)\n");
        printf("\t-baroff (disable bar outputs)\n");
        printf("\t-baron [n] (enable bar output n)\n");
        printf("\t-baroff [n] (disable bar output n)\n");
        printf("\t-marker {1|2} (drop marker 1 or 2)\n");
        printf("\t-s  (begin start sequence)\n");
        printf("\t-setbars n (set bar outputs)\n");
        printf("\t-noblink (stop animation)\n");
        printf("\t-redgreen (start red/green animation)\n");
        printf("\t-redblue (start red/blue animation)\n");

        printf("\nDVL commands:\n");
        printf("\t-dvlon (enable dvl)\n");
        printf("\t-dvloff (disable dvl)\n");

        printf("\nPneumatics Commands:\n");
        printf("\t-firetorp # (fire torpedo number #)\n");
        printf("\t-armtorp # (arm torpedo number #)\n");
        printf("\t-voidtorp # (void torpedo number #)\n");
        printf("\t-extgrabber (close the grabber)\n");
        printf("\t-retgrabber (open the grabber)\n");
        printf("\t-voidgrabber (void the grabber)\n");
        printf("\t-voidall (void all pneumatics)\n");
        printf("\t-pneuoff (turn off pneumatics)\n");

        printf("\nDerpy Commands:\n");
        printf("\t-derpypwr {on|off} (turn on or off derpy power)\n");
        printf("\t-setderpy # (set derpy speed)\n");
        printf("\t-stopderpy (set derpy speed to not move)\n");

        return -1;
    }

    int fd = openSensorBoard("/dev/ttyUSB0");

    if(fd == -1)
    {
        printf("\nCould not find device!\n");
        printf("Is the right device set?\n");
        printf("Has the serial number of this FTDI chip been added to udev?\n");
        printf("Because that needs to be done for every board we make.\n");

        close(fd);
        return -1;
    }

    if(syncBoard(fd) != 0)
    {
        printf("\nCould not sync with board!\n");
        close(fd);
    }

	if(strcmp(argv[1], "-readovr") == 0)
	{
		int a, b;

		if(readOvrParams(fd, &a, &b) != SB_OK)
			printf("Error reading parameters\n");
		else
			printf("a=%d, b=%d\n", a, b);
		close(fd);
		return 0;
	}

    else if(strcmp(argv[1], "-setovr") == 0)
    {
		if(argc != 4)
		{
			printf("Bad number of arguments\n");
			close(fd);
			exit(1);
		}

		printf("reply was 0x%02x\n", setOvrParams(fd, atoi(argv[2]), atoi(argv[3])));
	}

    else if(strcmp(argv[1], "-bfreset") == 0)
    {
        printf("reply was 0x%02x\n", resetBlackfin(fd));
    }

    else if(strcmp(argv[1], "-bfstart") == 0)
    {
        printf("reply was 0x%02x\n", startBlackfin(fd));
    }

    else if(strcmp(argv[1], "-bfstop") == 0)
    {
        printf("reply was 0x%02x\n", stopBlackfin(fd));
    }

    else if(strcmp(argv[1], "-sonar") == 0)
    {
        struct sonarData sd;
        getSonarData(fd, &sd);

        printf("Vector: \t<%5.4f %5.4f %5.4f>\n", sd.vectorX, sd.vectorY, sd.vectorZ);
        printf("Status: \t0x%02x\n", sd.status);
        printf("Range:  \t%u\n", sd.range);
        printf("Timestamp:\t%u\n", sd.timeStampSec);
        printf("Sample No:\t%u\n", sd.timeStampUSec);
//         printf("reply was 0x%02x\n", resetBlackfin(fd));
    }

    else if(strcmp(argv[1], "-magpwron") == 0)
    {
        int ret;
        if((ret = setMagPower(fd, 1)) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }

    else if(strcmp(argv[1], "-magpwroff") == 0)
    {
        int ret;
        if((ret = setMagPower(fd, 0)) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }
    else if(strcmp(argv[1], "-setspeed") == 0)
    {
        if(argc != 8)
        {
                printf("Bad number of arguments\n");
                close(fd);
                exit(1);
        }

        printf("Ctrl-C to quit.\n");
        while(1)
        {
            setSpeeds(fd, atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), atoi(argv[7]));
            usleep(50000);
        }
    }
    else if(strcmp(argv[1], "-status") == 0)
    {
        int ret;
        int bStat = -1;
        int bEnable = -1;

        unsigned char temp[NUM_TEMP_SENSORS];
        ret = readDepth(fd);

        if(ret == SB_ERROR)
            printf("Error reading depth!\n");
        else
            printf("Depth :   %d (%s)\n", ret, (ret > 50) ? "Seems OK" : "Check Sensor");

        ret = readTemp(fd, temp);
        if(ret == SB_ERROR)
            printf("Error reading temperature!\n");
        else
        {
            int i;
            printf("Temperature (C): ");

            for(i=0; i<NUM_TEMP_SENSORS; i++)
                if(temp[i] == 255)
                    printf("%c%c ", '?','?');
                else
                    printf("%d ", temp[i]);
            printf("\n");
        }

        ret = readThrusterState(fd);
        if(ret == SB_ERROR)
            printf("Error reading thruster state!\n");
        else
        {
            printf("\nThruster state: 0x%02X\t", ret);
            printf("[%c%c%c%c%c%c]",
            (ret & THRUSTER1_ENABLED) ? '1' : '-',
            (ret & THRUSTER2_ENABLED) ? '2' : '-',
            (ret & THRUSTER3_ENABLED) ? '3' : '-',
            (ret & THRUSTER4_ENABLED) ? '4' : '-',
            (ret & THRUSTER5_ENABLED) ? '5' : '-',
            (ret & THRUSTER6_ENABLED) ? '6' : '-');

            if(ret == 0x00)
                printf("   (All safe)");

            if(ret == 0x3F)
                printf("   (All unsafe)");

        }

        ret = readOvrState(fd);
        if(ret == SB_ERROR)
            printf("\nError reading overcurrent register!\n");
        else
        {
            printf("\nOver-current: \t0x%02X", ret);
            printf("\t[%c%c%c%c%c%c]",
            (ret & THRUSTER1_OVR) ? '1' : '-',
            (ret & THRUSTER2_OVR) ? '2' : '-',
            (ret & THRUSTER3_OVR) ? '3' : '-',
            (ret & THRUSTER4_OVR) ? '4' : '-',
            (ret & THRUSTER5_OVR) ? '5' : '-',
            (ret & THRUSTER6_OVR) ? '6' : '-');

            if(ret == 0x00)
                printf("   (All ok)");

            if(ret == 0xFF)
                printf("   (All busted)");
        }


        ret = readBarState(fd);
        if(ret == SB_ERROR)
            printf("Error reading bar state!\n");
        else
        {
            printf("\nBar state   :\t0x%02X", ret);
            printf("\t[%c%c%c%c%c%c%c%c]",
            (ret & BAR1_ENABLED) ? '1' : '-',
            (ret & BAR2_ENABLED) ? '2' : '-',
            (ret & BAR3_ENABLED) ? '3' : '-',
            (ret & BAR4_ENABLED) ? '4' : '-',
            (ret & BAR5_ENABLED) ? '5' : '-',
            (ret & BAR6_ENABLED) ? '6' : '-',
            (ret & BAR7_ENABLED) ? '7' : '-',
            (ret & BAR8_ENABLED) ? '8' : '-');

            if(ret == 0x00)
                printf(" (All off)");

            if(ret == 0xFF)
                printf(" (All on)");
        }

        ret = readBatteryEnables(fd);
        if(ret == SB_ERROR)
            printf("Error reading battery enables state!\n");
        else
        {
            printf("\nBatt enables:   0x%02X\t", ret);
            printf("[%c%c%c%c%c%c]",
            (ret & BATT1_ENABLED) ? '1' : '-',
            (ret & BATT2_ENABLED) ? '2' : '-',
            (ret & BATT3_ENABLED) ? '3' : '-',
            (ret & BATT4_ENABLED) ? '4' : '-',
            (ret & BATT5_ENABLED) ? '5' : '-',
            (ret & BATT6_ENABLED) ? '6' : '-');

            if(ret == 0x00)
                printf("  (All off ? ? ? ? ?)");

            if(ret == 0x1F)
                printf("    (All on)");

            bEnable = ret;
        }

        ret = readStatus(fd);
        if(ret == SB_ERROR)
            printf("Error reading board status!\n");
        else
        {
            printf("\nBatt in use :   0x%02X\t", ret);
            printf("[%c%c%c%c%c%c]",
            (ret & BATT1_INUSE) ? '1' : '-',
            (ret & BATT2_INUSE) ? '2' : '-',
            (ret & BATT3_INUSE) ? '3' : '-',
            (ret & BATT4_INUSE) ? '4' : '-',
            (ret & BATT5_INUSE) ? '5' : '-',
            (ret & BATT6_INUSE) ? '6' : '-');

            bStat = ret;

            printf("\n\nStatus: 0x%02X\n", ret);
            printf("\t%s\n\t%s\n\t%s\n",
                (ret & STATUS_WATER) ? "Water present" : "No water detected.",
                (ret & STATUS_STARTSW) ? "Start switch on" : "Start switch off",
                (ret & STATUS_KILLSW) ? "Kill magnet present" : "No kill magnet");
        }

        struct powerInfo info;

        ret = readMotorCurrents(fd, &info);
        if(ret == SB_OK)
        {
            int i;
            printf("\nOutput currents:\n\t[1-4]: ");
            for(i=0; i<4; i++)
                printf("\t%2.3fA", info.motorCurrents[i]);
            printf("\n\t[5-8]: ");
            for(i=0; i<4; i++)
                printf("\t%2.3fA", info.motorCurrents[i+4]);
        } else
            printf("\nError reading motor currents\n");

        printf("\n");


        if(readBoardVoltages(fd, &info) == SB_OK &&
           readBatteryVoltages(fd, &info) == SB_OK &&
           readBatteryCurrents(fd, &info) == SB_OK)
        {
            printf("\nPower information:\n");
            printf("\t5V Bus :\t% 2.3fV\t  % 2.3fA\n", info.v5VBus, info.i5VBus);
            printf("\t12V Bus:\t%-2.3fV\t  % 2.3fA\n", info.v12VBus, info.i12VBus);
            printf("\t26V Bus:\t% 2.3fV  (Not implemented)\n", info.v26VBus);
            printf("\tAux Current:\t %2.3fA\n", info.iAux);


            if(bStat == -1 || bEnable == -1)
                printf("Could not get enough information about batteries\n");
            else
            {
                printf("\nBattery information:\n");

                unsigned char enableFlags[]=
                {
                    BATT1_ENABLED, BATT2_ENABLED, BATT3_ENABLED, BATT4_ENABLED, BATT5_ENABLED, BATT6_ENABLED
                };

                unsigned char useFlags[]=
                {
                    BATT1_INUSE, BATT2_INUSE, BATT3_INUSE, BATT4_INUSE, BATT5_INUSE, BATT6_INUSE
                };

                int i;

                printf("\tBAT\t Voltage\t Current   EN?\tUsed?\n");
                for(i=0; i<6; i++)
                {
                    printf("\t");
                    if(i != 4)
                        printf("B%d ", i+1);
                    else
                        printf("EXT ");

                    printf("\t% 2.3fV\t% 2.3fA\t ", info.battVoltages[i], info.battCurrents[i]);

                    printf("   %c\t %c", bEnable & enableFlags[i] ? 'Y' : 'N',
                                     bStat & useFlags[i] ? 'Y' : 'N');


                    printf("\n");
                }
            }


        } else
            printf("\nError reading power information\n");




    }


    else if(strcmp(argv[1], "-check") == 0)
    {
        int ret = pingBoard(fd);

        if(ret == SB_OK)
            printf("Ping: OK\n");
        else
            printf("Ping: Error (Code %d)\n", ret);

        ret = checkBoard(fd);

        if(ret == SB_OK)
            printf("Self-test: OK\n");
        else
            printf("Self-test: Error (Code %d)\n", ret);

        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-marker") == 0)
    {
        if(argc == 3)
        {
            int t = atoi(argv[2]);
            if(t != 1 && t != 2)
            {
                printf("Bad marker number: %d\n", t);
                close(fd);
                return -1;
            }

            dropMarker(fd, t-1);

        } else
        {
            printf("Which marker? Specify 1 or 2.\n");
        }

        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-safe") == 0)
    {
        int i;
        unsigned int cmdList[]=
        {
            CMD_THRUSTER1_OFF, CMD_THRUSTER2_OFF, CMD_THRUSTER3_OFF,
            CMD_THRUSTER4_OFF, CMD_THRUSTER5_OFF, CMD_THRUSTER6_OFF
        };

        if(argc == 3)
        {
            int t = atoi(argv[2]);
            if(t < 1 || t > 6)
            {
                printf("Bad thruster number: %d\n", t);
                close(fd);
                return -1;
            }

            thrusterCmd(fd, cmdList[t-1]);

        } else
        {
            for(i=0; i<6; i++)
                thrusterCmd(fd, cmdList[i]);
        }

        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-battoff") == 0)
    {
        unsigned int cmdList[]=
        {
            CMD_BATT1_OFF, CMD_BATT2_OFF, CMD_BATT3_OFF, CMD_BATT4_OFF, CMD_BATT5_OFF
        };

        if(argc == 3)
        {
            int t = atoi(argv[2]);
            if(t < 1 || t > 5)
            {
                printf("Bad battery number: %d\n", t);
                close(fd);
                return -1;
            }

            setBatteryState(fd, cmdList[t-1]);

        } else
        {
            printf("Battery number not specified.\n");
        }

        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-batton") == 0)
    {
        unsigned int cmdList[]=
        {
            CMD_BATT1_ON, CMD_BATT2_ON, CMD_BATT3_ON, CMD_BATT4_ON, CMD_BATT5_ON
        };

        if(argc == 3)
        {
            int t = atoi(argv[2]);
            if(t < 1 || t > 5)
            {
                printf("Bad battery number: %d\n", t);
                close(fd);
                return -1;
            }

            setBatteryState(fd, cmdList[t-1]);

        } else
        {
            printf("Battery number not specified.\n");
        }

        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-unsafe") == 0)
    {
        int i;
        unsigned int cmdList[]=
        {
            CMD_THRUSTER1_ON, CMD_THRUSTER2_ON, CMD_THRUSTER3_ON,
            CMD_THRUSTER4_ON, CMD_THRUSTER5_ON, CMD_THRUSTER6_ON
        };

        if(argc == 3)
        {
            int t = atoi(argv[2]);
            if(t < 1 || t > 6)
            {
                printf("Bad thruster number: %d\n", t);
                close(fd);
                return -1;
            }

            thrusterCmd(fd, cmdList[t-1]);

        } else
        {
            for(i=0; i<6; i++)
                thrusterCmd(fd, cmdList[i]);
        }


        close(fd);
        return 0;
    }



    else if(strcmp(argv[1], "-baroff") == 0)
    {
        int i;
        unsigned int cmdList[]=
        {
            CMD_BAR1_OFF, CMD_BAR2_OFF, CMD_BAR3_OFF, CMD_BAR4_OFF,
            CMD_BAR5_OFF, CMD_BAR6_OFF, CMD_BAR7_OFF, CMD_BAR8_OFF
        };

        if(argc == 3)
        {
            int t = atoi(argv[2]);
            if(t < 1 || t > 8)
            {
                printf("Bad bar number: %d\n", t);
                close(fd);
                return -1;
            }

            barCmd(fd, cmdList[t-1]);

        } else
        {
            for(i=0; i<8; i++)
                barCmd(fd, cmdList[i]);
        }

        close(fd);
        return 0;
    }



    else if(strcmp(argv[1], "-baron") == 0)
    {
        int i;
        unsigned int cmdList[]=
        {
            CMD_BAR1_ON, CMD_BAR2_ON, CMD_BAR3_ON, CMD_BAR4_ON,
            CMD_BAR5_ON, CMD_BAR6_ON, CMD_BAR7_ON, CMD_BAR8_ON
        };

        if(argc == 3)
        {
            int t = atoi(argv[2]);
            if(t < 1 || t > 8)
            {
                printf("Bad bar number: %d\n", t);
                close(fd);
                return -1;
            }

            barCmd(fd, cmdList[t-1]);

        } else
        {
            for(i=0; i<8; i++)
                barCmd(fd, cmdList[i]);
        }

        close(fd);
        return 0;
    }


    else if(strcmp(argv[1], "-setbars") == 0)
    {
    	if(argc == 1)
	{
	    printf("Segmentation fault\n");
	    close(fd);
	    return -1;
	}

    	int t = atoi(argv[2]);

        setBarOutputs(fd, t);

        close(fd);
        return 0;
    }


    else if(strcmp(argv[1], "-noblink") == 0)
    {
        setAnimation(fd, ANIMATION_NONE);
        close(fd);
        return 0;
    }


    else if(strcmp(argv[1], "-redblue") == 0)
    {
        setAnimation(fd, ANIMATION_REDBLUE);
        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-redgreen") == 0)
    {
        setAnimation(fd, ANIMATION_REDGREEN);
        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-tstop") == 0)
    {
        setSpeeds(fd, 0, 0, 0, 0, 0, 0);
        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-hardkill") == 0)
    {
        hardKill(fd);
        close(fd);
        return 0;
    }


    else if(strcmp(argv[1], "-diagon") == 0)
    {
        setDiagnostics(fd, 1);
        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-diagoff") == 0)
    {
        setDiagnostics(fd, 0);
        close(fd);
        return 0;
    }


    else if(strcmp(argv[1], "-bloff") == 0)
    {
        lcdBacklight(fd, LCD_BL_OFF);
        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-blon") == 0)
    {
        lcdBacklight(fd, LCD_BL_ON);
        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-blfl") == 0)
    {
        lcdBacklight(fd, LCD_BL_FLASH);
        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-intpower") == 0)
    {
        switchToInternalPower(fd);
        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-extpower") == 0)
    {
        switchToExternalPower(fd);
        close(fd);
        return 0;
    }

    else if(strcmp(argv[1], "-c") == 0)
    {
        displayText(fd, 0, "");
        displayText(fd, 1, "");
        close(fd);
        return 0;
    }



    else if(strcmp(argv[1], "-s") == 0)
    {
        displayText(fd, 0, "Please attach   ");
        displayText(fd, 1, "Start magnet    ");

        while((readStatus(fd) & STATUS_STARTSW) == 0)
        {
            usleep(100*1000);
        }

        displayText(fd, 0, "Ready to start  ");
    	displayText(fd, 1, "");

    	while((readStatus(fd) & STATUS_STARTSW))
        {
            usleep(100*1000);
        }
        displayText(fd, 0, "Running...");
        close(fd);
        return 0;
    }


    else if(strcmp(argv[1], "-t") == 0)
    {
        displayText(fd, 0, argv[2]);

        if(argc == 4)
            displayText(fd, 1, argv[3]);
    }

    else if(strcmp(argv[1], "-dvlon") == 0)
    {
        int ret;
        if((ret = DVLOn(fd, 1)) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }

    else if(strcmp(argv[1], "-dvloff") == 0)
    {
        int ret;
        if((ret = DVLOn(fd, 0)) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }

    else if(strcmp(argv[1], "-magpwron") == 0)
    {
        int ret;
        if((ret = setMagPower(fd, 1)) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }

    else if(strcmp(argv[1], "-magpwroff") == 0)
    {
        int ret;
        if((ret = setMagPower(fd, 0)) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }

    else if(strcmp(argv[1], "-firetorp") == 0)
    {
        int ret;
        if(argc != 3) {
            printf("I need a torpedo number!\n");
        } else if((ret = fireTorpedo(fd, atoi(argv[2]))) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }

    else if(strcmp(argv[1], "-armtorp") == 0)
    {
        int ret;
        if(argc != 3) {
            printf("I need a torpedo number!\n");
        }
        else if((ret = armTorpedo(fd, atoi(argv[2]))) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }

    else if(strcmp(argv[1], "-voidtorp") == 0)
    {
        int ret;
        if(argc != 3) {
            printf("I need a torpedo number!\n");
        }
        else if((ret = voidTorpedo(fd, atoi(argv[2]))) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }

    else if(strcmp(argv[1], "-extgrabber") == 0)
    {
        int ret;
        if((ret = extendGrabber(fd)) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }

    else if(strcmp(argv[1], "-retgrabber") == 0)
    {
        int ret;
        if((ret = retractGrabber(fd)) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }

    else if(strcmp(argv[1], "-voidgrabber") == 0)
    {
        int ret;
        if((ret = voidGrabber(fd)) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }

    else if(strcmp(argv[1], "-voidall") == 0)
    {
        int ret;
        if((ret = voidSystem(fd)) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }

    else if(strcmp(argv[1], "-pneuoff") == 0)
    {
        int ret;
        if((ret = pneumaticsOff(fd)) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }

    else if(strcmp(argv[1], "-derpypwr") == 0)
    {
        int ret;

        if(argc != 3) {
            printf("No parameter for -derpypwr!\n");
        } else if(strcmp(argv[2], "on") == 0) {
            if((ret = setDerpyPower(fd, 1)) != SB_OK)
                printf("Error: %s\n", sbErrorToText(ret));
        } else if(strcmp(argv[2], "off") == 0) {
            if((ret = setDerpyPower(fd, 0)) != SB_OK)
                printf("Error: %s\n", sbErrorToText(ret));
        } else {
            printf("Invalid parameter for -derpypwr!\n");
        }
    }
    
    else if(strcmp(argv[1], "-setderpy") == 0)
    {
        int ret;
        if(argc != 3) {
            printf("No parameter for -setderpy!\n");
        } else {
            if((ret = setDerpySpeed(fd, atoi(argv[2]))) != SB_OK)
                printf("Error: %s\n", sbErrorToText(ret));
        }
    }

    else if(strcmp(argv[1], "-stopderpy") == 0)
    {
        int ret;
        if((ret = stopDerpy(fd)) != SB_OK)
            printf("Error: %s\n", sbErrorToText(ret));
    }
    
    else {
        printf("error: too much bullshit: %s\n", argv[1]);
        return -1;
    }

    close(fd);
    return 0;
}
Ejemplo n.º 23
0
bool AFramework::MTempMaster::run(){
    
    AString currentCmd;
    AString str;
    AString sensAdd;
    uint8 temp = 0;
    
    if(!m_flag){
        
        return false;
    }
    if(joinNetwork()){
            
            /* joinNetwork da direttamente l'output                             */
        if(!loadAll()){
            
            msg("Errore\nCaricamento", 0);
            while(1);
        }
        
            //cerco per due volte i sensori vicini
            readTemp(str);
            for(uint8 i = 0; i < _MTEMP_ROOM_VEC_SIZE; i++){

                str.clear();
                str = m_rooms[i].sensorAddress();
                sensAdd = "Ricerco\nSensore ";
                sensAdd += m_rooms[i].sensorAddress();
                msg(sensAdd);
                temp = 0;
                temp = readTemp(str);
                m_rooms[i].setTemperature(temp);
                if(temp != 0){
                    sensAdd.clear();
                    sensAdd += "Sensore ";
                    sensAdd += m_rooms[i].sensorAddress();
                    sensAdd += "\nTrovato";
                    msg(sensAdd);
                }else{
                    sensAdd.clear();
                    sensAdd += "Sensore ";
                    sensAdd += m_rooms[i].sensorAddress();
                    sensAdd += "\nNon trovato";
                    msg(sensAdd);
                }
            }
            
            msg("In ascolto...", 0);
            m_wifi->prepareForReceive();
            PortA.write(bit7, Hi);
            System::delay(1000);
            PortA.write(bit7, Lo);
            ATime time = System::aliveTime();
            time.addMinutes(1);
            while(1){
                
                if(m_wifi->waitForData(currentCmd, 0)){
                    
                    PortA.write(bit7, Hi);
                    commandExec(currentCmd);
                    PortA.write(bit7, Lo);
                    currentCmd.clear();
                }else{
                    if(System::aliveTime() <= time){
                        
                        programsManager(false);
                    }else{
                        
                        programsManager(true);
                        time.addMinutes(1);
                    }
                }
            }
    }else{
        /*  joinNetwork da direttamente l'output                                */
        while(1);
    }
}
Ejemplo n.º 24
0
bool AFramework::MTempMaster::programsManager(const bool read){                                                //da fare
    
    ADateTime currentClk;
    Program prg;
    AString str;
    
    if(!m_flag){
        
        return false;
    }
    
    if(read){
        for(uint8 i = 0; i < _MTEMP_ROOM_VEC_SIZE; i++){
            
            if(m_rooms[i].currentTemperature() != 0){           //se il sensore è vivo
                
                str.clear();
                str = m_rooms[i].sensorAddress();
                m_rooms[i].setTemperature(readTemp(str, 1000));      //aggiorno la temperatura
            }
        }
    }
    if(m_clk->isGood()){
        
        currentClk = m_clk->currentTime();

        for(uint8 i=0; i < _MTEMP_ROOM_VEC_SIZE; i++){

            prg = m_rooms[i].program(currentClk.Weekday());
            
            if(m_rooms[i].isAuto()){
                
                if(prg.isEnabled()){
                    
                    if( ((prg.startHours() == currentClk.hours() && prg.startMinutes() <= currentClk.minutes())
                                                             ||
                                           (prg.startHours() < currentClk.hours()))    
                                                             &&
                    ((prg.endHours() == currentClk.hours() && prg.endMinutes() >= currentClk.minutes())
                                                             ||
                                            (prg.endHours() > currentClk.hours()))) {
                        
                        if(m_rooms[i].currentTemperature() <= prg.targetTemperature()){
                           
                            m_rooms[i].on();
                        }else{
                            
                            m_rooms[i].off();
                        }    
                    }else{
                    
                        m_rooms[i].off();
                    }   
                }else{
                
                    m_rooms[i].off();
                }
            }
            
            if(m_rooms[i].isForcedOff()){           //se lo spegnimento è forzato

                m_rooms[i].off();               //metto off la porta
            }
            
            if(m_rooms[i].isForcedOn()){            

                m_rooms[i].on();                //metto on la porta

            }
        }
    }else{
        
        m_lcd->clear();
        m_lcd->write("Errore ora");
        System::delay(1000);
    }
    return false;
}
//Give me temperature in fahrenheit!
float Weather::readTempF()
{
  return((readTemp() * 1.8) + 32.0); // Convert celsius to fahrenheit
}
Ejemplo n.º 26
0
double Adafruit_MLX90614::readAmbientTempC(void) {
  return readTemp(MLX90614_TA);
}
Ejemplo n.º 27
0
double Adafruit_MLX90614::readObjectTempC(void) {
  return readTemp(MLX90614_TOBJ1);
}
Ejemplo n.º 28
0
double Adafruit_MLX90614::readAmbientTempF(void) {
  return (readTemp(MLX90614_TA) * 9 / 5) + 32;
}
Ejemplo n.º 29
0
double Adafruit_MLX90614::readObjectTempF(void) {
  return (readTemp(MLX90614_TOBJ1) * 9 / 5) + 32;
}
Ejemplo n.º 30
0
void updateTemp() {
	float t = readTemp();
	ss_setValueFloat(&Disp, t, 1);
}