コード例 #1
0
void ResetRTC ( )
{
	UB_RTC.std = 12;
	UB_RTC.min = 24;
	UB_RTC.sek = 36;
	UB_RTC.tag = 4;
	UB_RTC.monat = 1;
	UB_RTC.jahr = 14;
	UB_RTC.wotag = 6;
	UB_RTC_SetClock ( RTC_DEC );
};
コード例 #2
0
void SetRTCTime ( char * sTimeExpression )
{
	char  *yy, *mon, *dd, *hh, *mm, *ss;
	hh = strchr ( sTimeExpression, ' ' );
	if ( hh )
	{
		*hh = '\0';
		hh++;
		dd = sTimeExpression;
		mon = strchr ( dd, '.' );
		if ( 0 != mon )
		{
			*mon = '\0';
			mon++;
			yy = strchr ( mon, '.' );
			if ( 0 != yy )
			{
				*yy = '\0';
				yy++;
				UB_RTC.tag = atoi ( dd );
				UB_RTC.monat = atoi ( mon );
				UB_RTC.jahr = atoi ( yy );
				UB_RTC.wotag=5;
			};
		};
	}
	else
	{
		hh = sTimeExpression;
	};
	mm = strchr ( hh, ':' );
	if ( 0 != mm )
	{
		*mm = '\0';
		mm++;
		ss = strchr ( mm, ':' );
		if ( 0 != ss )
		{
			*ss = '\0';
			ss++;
			UB_RTC.std = atoi ( hh );
			UB_RTC.min = atoi ( mm );
			UB_RTC.sek = atoi ( ss );

			UB_RTC_SetClock ( RTC_DEC );
		};
	};
};
コード例 #3
0
ファイル: wc_IrRemoteProcessing.c プロジェクト: Jinzuu/wc_ws
//####################################################################################################
//################################## FUNCTIONS IMPLEMENTATION ########################################
//####################################################################################################
// Function that uses a received IR command to do stuff
void ProcessIrDataPacket( IRMP_DATA irPacket ){
	// Process packet only if it came from the right remote
	if ( irAddressFirstSeen == -1 )
		irAddressFirstSeen = irPacket.address;
	else if ( irAddressFirstSeen != irPacket.address )
		return;

	switch ( irPacket.command )
	{
		// Commands
		case IR_REMOTE_KEY_BRIGHTNESS_INC:
			AdjustBrightnessArray( 1, ambientBrightnessCurrent, ambientBrightnessLedDimmingFactors );
			break;
		case IR_REMOTE_KEY_BRIGHTNESS_DEC:
			AdjustBrightnessArray( 0, ambientBrightnessCurrent, ambientBrightnessLedDimmingFactors );
			break;
		case IR_REMOTE_KEY_OFF:
			gCurrentMatrixColor = WC_GetColor();
			WC_SetColor(WS2812_HSV_COL_OFF);
			break;
		case IR_REMOTE_KEY_ON:
			WC_SetColor(gCurrentMatrixColor);
			break;
//		case IR_REMOTE_KEY_FLASH:
//
//			break;
//		case IR_REMOTE_KEY_STROBE:
//
//			break;
//		case IR_REMOTE_KEY_FADE:
//
//			break;
#ifdef ENABLE_TESTMODE
		case IR_REMOTE_KEY_SMOOTH:
			UB_RTC = UB_RTC_GetClock( RTC_DEC );
			UB_RTC.min = ( UB_RTC.min + 3 ) % 60;
			UB_RTC.std = ( UB_RTC.std + 1 ) % 24;
			UB_RTC_SetClock( RTC_DEC );
			break;
#endif

		// Basic colors
		case IR_REMOTE_KEY_RED:
			WC_SetColor(WS2812_HSV_COL_RED);
			break;
		case IR_REMOTE_KEY_GREEN:
			WC_SetColor(WS2812_HSV_COL_GREEN);
			break;
		case IR_REMOTE_KEY_BLUE:
			WC_SetColor(WS2812_HSV_COL_BLUE);
			break;
		case IR_REMOTE_KEY_WHITE:
			WC_SetColor(WS2812_HSV_COL_WHITE);
			break;

		// Other colors
		case IR_REMOTE_KEY_ORANGE:
			WC_SetColor(WS2812_HSV_COL_ORANGE);
			break;
		case IR_REMOTE_KEY_LIGHTORANGE:
			WC_SetColor(WS2812_HSV_COL_LIGHTORANGE);
			break;
		case IR_REMOTE_KEY_DARKYELLOW:
			WC_SetColor(WS2812_HSV_COL_DARKYELLLOW);
			break;
		case IR_REMOTE_KEY_YELLOW:
			WC_SetColor(WS2812_HSV_COL_YELLOW);
			break;
		case IR_REMOTE_KEY_LIGHTGREEN:
			WC_SetColor(WS2812_HSV_COL_LIGHTGREEN);
			break;
		case IR_REMOTE_KEY_LIGHTGREENBLUE:
			WC_SetColor(WS2812_HSV_COL_LIGHTGREENBLUE);
			break;
		case IR_REMOTE_KEY_CYAN:
			WC_SetColor(WS2812_HSV_COL_CYAN);
			break;
		case IR_REMOTE_KEY_DARKGREENBLUE:
			WC_SetColor(WS2812_HSV_COL_DARKGREENBLUE);
			break;
		case IR_REMOTE_KEY_DARKBLUE:
			WC_SetColor(WS2812_HSV_COL_DARKBLUE);
			break;
		case IR_REMOTE_KEY_PURPLE:
			WC_SetColor(WS2812_HSV_COL_PURPLE);
			break;
		case IR_REMOTE_KEY_PINK:
			WC_SetColor(WS2812_HSV_COL_PINK);
			break;
		case IR_REMOTE_KEY_DARKPINK:
			WC_SetColor(WS2812_HSV_COL_DARKPINK);
			break;
	}

	// Save current color
	if ( irPacket.command != IR_REMOTE_KEY_OFF )
		gCurrentMatrixColor = WC_GetColor();
}
コード例 #4
0
ファイル: stm32_ub_rtc.c プロジェクト: Jinzuu/wc_ws
//--------------------------------------------------------------
// Init und Start der RTC
// Return Wert :
//  -> RTC_UNDEFINED = RTC war noch nicht initialisiert
//  -> RTC_INIT_OK   = RTC war schon initialisiert
//                     (aber noch nicht eingestellt)
//  -> RTC_TIME_OK   = RTC war schon eingestellt
//--------------------------------------------------------------
RTC_STATUS_t UB_RTC_Init(void)
{
  RTC_STATUS_t ret_wert=RTC_UNDEFINED;
  uint32_t status;

  // Clock enable fuer PWR
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  // Zugriff auf RTC freigeben
  PWR_BackupAccessCmd(ENABLE);

  // Test vom Status-Register
  status=RTC_ReadBackupRegister(RTC_STATUS_REG);
  if(status==RTC_STATUS_TIME_OK) {
    // wenn Uhrzeit schon eingestellt ist
    ret_wert=RTC_TIME_OK;
    UB_RTC.status=RTC_TIME_OK;

    // warte bis synconisiert
    RTC_WaitForSynchro();
    #if RTC_USE_WAKEUP_ISR==1
      RTC_ClearITPendingBit(RTC_IT_WUT);
      EXTI_ClearITPendingBit(EXTI_Line22);
    #endif

    // RTC auslesen
    UB_RTC_GetClock(RTC_DEC);
  }
  else if(status==RTC_STATUS_INIT_OK) {
    // wenn RTC schon initialisiert ist
    ret_wert=RTC_INIT_OK;
    UB_RTC.status=RTC_INIT_OK;

    // warte bis synconisiert
    RTC_WaitForSynchro();
    #if RTC_USE_WAKEUP_ISR==1
      RTC_ClearITPendingBit(RTC_IT_WUT);
      EXTI_ClearITPendingBit(EXTI_Line22);
    #endif

    // RTC auslesen
    UB_RTC_GetClock(RTC_DEC);
  }
  else {
    // wenn RTC noch nicht initialisiert ist
    ret_wert=RTC_UNDEFINED;
    UB_RTC.status=RTC_UNDEFINED;

    // RTC Konfig und start
    P_RTC_Config();

    // RTC zuruecksetzen auf (0:00:00 / 1.1.00)
    UB_RTC.std=0;
    UB_RTC.min=0;
    UB_RTC.sek=0;
    UB_RTC.tag=1;
    UB_RTC.monat=1;
    UB_RTC.jahr=0;
    UB_RTC.wotag=1;
    UB_RTC_SetClock(RTC_DEC);

    UB_RTC.status=RTC_INIT_OK;
  }
  
  return(ret_wert);
}
コード例 #5
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;
		}
	}

}
コード例 #6
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;
}