Quantcast
Channel: DIY Tiny OLED I2C full graphics controller
Viewing all articles
Browse latest Browse all 233

Re: DIY Tiny OLED I2C full graphics controller

$
0
0
Quote
n.glasson
It looks like the fix for the rotary encoder isn't quite 100% yet. I still find it works the wrong way in some places. For example when I am printing I can turn the speed up by twisting the knob upwards (at the front) when I am on the info screen, but when I select speed from the tune menu the knob needs to be twisted down to increase the speed...

Yes, you are right indeed! As I use my TinyOled just for checking the temperatures and adjusting the feed rate, I did not notice the problem with the value editing.. :(

So here is a new attempt. It's again just a patch for ultralcd.cpp, but this time you need to add the line "#define SIDE_ENCODER" to your Configuration.h to activate these changes.

If SIDE_ENCODER is defined, it will reverse the direction of rotation of the encoder in general (which should affect all the encoder operations) and then explicitly revert (back) the menu rotation, because that should be left as it is in the front encoder (i.e. left -> down, right -> up).

--- ultralcd.cpp.ori103 2015-05-08 18:47:27.000000000 +0200
+++ ultralcd.cpp        2015-07-04 11:18:42.000000000 +0200
@@ -127,10 +127,18 @@
   /**
    * START_MENU generates the init code for a menu function
    */
+
+  // reverse menu direction for encoders mounted on the side
+  #ifdef SIDE_ENCODER
+    #define MENU_DIR -1
+  #else
+    #define MENU_DIR 1
+  #endif
+
   #define START_MENU() do { \
     encoderRateMultiplierEnabled = false; \
-    if (encoderPosition > 0x8000) encoderPosition = 0; \
-    uint8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \
+    if (MENU_DIR*encoderPosition < 0) encoderPosition = 0; \
+    uint8_t encoderLine = MENU_DIR*encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \
     if (encoderLine < currentMenuViewOffset) currentMenuViewOffset = encoderLine; \
     uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
     bool wasClicked = LCD_CLICKED, itemSelected; \
@@ -204,7 +212,7 @@
     #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## args)
   #endif //!ENCODER_RATE_MULTIPLIER
   #define END_MENU() \
-      if (encoderLine >= _menuItemNr) { encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; }\
+      if (encoderLine >= _menuItemNr) { encoderPosition = MENU_DIR*(_menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1); encoderLine = _menuItemNr-1; }\
       if (encoderLine >= currentMenuViewOffset + LCD_HEIGHT) { currentMenuViewOffset = encoderLine - LCD_HEIGHT + 1; lcdDrawUpdate = 1; _lineNr = currentMenuViewOffset - 1; _drawLineNr = -1; } \
       } } while(0)
 
@@ -220,7 +228,7 @@
   uint8_t currentMenuViewOffset;              /* scroll offset in the current menu */
   millis_t next_button_update_ms;
   uint8_t lastEncoderBits;
-  uint32_t encoderPosition;
+  int32_t encoderPosition;
   #if (SDCARDDETECT > 0)
     bool lcd_oldcardstatus;
   #endif
@@ -1510,8 +1518,13 @@
 
   //manage encoder rotation
   uint8_t enc=0;
-  if (buttons & EN_A) enc |= B01;
-  if (buttons & EN_B) enc |= B10;
+  #ifndef SIDE_ENCODER
+    if (buttons & EN_A ) enc |= B01;
+    if (buttons & EN_B ) enc |= B10;
+  #else // for side encoders reverse rotation direction
+    if (buttons & EN_B ) enc |= B01;
+    if (buttons & EN_A ) enc |= B10;
+  #endif
   if (enc != lastEncoderBits) {
     switch(enc) {
       case encrot0:

I have done some quick tests on my systems here, and so far it seems to work. But as I only use the very basic stuff here, more testing is certainly needed.

PS: Note that I changed the type of encoderPosition from uint32_t to int32_t. This seems to be the more natural type for this variable, and there are many int() casts that could be removed as well, in case someone someday decides to integrate this patch to a Marlin source tree. However, if someone sees a problem with this type change, or knows a good reason why encoderPosition needs to be unsigned, please let me know.

Viewing all articles
Browse latest Browse all 233

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>