Example #1
0
//--------------------------------------------------------------
// Init aller Digital-Out Pins
//--------------------------------------------------------------
void UB_DigOut_Init(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;
  DOUT_NAME_t dig_pin;
  
  for(dig_pin=0;dig_pin<DOUT_ANZ;dig_pin++) {
    // Clock Enable
    RCC_AHB1PeriphClockCmd(DOUT_PIN[dig_pin].GPIO_CLK, ENABLE);

    // Config als Digital-Ausgang
    GPIO_InitStructure.GPIO_Pin = DOUT_PIN[dig_pin].GPIO_PIN;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(DOUT_PIN[dig_pin].GPIO_PORT, &GPIO_InitStructure);

    // Default Wert einstellen
    if(DOUT_PIN[dig_pin].GPIO_INIT==Bit_RESET) {
    	 UB_DigOut_Lo(dig_pin);
    }
    else {
    	UB_DigOut_Hi(dig_pin);
    }
  }
}
Example #2
0
//--------------------------------------------------------------
// Digital-Out Pin auf Lo oder Hi setzen
//--------------------------------------------------------------
void UB_DigOut_Pin(DOUT_NAME_t dig_pin,BitAction wert)
{
  if(wert==Bit_RESET) {
    UB_DigOut_Lo(dig_pin);
  }
  else {
    UB_DigOut_Hi(dig_pin);
  }
}
Example #3
0
/*****************************************
 *  MAIN
 *****************************************/
int main(void)
{
	SystemInit();
	UB_Systick_Init();

	// Init of UB libs
	UB_TIMER2_Init_FRQ( 100 );
	UB_TIMER5_Init_FRQ( 10000 );

	UB_Led_Init();

	UB_DigIn_Init();
	UB_DigOut_Init();

	UB_ADC1_SINGLE_Init();

	UB_RTC_Init();
	UB_RTC_SetWakeUpInterrupt(RTC_WAKEUP_5s);

	// Note: code needs to be reconfigured for Nucleo Board (Frequency of 96 MHz should also be checked)
	UB_WS2812_Init();
	WC_DisableAllElements();
	WC_SetColor( WS2812_HSV_COL_WHITE );
	WC_SetBrightness( 10 );
	WC_SetElement(WC_ELEMENT_ES, 1);
	WC_Refresh();

	UB_Uart_Init();
	esp8266_init();

	UB_Systick_Pause_ms(1000);

	// Indicate successful booting
	UB_Led_On( LED_GREEN );
	UB_Systick_Pause_s(1);
	UB_Led_Off( LED_GREEN );

	// Start timers and therefore cyclic actions in the call backs below
	UB_TIMER2_Start();
	UB_TIMER5_Start();


	UB_DigOut_Lo(DOUT_PB7);	// Set ground for LDR
	UB_DigOut_Lo(DOUT_PB9);	// Set PC9 low to start DCF module

	while(1) {
		// Handle word matrix refreshes
		if ( gWcIsToBeRefreshed == Bit_SET ){
			WC_Refresh();
			gWcIsToBeRefreshed = Bit_RESET;
		}

		// Check if update of time is necessary
#ifndef DISABLE_DCF
		if ( DcfTimeWasSetRecently() == Bit_RESET )
			gDcfRxInProgress = Bit_SET;
#endif

		// Handle IR remote
		if ( irmp_get_data( &irData ) )
			ProcessIrDataPacket( irData );

		// Read Ambient brightness and set LED brightness
		if ( gDcfRxInProgress == Bit_RESET ){
			ambientBrightnessCurrent = SlidingAverageOnLastValues( UB_ADC1_SINGLE_Read( ADC_PA1 ) );
			int brightnessToSet = 100.0 * GetBrightnessFactor( ambientBrightnessPoints, ambientBrightnessLedDimmingFactors, ambientBrightnessCurrent );
			if ( brightnessToSet < LED_BRIGHTNESS_OFF_THRESHOLD )
				WC_SetColor( WS2812_HSV_COL_OFF );
			else
				WC_SetBrightness( brightnessToSet );
			gWcIsToBeRefreshed = Bit_SET;
		}

		// Handle ESP8266 receive
		esp8266_handle_receive();
		if( esp8266_request_time_from_google() == 1 ) {
			UB_RTC = Esp8266_curTime;
			UB_RTC_SetClock( RTC_DEC );
			SetWordMatrix( UB_RTC_GetClock(RTC_DEC) );
			gWcIsToBeRefreshed = Bit_SET;
		}
	}

}