Hallo zusammen,
ist es erlaubt, innerhalb eines switch-Statements die switch-Variable zu
ändern? Konkret habe ich auf einem ATmega48 ein paar Zeilen, die jeweils
nur einmal durchlaufen werden sollen (label tohigh und tolow):
1 | void setup(void) {
|
2 | enum {tohigh,high,tolow,low,last} setup_mode = tohigh;
|
3 |
|
4 | uint8_t shi = eeprom_read_byte(&eeServoHigh);
|
5 | uint8_t slo = eeprom_read_byte(&eeServoLow);
|
6 | int8_t enc_this = encoder_get();
|
7 | int8_t enc_last = enc_this;
|
8 | uint8_t *enc_var = &shi;
|
9 |
|
10 | uint16_t kt = 0;
|
11 |
|
12 | while(1) {
|
13 | // Tastendruck interpretieren: Ausgang oder weiterschalten
|
14 | kt = key_time();
|
15 | if(kt) {
|
16 | if (kt > SHORT_LONG) {
|
17 | break;
|
18 | } else {
|
19 | setup_mode++;
|
20 | if (setup_mode==last) setup_mode = 0;
|
21 | }
|
22 | } // if(kt)
|
23 |
|
24 | // Drehgeber auswerten (nur Aenderungen)
|
25 | enc_this = encoder_get();
|
26 | *enc_var += enc_this-enc_last;
|
27 | enc_last = enc_this;
|
28 |
|
29 | switch (setup_mode) {
|
30 | tohigh: // High-Stellung einstellen (Start)
|
31 | led_mpx_putany((char[]) {0x00,LED_CHAR_I,LED_CHAR_H});
|
32 | enc_this = encoder_get();
|
33 | enc_last = enc_this;
|
34 | enc_var = &shi;
|
35 | setup_mode = high;
|
36 | /* FALLTHRU */
|
37 | high: // High-Stellung einstellen
|
38 | OCR1A = shi;
|
39 | break;
|
40 |
|
41 | tolow: // Low-Stellung einstellen (Start)
|
42 | led_mpx_putany((char[]) {0x00,LED_CHAR_O,LED_CHAR_L});
|
43 | enc_this = encoder_get();
|
44 | enc_last = enc_this;
|
45 | enc_var = &slo;
|
46 | setup_mode = low;
|
47 | /* FALLTHRU */
|
48 | low: // Low-Stellung einstellen
|
49 | OCR1A = slo;
|
50 | }
|
51 | } // while(1)
|
52 |
|
53 | eeprom_write_byte(&eeServoHigh, shi);
|
54 | eeprom_write_byte(&eeServoLow, slo);
|
55 | }
|
das beobachtete Verhalten weicht jedoch massiv davon ab, was ich
erreichen will (um genau zu sein: Er hängt sich beim Start der Routine
auf).
Die Routine led_mpx_putany((char[]) ) stellt beliebige Bitmuster auf
einer 3-Ziffern-7-Segment-Anzeige dar, die Funktion encoder_get(void)
liest einen Drehgeber kontinuierlich aus und der Rest sind
Standardfunktionen.
Die folgenden Warnungen des build-Prozesses machen mich mißstrauisch:
enumeration value 'tohigh' not handled in switch [-Wswitch]
enumeration value 'high' not handled in switch [-Wswitch]
enumeration value 'tolow' not handled in switch [-Wswitch]
enumeration value 'low' not handled in switch [-Wswitch]
enumeration value 'last' not handled in switch [-Wswitch]
label 'low' defined but not used [-Wunused-label]
label 'tolow' defined but not used [-Wunused-label]
label 'high' defined but not used [-Wunused-label]
label 'tohigh' defined but not used [-Wunused-label]
Viele Grüße
Nicolas