Esempio n. 1
0
void WC_Refresh()
{
    int i;
    for( i=0; i<T_WC_ELEMENT_COUNT; ++i ) {
        if( WC_CONFIG[i].ENABLED == 1 ) {
            WC_SetElement(WC_CONFIG[i].ELEMENT_NAME, 1);
        }
        else {
            WC_SetElement(WC_CONFIG[i].ELEMENT_NAME, 0);
        }
    }

    UB_WS2812_Refresh();
}
Esempio n. 2
0
void WC_SetElement(T_WC_ELEMENT element, int enable)
{
    int index = WC_CONFIG[element].START_INDEX;
    int length = WC_CONFIG[element].LENGTH;
    if( enable == 1 ) {
        WC_CONFIG[element].ENABLED = 1;
        while(length-- > 0 ) {
            UB_WS2812_One_Led_HSV(index++, WC_Colour, 0);
        }
    } else {
        WC_CONFIG[element].ENABLED = 0;
        while(length-- > 0 ) {
            UB_WS2812_One_Led_HSV(index++, WS2812_HSV_COL_OFF, 0);
        }
    }

    // Because the segments "ES IST" are separated by one LED, individual handling
    // is required
    if( element == WC_ELEMENT_ES ) {
        WC_SetElement(WC_ELEMENT_IST, enable);
    }
}
Esempio n. 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;
		}
	}

}
Esempio n. 4
0
/*****************************************
 *  Timer 2 Callback @100Hz
 *  - Used for: DCF77 sampling
 *****************************************/
void UB_TIMER2_ISR_CallBack( void )
{
#ifdef DISABLE_DCF
	return;
#endif

	gDcfInputState = UB_DigIn_Read( DIN_PB8 );
	if ( gDcfInputState == Bit_SET )
		UB_Led_On( LED_GREEN );
	else
		UB_Led_Off( LED_GREEN );

#ifdef ENABLE_TESTMODE	//Testing: Just set a time
	gLastSuccessfulDcfRxTime.jahr = 0;
	gLastSuccessfulDcfRxTime.monat = 1;
	gLastSuccessfulDcfRxTime.tag = 1;
	gLastSuccessfulDcfRxTime.wotag = 1;
	gLastSuccessfulDcfRxTime.sek = 0;
	gLastSuccessfulDcfRxTime.min = 0;
	gLastSuccessfulDcfRxTime.std = 0;

	WC_SetElement(WC_ELEMENT_ES, 1);
	SetWordMatrix( UB_RTC_GetClock(RTC_DEC) );
	gDcfRxInProgress = Bit_RESET;
	gDcfRxWasSuccesful = Bit_SET;
	gCurrentMatrixColor = WS2812_HSV_COL_WHITE;

#else
	dcf77_SignalState_t dcf77state = Dcf77_ProcessSignal( gDcfInputState );
	if ( dcf77state == dcf77_TimeRxSuccess )
	{
		gLastSuccessfulDcfRxTime = Dcf77_GetTime();
		UB_RTC = gLastSuccessfulDcfRxTime;
		UB_RTC_SetClock( RTC_DEC );
		gDcfRxWasSuccesful = Bit_SET;

		// Set word matrix directly after first DCF RX
		if ( gDcfRxInProgress == Bit_SET ){
			WC_SetElement(WC_ELEMENT_ES, 1);
			SetWordMatrix( UB_RTC_GetClock(RTC_DEC) );
			gDcfRxInProgress = Bit_RESET;
			gCurrentMatrixColor = WS2812_HSV_COL_WHITE;
		}
	}
	// Indicate status of DCF reception by FUNK in red/green while DCF RX in progress
	if ( gDcfRxWasSuccesful == Bit_RESET ){
		WC_DisableAllElements();
		WC_SetElement( WC_ELEMENT_FUNK, 1 );
		if ( dcf77state == dcf77_RxStateUnkown )
			WC_SetColor( WS2812_HSV_COL_RED );
		else if ( dcf77state == dcf77_RxStateGood )
			WC_SetColor( WS2812_HSV_COL_GREEN );

		WC_SetBrightness( 50 );
		WC_SetElement( WC_ELEMENT_FUNK, 1 );
	}
	else{
		// Disable FUNK and set normal color
		WC_SetElement( WC_ELEMENT_FUNK, 0 );
		WC_SetColor( gCurrentMatrixColor );
	}
#endif

	gWcIsToBeRefreshed = Bit_SET;
}