Add 2-axis joystick to Marlin? June 28, 2015 11:35PM |
Registered: 9 years ago Posts: 70 |
Re: Add 2-axis joystick to Marlin? June 29, 2015 09:01PM |
Registered: 9 years ago Posts: 70 |
Re: Add 2-axis joystick to Marlin? June 30, 2015 02:03AM |
Registered: 8 years ago Posts: 5,232 |
Re: Add 2-axis joystick to Marlin? June 30, 2015 11:24AM |
Registered: 9 years ago Posts: 70 |
Quote
o_lampe
I´m not sure, if you have to read the joystick as analog input. Just read it as a digital value. Everything below the threshold is "0", everything above is "1".
The main problem you´ll find is:
the encoder provides pulses, but the joystick doesn´t.
How do you implement up/down function?
You´d have to rewrite the hole LCD-menue or borrow it from the sprinter-FW? Marlin is an offsprint of sprinter AFAIK. Maybe it is worth looking into the custom sprinter code?
-Olaf
void lcd_buttons_update() { #ifdef NEWPANEL uint8_t newbutton=0; if(READ(BTN_EN1)==0) newbutton|=EN_A; if(READ(BTN_EN2)==0) newbutton|=EN_B; #if BTN_ENC > 0 if((blocking_enc>1; if(READ(SHIFT_OUT)) newbutton_reprapworld_keypad|=(1<<7); WRITE(SHIFT_CLK,HIGH); WRITE(SHIFT_CLK,LOW); } buttons_reprapworld_keypad=~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0 #endif #else //read it from the shift register uint8_t newbutton=0; WRITE(SHIFT_LD,LOW); WRITE(SHIFT_LD,HIGH); unsigned char tmp_buttons=0; for(int8_t i=0;i<8;i++) { newbutton = newbutton>>1; if(READ(SHIFT_OUT)) newbutton|=(1<<7); WRITE(SHIFT_CLK,HIGH); WRITE(SHIFT_CLK,LOW); } buttons=~newbutton; //invert it, because a pressed switch produces a logical 0 #endif//!NEWPANEL //manage encoder rotation uint8_t enc=0; if (buttons & EN_A) enc |= B01; if (buttons & EN_ enc |= B10; if(enc != lastEncoderBits) { switch(enc) { case encrot0: if(lastEncoderBits==encrot3) encoderDiff++; else if(lastEncoderBits==encrot1) encoderDiff--; break; case encrot1: if(lastEncoderBits==encrot0) encoderDiff++; else if(lastEncoderBits==encrot2) encoderDiff--; break; case encrot2: if(lastEncoderBits==encrot1) encoderDiff++; else if(lastEncoderBits==encrot3) encoderDiff--; break; case encrot3: if(lastEncoderBits==encrot2) encoderDiff++; else if(lastEncoderBits==encrot0) encoderDiff--; break; } } lastEncoderBits = enc; }