diff --git a/extruder/extruder.c b/extruder/extruder.c index 6e97cd0..8200e48 100644 --- a/extruder/extruder.c +++ b/extruder/extruder.c @@ -202,13 +202,33 @@ int main (void) // check if we've had a new intercom packet if (intercom_flags & FLAG_NEW_RX) { intercom_flags &= ~FLAG_NEW_RX; - - send_temperature(0, temp_get(0)); - send_temperature(1, temp_get(1)); - temp_set(0, read_temperature(0)); - temp_set(1, read_temperature(1)); - - start_send(); + + switch (rx.packet.control_word) { + // M105- read temperatures + case 105: + send_temperature(0, temp_get(0)); + temp_set(0, read_temperature(0)); + send_temperature(1, temp_get(1)); + temp_set(1, read_temperature(1)); + start_send(); + break; + // M130 - set PID P factor + case 130: + pid_set_p(rx.packet.control_index, rx.packet.control_data_int32); + // M131 - set PID I factor + case 131: + pid_set_i(rx.packet.control_index, rx.packet.control_data_int32); + // M132 - set PID D factor + case 132: + pid_set_d(rx.packet.control_index, rx.packet.control_data_int32); + // M133 - set PID I limit + case 133: + pid_set_i_limit(rx.packet.control_index, rx.packet.control_data_int32); + // M134 - save PID values to eeprom + case 134: + heater_save_settings(); + break; + } } } } diff --git a/extruder/intercom.c b/extruder/intercom.c index bf89ece..ec02cac 100644 --- a/extruder/intercom.c +++ b/extruder/intercom.c @@ -11,31 +11,6 @@ #define START 0x55 -enum { - ERROR_BAD_CRC -} err_codes; - -typedef struct { - uint8_t start; - uint8_t dio; - uint8_t controller_num; - uint8_t control_word; - uint8_t control_index; - union { - int32_t control_data_int32; - uint32_t control_data_uint32; - float control_data_float; - uint16_t temp[2]; - }; - uint8_t err; - uint8_t crc; -} intercom_packet_t; - -typedef union { - intercom_packet_t packet; - uint8_t data[sizeof(intercom_packet_t)]; -} intercom_packet; - intercom_packet tx; // this packet will be send intercom_packet rx; // the last received packet with correct checksum intercom_packet _tx; // current packet in transmission diff --git a/extruder/intercom.h b/extruder/intercom.h index 0e826fe..988ccdc 100644 --- a/extruder/intercom.h +++ b/extruder/intercom.h @@ -12,6 +12,34 @@ #define disable_transmit() do { WRITE(TX_ENABLE_PIN,0); UCSR0B &= ~(MASK(TXCIE0) | MASK(UDRIE0)); UCSR0B |= MASK(RXEN0); } while(0) #endif +enum { + ERROR_BAD_CRC +} err_codes; + +typedef struct { + uint8_t start; + uint8_t dio; + uint8_t controller_num; + uint8_t control_word; + uint8_t control_index; + union { + int32_t control_data_int32; + uint32_t control_data_uint32; + float control_data_float; + uint16_t temp[2]; + }; + uint8_t err; + uint8_t crc; +} intercom_packet_t; + +typedef union { + intercom_packet_t packet; + uint8_t data[sizeof(intercom_packet_t)]; +} intercom_packet; + +extern intercom_packet tx; +extern intercom_packet rx; + // initialise serial subsystem void intercom_init(void); @@ -47,4 +75,6 @@ void start_send(void); #define FLAG_TX_FINISHED 8 extern volatile uint8_t intercom_flags; + + #endif /* _INTERCOM_H */ diff --git a/intercom.c b/intercom.c index bf89ece..ec02cac 100644 --- a/intercom.c +++ b/intercom.c @@ -11,31 +11,6 @@ #define START 0x55 -enum { - ERROR_BAD_CRC -} err_codes; - -typedef struct { - uint8_t start; - uint8_t dio; - uint8_t controller_num; - uint8_t control_word; - uint8_t control_index; - union { - int32_t control_data_int32; - uint32_t control_data_uint32; - float control_data_float; - uint16_t temp[2]; - }; - uint8_t err; - uint8_t crc; -} intercom_packet_t; - -typedef union { - intercom_packet_t packet; - uint8_t data[sizeof(intercom_packet_t)]; -} intercom_packet; - intercom_packet tx; // this packet will be send intercom_packet rx; // the last received packet with correct checksum intercom_packet _tx; // current packet in transmission diff --git a/intercom.h b/intercom.h index 0e826fe..988ccdc 100644 --- a/intercom.h +++ b/intercom.h @@ -12,6 +12,34 @@ #define disable_transmit() do { WRITE(TX_ENABLE_PIN,0); UCSR0B &= ~(MASK(TXCIE0) | MASK(UDRIE0)); UCSR0B |= MASK(RXEN0); } while(0) #endif +enum { + ERROR_BAD_CRC +} err_codes; + +typedef struct { + uint8_t start; + uint8_t dio; + uint8_t controller_num; + uint8_t control_word; + uint8_t control_index; + union { + int32_t control_data_int32; + uint32_t control_data_uint32; + float control_data_float; + uint16_t temp[2]; + }; + uint8_t err; + uint8_t crc; +} intercom_packet_t; + +typedef union { + intercom_packet_t packet; + uint8_t data[sizeof(intercom_packet_t)]; +} intercom_packet; + +extern intercom_packet tx; +extern intercom_packet rx; + // initialise serial subsystem void intercom_init(void); @@ -47,4 +75,6 @@ void start_send(void); #define FLAG_TX_FINISHED 8 extern volatile uint8_t intercom_flags; + + #endif /* _INTERCOM_H */