Skip to content

Instantly share code, notes, and snippets.

@justjoheinz
Created November 27, 2011 11:55
Show Gist options
  • Save justjoheinz/1397466 to your computer and use it in GitHub Desktop.
Save justjoheinz/1397466 to your computer and use it in GitHub Desktop.
switch statement for ISR in Marlin firmware
switch(temp_state) {
case 0: // Prepare TEMP_0
#ifdef NORMAL_OP
#if (TEMP_0_PIN > -1)
#if TEMP_0_PIN > 7
ADCSRB = 1<<MUX5;
#endif
ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
ADCSRA |= 1<<ADSC; // Start conversion
#endif
#ifdef ULTIPANEL
buttons_check();
#endif
#endif
temp_state = 1;
break;
case 1: // Measure TEMP_0
#ifdef NORMAL_OP
#if (TEMP_0_PIN > -1)
raw_temp_0_value += ADC;
#endif
#endif
#ifndef NORMAL_OP
raw_temp_0_value += analogRead(TEMP_0_PIN);
#endif
temp_state = 2;
break;
case 2: // Prepare TEMP_1
#ifdef NORMAL_OP
#if (TEMP_1_PIN > -1)
#if TEMP_1_PIN > 7
ADCSRB = 1<<MUX5;
#endif
ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07));
ADCSRA |= 1<<ADSC; // Start conversion
#endif
#ifdef ULTIPANEL
buttons_check();
#endif
#endif
temp_state = 3;
break;
case 3: // Measure TEMP_1
#ifdef NORMAL_OP
#if (TEMP_1_PIN > -1)
raw_temp_1_value += ADC;
#endif
#endif
#ifndef NORMAL_OP
raw_temp_1_value += analogRead(TEMP_1_PIN);
#endif
temp_state = 4;
break;
case 4: // Prepare TEMP_2
#if (TEMP_2_PIN > -1)
#if TEMP_2_PIN > 7
ADCSRB = 1<<MUX5;
#endif
ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07));
ADCSRA |= 1<<ADSC; // Start conversion
#endif
#ifdef ULTIPANEL
buttons_check();
#endif
temp_state = 5;
break;
case 5: // Measure TEMP_2
#if (TEMP_2_PIN > -1)
raw_temp_2_value += ADC;
#endif
temp_state = 0;
temp_count++;
break;
default:
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Temp measurement error!");
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment