Panel* Panel::instance= nullptr;
+#define MENU_MODE 0
+#define CONTROL_MODE 1
+#define DIRECT_ENCODER_MODE 2
+
Panel::Panel()
{
instance= this;
// NOTE FIXME (WHY is it in menu only?) this code will not work if change is not 1,0,-1 anything greater (as in above case) will not work properly
static int encoder_counter = 0; // keeps track of absolute encoder position
static int last_encoder_click= 0; // last readfing of divided encoder count
+
int change = lcd->readEncoderDelta();
+
+ if(mode == DIRECT_ENCODER_MODE) {
+ if(change != 0 && encoder_cb_fnc) {
+ encoder_cb_fnc(change);
+ }
+ return 0;
+ }
+
encoder_counter += change;
int clicks= encoder_counter/this->encoder_click_resolution;
int delta= clicks - last_encoder_click; // the number of clicks this time
return 0;
}
-// Read and update encoder
+// Read and update encoder from a slow source
uint32_t Panel::encoder_tick(uint32_t dummy)
{
this->do_encoder = true;
return 0;
}
+// special mode where all encoder ticks are sent to the given function
+bool Panel::enter_direct_encoder_mode(encoder_cb_t fnc)
+{
+ encoder_cb_fnc= fnc;
+ this->mode= DIRECT_ENCODER_MODE;
+ return true;
+}
+
void Panel::on_set_public_data(void *argument)
{
PublicDataRequest *pdr = static_cast<PublicDataRequest *>(argument);
this->click_button.check_signal(but & BUTTON_SELECT);
}
- // If we are in menu mode and the position has changed
- if ( this->mode == MENU_MODE && this->counter_change() ) {
- this->menu_update();
- }
-
- // If we are in control mode
- if ( this->mode == CONTROL_MODE && this->counter_change() ) {
- this->control_value_update();
+ if(this->counter_change()) {
+ switch(this->mode) {
+ case MENU_MODE: // If we are in menu mode and the position has changed
+ this->menu_update();
+ break;
+ case CONTROL_MODE: // If we are in control mode
+ this->control_value_update();
+ break;
+ }
}
// If we must refresh
}
}
-
// Enter menu mode
void Panel::enter_menu_mode(bool force)
{
this->mode = MENU_MODE;
this->counter = &this->menu_selected_line;
this->menu_changed = force;
+ encoder_cb_fnc= nullptr;
}
void Panel::setup_menu(uint16_t rows)
this->counter = &this->control_normal_counter;
this->control_normal_counter = 0;
this->control_base_value = 0;
+ encoder_cb_fnc= nullptr;
return true;
}