/********************************************************************* Main Program Loop **********************************************************************/ int main() { /* Initializations */ debug_init(); /* This should be first. */ timer_init(); /* This should be before any GPIO activities. */ uint32 ret_val = bcm2835_init(); if ( ret_val == 0 ) { DEBUG_MSG_ERROR("bcm2835_init() failed."); } pwm_init(); pump_init(); therm_init(); pid_init(); pump_start(); /* Take temperature as input from console. */ float setpoint; printf("Set your desired temperature: "); scanf("%f", &setpoint); pid_update_temp_setpoint(setpoint); pid_gain_params pid_gain; pid_gain.k_p = 1; pid_gain.k_d = 1; pid_gain.k_i = 1; pid_gain.k_windup = 1; pid_set_gain(&pid_gain); /* Main Program Loop */ while (1) { pwm_run(); therm_capture(); pid_loop(); } pump_stop(); /* De-initializations */ pump_deinit(); pid_deinit(); pwm_deinit(); /* This should be after all GPIO activities. */ ret_val = bcm2835_close(); if ( ret_val == 0 ) { DEBUG_MSG_ERROR("bcm2835_close() failed."); } timer_deinit(); debug_deinit(); /* This should be last. */ return 0; }
void watering_system_init(uint64_t start_delay, uint64_t time_between_watering, uint32_t watering_cycles, uint32_t pumping_time, uint64_t dry_time){ pump_ptr p; p = (pump_ptr)_mem_alloc_zero(sizeof(pump)); pump_init(p); ws_params.pump = p; watering_system_update(start_delay, time_between_watering, watering_cycles, pumping_time, dry_time); }
/** * initialize - Performs all initialization procedures * * Returns a CHARLIE_STAT_* constant that indicates the succes or * failure of the initialization. */ static uint8_t initialize(void) { charlie.shutdown = FALSE; init_atmega(); init_ports(); debug_init_ports(); rs232_init(); spi_init_master(); i2c_init(); if (rtc_init()) { return CHARLIE_STAT_RTC_ERROR; } time_init(); time_sync_to_realtime(); sched_init(); if (card_init()) { return CHARLIE_STAT_CARD_ERROR; } if (fsys_init()) { return CHARLIE_STAT_FSYS_ERROR; } if (fsys_check_read_only()) { return CHARLIE_STAT_FSYS_READONLY; } cfg_load(); if (enc28j60_init(&cfg.mac_addr)) { return CHARLIE_STAT_NET_ERROR; } net_init(); adc_init(); sensors_init(); pump_init(); plants_init(); sei(); return CHARLIE_STAT_OK; }