Add layer condition example to encoder callback function (#15490)
Co-authored-by: filterpaper <filterpaper@localhost>
This commit is contained in:
		
							parent
							
								
									dad7424bec
								
							
						
					
					
						commit
						067d94f0b6
					
				
					 1 changed files with 37 additions and 0 deletions
				
			
		|  | @ -87,6 +87,43 @@ bool encoder_update_user(uint8_t index, bool clockwise) { | |||
| 
 | ||||
| !> If you return `true`, this will allow the keyboard level code to run, as well.  Returning `false` will override the keyboard level code.  Depending on how the keyboard level function is set up.  | ||||
| 
 | ||||
| Layer conditions can also be used with the callback function like the following: | ||||
| 
 | ||||
| ```c | ||||
| bool encoder_update_user(uint8_t index, bool clockwise) { | ||||
|     if (get_highest_layer(layer_state|default_layer_state) > 0) { | ||||
|         if (index == 0) { | ||||
|             if (clockwise) { | ||||
|                 tap_code(KC_WH_D); | ||||
|             } else { | ||||
|                 tap_code(KC_WH_U); | ||||
|             } | ||||
|         } else if (index == 1) { | ||||
|             if (clockwise) { | ||||
|                 tap_code(KC_VOLU); | ||||
|             } else { | ||||
|                 tap_code(KC_VOLD); | ||||
|             } | ||||
|         } | ||||
|     } else {  /* Layer 0 */ | ||||
|         if (index == 0) { | ||||
|             if (clockwise) { | ||||
|                 tap_code(KC_PGDN); | ||||
|             } else { | ||||
|                 tap_code(KC_PGUP); | ||||
|             } | ||||
|         } else if (index == 1) { | ||||
|             if (clockwise) { | ||||
|                 tap_code(KC_DOWN); | ||||
|             } else { | ||||
|                 tap_code(KC_UP); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| ``` | ||||
| 
 | ||||
| ## Hardware | ||||
| 
 | ||||
| The A an B lines of the encoders should be wired directly to the MCU, and the C/common lines should be wired to ground. | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Albert Y
						Albert Y