/*--------------------------------------------------------------------------------------------------------------------------------------------------- * MAIN: main routine *--------------------------------------------------------------------------------------------------------------------------------------------------- */ //int main(void) __attribute__((noreturn)); /* saves some Bytes but produces warning */ int main (void) { static DATETIME datetime; uart_init(); // initialize uart log_main("Init...\n"); wcEeprom_init(); # if (DCF_PRESENT == 1) dcf77_init (); // initialize dcf77 # endif display_init (); // initialize display { // local to save stack uint8_t i2c_errorcode; uint8_t i2c_status; if (! i2c_rtc_init (&i2c_errorcode, &i2c_status)) // initialize rtc { log_main("RTC init failed\n"); // TODO: error handling } } ldr_init (); // initialize ldr pwm_init (); // initialize pwm irmp_init (); // initialize irmp timer_init (); // initialize timer user_init(); sei (); // enable interrupts pwm_on (); // switch on pwm //pwm_set_base_brightness_step(MAX_PWM_STEPS-1); /// @todo remove if ldr stuff is working log_main("Init finished\n"); for (;;) { handle_brightness (); handle_datetime (&datetime); // check & display new time, if necessary handle_ir_code (); // handle ir user interaction # if (DCF_PRESENT == 1) if (dcf77_getDateTime (&datetime)) // handle dcf77 examination (enable_dcf77_ISR must be TRUE to enable analysis) { i2c_rtc_write (&datetime); soft_seconds = datetime.ss; user_setNewTime (&datetime); } # endif /** (DCF_PRESENT == 1) */ } }
int main ( int argc, char **argv ) { char *dev_serial = getenv("BC_DEV"); if(dev_serial == NULL) { dev_serial = "/dev/ttyACM0"; } fd = open ( dev_serial, O_RDWR | O_NOCTTY ); if ( fd < 0 ) { // TODO: THROW error fprintf(stderr, "Failed to open device: %s\n", dev_serial); return EXIT_FAILURE; } // save status port settings. tcgetattr ( fd, &oldtio ); // Setup the serial port. struct termios newtio = { 0, }; newtio.c_cflag = baudrate | CS8 | CREAD | PARODD; newtio.c_iflag = 0; newtio.c_oflag = 0; newtio.c_lflag = 0; //ICANON; newtio.c_cc[VMIN] = 1; newtio.c_cc[VTIME] = 0; tcflush ( fd, TCIFLUSH | TCIOFLUSH ); tcsetattr ( fd, TCSANOW, &newtio ); if( argc == 1) { printf_information(); } else if (argc > 1 ) { const char *command = argv[1]; // Alarm if(strcasecmp(command, "alarm") == 0 ) { handle_alarm( argc-2, &argv[2]); // Initialize } else if (strcasecmp(command, "init") == 0) { handle_init(); } else if(strcasecmp(command, "temperature") == 0 ) { handle_temperature(); } else if(strcasecmp(command, "drift") == 0 ) { handle_drift(); } else if ( strcasecmp(command, "brightness") == 0) { handle_brightness(argc-2, &argv[2]); } else if ( strcasecmp(command, "test") == 0){ handle_test(); } } sync(fd); // tcsetattr ( fd, TCSANOW, &oldtio ); close(fd); return EXIT_SUCCESS; }