Exemplo n.º 1
0
void USER_FUNC changeSwitchStatus(SWITCH_PIN_FLAG switchFlag)
{
	if(getSwitchStatus(switchFlag) == SWITCH_OPEN)
	{
		setSwitchStatus(SWITCH_CLOSE, switchFlag);
	}
	else
	{
		setSwitchStatus(SWITCH_OPEN, switchFlag);
	}
}
bool CloudWatcherController::getAllData(CloudWatcherData *cwd) {
  int skyTemperature[NUMBER_OF_READS];
  int sensorTemperature[NUMBER_OF_READS];
  int rainFrequency[NUMBER_OF_READS];

  int internalSupplyVoltage[NUMBER_OF_READS];
  int ambientTemperature[NUMBER_OF_READS];
  int ldrValue[NUMBER_OF_READS];
  int rainSensorTemperature[NUMBER_OF_READS];

  int check = 0;

  totalReadings++;

  timeval begin;
  gettimeofday(&begin, NULL);


  for (int i = 0 ; i < NUMBER_OF_READS ; i++) {
    check = getIRSkyTemperature(&skyTemperature[i]);

    if (!check) {
      return false;
    }

    check = getIRSensorTemperature(&sensorTemperature[i]);

    if (!check) {
      return false;
    }

    check = getRainFrequency(&rainFrequency[i]);

    if (!check) {
      return false;
    }

    check = getValues(&internalSupplyVoltage[i], &ambientTemperature[i], &ldrValue[i], &rainSensorTemperature[i]);

    if (!check) {
      return false;
    }
  }

  timeval end;
  gettimeofday(&end, NULL);

  float rc = float(end.tv_sec - begin.tv_sec) + float(end.tv_usec - begin.tv_usec) / 1000000.0;

  cwd->readCycle = rc;

  cwd->sky = aggregateInts(skyTemperature, NUMBER_OF_READS);
  cwd->sensor = aggregateInts(sensorTemperature, NUMBER_OF_READS);
  cwd->rain = aggregateInts(rainFrequency, NUMBER_OF_READS);
  cwd->supply = aggregateInts(internalSupplyVoltage, NUMBER_OF_READS);
  cwd->ambient = aggregateInts(ambientTemperature, NUMBER_OF_READS);
  cwd->ldr = aggregateInts(ldrValue, NUMBER_OF_READS);
  cwd->rainTemperature = aggregateInts(rainSensorTemperature, NUMBER_OF_READS);
  cwd->totalReadings = totalReadings;

  check = getIRErrors(&cwd->firstByteErrors, &cwd->commandByteErrors, &cwd->secondByteErrors, &cwd->pecByteErrors);

  if (!check) {
    return false;
  }

  cwd->internalErrors = cwd->firstByteErrors + cwd->commandByteErrors + cwd-> secondByteErrors + cwd->pecByteErrors;

  check = getPWMDutyCycle(&cwd->rainHeater);

  if (!check) {
    return false;
  }

  check = getSwitchStatus(&cwd->switchStatus);

  if (!check) {
    return false;
  }

  return true;
}
Exemplo n.º 3
0
void USER_FUNC setSwitchStatus(SWITCH_STATUS action, SWITCH_PIN_FLAG switchFlag)
{
	SWITCH_STATUS switchStatus = getSwitchStatus(switchFlag);
#if !defined(LIGHT_CHENGE_SUPPORT) && !defined(CHANGE_BRIGHTNESS_SUPPORT)
	S32 fid;


	fid = lum_getSwitchFlag(switchFlag);	
#endif

	if(SWITCH_OPEN == action)
	{
#ifdef LIGHT_CHENGE_SUPPORT
		lum_lightChangeLevel(MAX_LIGHT_LEVEL);
		if(g_lightDimStatus != GET_AC_FREQ)
		{
			hfgpio_fenable_interrupt(HFGPIO_F_ZERO_DETECTER);
		}
#elif defined(CHANGE_BRIGHTNESS_SUPPORT)
		lum_setLedLightStatus(LIGHT_LED_OPEN);
#else
		hfgpio_fset_out_high(fid);
#endif
#ifdef SPECIAL_RELAY_SUPPORT
		hfgpio_fset_out_high(HFGPIO_F_RELAY_2);
		hfgpio_fset_out_low(HFGPIO_F_RELAY_1);
		startSpecialRelayTimer();
#endif
#ifdef DEVICE_RELAY_LED_SUPPORT
		hfgpio_fset_out_low(HFGPIO_F_RELAY_LED);
#endif
	}
	else
	{
#ifdef LIGHT_CHENGE_SUPPORT
		lum_lightChangeLevel(0);
		if(g_lightDimStatus != GET_AC_FREQ)
		{
			hfgpio_fdisable_interrupt(HFGPIO_F_ZERO_DETECTER);
		}
#elif defined(CHANGE_BRIGHTNESS_SUPPORT)
		lum_setLedLightStatus(LIGHT_LED_CLOSE);
#else
		hfgpio_fset_out_low(fid);
#endif
#ifdef SPECIAL_RELAY_SUPPORT
		hfgpio_fset_out_low(HFGPIO_F_RELAY_2);
		hfgpio_fset_out_high(HFGPIO_F_RELAY_1);
		startSpecialRelayTimer();
#endif
#ifdef DEVICE_RELAY_LED_SUPPORT
		hfgpio_fset_out_high(HFGPIO_F_RELAY_LED);
#endif
	}
	if(action != switchStatus)
	{
		GPIO_CHANGE_REPORT data;


		data.action = action;
		data.pinFlag = switchFlag;

		if(!lum_bEnterFactoryTest())
		{
			insertLocalMsgToList(MSG_LOCAL_EVENT, (U8*)(&data), sizeof(GPIO_CHANGE_REPORT), MSG_CMD_REPORT_GPIO_CHANGE);
		}
	}
}
Exemplo n.º 4
0
int main (int argc, char *argv[])
{
  char msg[32] = "\n\rHallo Welt!\n\r";
  char msg_key1[32]		 	= " Pushbutton 1 ";
  char msg_key2[32] 		= " Pushbutton 2 ";
  char msg_key3[32] 		= " Pushbutton 3 ";
  char msg_pos1[32]			= "\r";
	char msg_tmp[32] = "";

  UART_Cfg cfg;
    
  // Initialize peripheral components ...
  // UART
  cfg.fclk = 50000000;
  cfg.baud = UART_CFG_BAUD_115200;
  cfg.frame.msg_len = UART_CFG_MSG_LEN_8;
  cfg.frame.parity = UART_CFG_PARITY_EVEN;
  cfg.frame.stop_bits = UART_CFG_STOP_BITS_1;
  UART_init (cfg);

  // 7-Segment
  dis7seg_initHandle(&display_handle, DISP7SEG_BADDR, 8);
	dis7seg_displayHexUInt32(&display_handle, 0, 0x00000042);
  
	
	uint32_t keys, keys_old, led_port;
	uint8_t i;

	keys_old = 0;
	led_port = 0;
	

  UART_write(0, msg, strlen(msg));

  //register interrupt to line 2
  REGISTER_INTERRUPT(isr, 2);
  // unmask interrupt line 2
  UMASKI(2);
  // globally enable interrupts
  SEI();

  // timer 80000 ticks = 1ms, 80 ticks = 1s
  config_timer(50000000, 0);
  timer_initHandle(&timer_handle, TIMER_BADDR);
  start_timer();

  while(1) {
		// pushbuttons
		keys = getButtonStatus();
		if(keys != keys_old) {
			if(keys & (1<<BUTTON3)) {
				UART_write(0, msg_key3, strlen(msg_key3));
			}
			if(keys & (1<<BUTTON2)) {
				UART_write(0, msg_key2, strlen(msg_key2));
			}
			if(keys & (1<<BUTTON1)) {
				UART_write(0, msg_key1, strlen(msg_key1));
			}
		}
		keys_old = keys;
		// switches & leds
		led_port = 0;
		for(i=0; i<18; i++)
		{
			if (getSwitchStatus(i) == SW_ON) {
				led_port |= (SW_ON<<i);
				//(void) sprintf(msg_tmp, "KEY %i ON", i);
				//UART_write(0, msg_tmp, strlen(msg_tmp));
			}	
		} 
		UART_write(0, msg_pos1, strlen(msg_pos1));

		// leds
		//setLeds(led_port);
	}


  return 0;
}