int main(void) { uart_init(); servos_init(); steppers_init(); pumps_init(); *idle_ddr &= ~idle_mask; *idle_port |= idle_mask; *setup_ddr &= ~setup_mask; *setup_port |= setup_mask; *ready_ddr |= ready_mask; *ready_port &= ~(ready_mask); sei(); uart_puts("PumpControl 0.1 ready\n\r"); uint8_t active_pump = 0; while(1) { pumps_run(); // Setup is active low if(!(*setup_pin & setup_mask)) { for(uint8_t i = 0; i < PumpCount; i++) { if(pump_states[i] != PUMP_SETUP) { pump_enter_setup(i); } } } // We only activate extruders if we are idle if(*idle_pin & idle_mask) { /* * Check if we need a new active pump * if full -> nice we've got a fresh one * if dispense -> still some stuff left in this one */ if(pump_states[active_pump] != PUMP_FULL && pump_states[active_pump] != PUMP_DISPENSE) { for(uint8_t i = 0; i < PumpCount; i++) { if(pump_states[i] == PUMP_FULL) { active_pump = i; break; } } } // We've selected a new active pump, now we need to start it if(pump_states[active_pump] == PUMP_FULL) { uart_debug_pump(active_pump, "is new acitve pump"); pump_enter_dispense(active_pump); } } /* * We are ready if we picked a new active pump and set it to dispense, * or if the old one still has stuff left in it and is in dispense. */ if(pump_states[active_pump] == PUMP_DISPENSE) { *ready_port |= ready_mask; } else { *ready_port &= ~(ready_mask); } /* * If we are idle, try to fill all pumps * If the active pump is also refilled, a other full one will be chosen * in the next iteration. */ if(!(*idle_pin & idle_mask)) { for(uint8_t i = 0; i < PumpCount; i++) { if(pump_states[i] == PUMP_DISPENSE) { uart_debug("Idle state detected, refilling"); pump_enter_fill(i); } } } } }
int main () { uart_init(38400); // initialisation of the buttons and leds // DDRE &= ~(0xF0); // buttons as input PORTE |= 0xF0; // activate internal pull-ups DDRA |= 0xFF; // leds as output /** CAN TESTING HERE **/ can_init(BITRATE_1_MBPS); sei(); // motor 1 can_filter_t filter0; filter0.id = 9; //filter0.mask = 0x7FF; filter0.mask = 0; filter0.flags.rtr = 0; can_set_filter(0, &filter0); PORTA ^= 0x02; /*while(true) { if (can_check_message()) { can_t msg; can_get_message(&msg); PORTA ^= 0x01; } }*/ PORTA = 0x01; _delay_ms(1000); PORTA = 0x02; int j = 0; while(true) { can_t frame; frame.id = 0x42; frame.flags.rtr = 0; frame.length = 8; for(int i = 0; i < 8; i++) { frame.data[i] = 42;//j + i; } j++; for (int k = 0; k < 8; k++) { if (can_send_message(&frame)) { PORTA &= ~0x0F; PORTA ^= 0xF0; } else { PORTA |= 0x0F; } } //_delay_ms(1); _delay_ms(1); } while(true) { if (can_check_message()) { PORTA ^= 0x03; /*can_t msg; can_get_message(&msg);*/ can_t message; can_get_message(&message); for (int i = 0; i < 8; i++) { uart_debug("%d: %d\n\r", i, message.data[i]); _delay_ms(5); } uart_debug("##########################\n\n\r"); } if (PINE < 0xF0) { can_t frame; frame.id = 0x09; frame.flags.rtr = 0; frame.length = 2; frame.data[0] = 0x2A; frame.data[1] = 0x06; if (can_send_message(&frame)) { PORTA &= ~0xE0; PORTA ^= 0x10; } else PORTA = 0xE0; uart_debug(".\n\r"); _delay_ms(500); } } /** ** ++++++++++ ** **/ return 0; }