Register / Login  |  Desktop view  |  Jump to bottom of page

tcMenu Arduinio library » u8glib2 print to display issue, as well as some timing issues

Author: shed
16/07/2020 22:50:46
Hi,

I'm trying to build a menu item that uses the takeOverDisplay() function.

The menu item looks like:
void CALLBACK_FUNCTION runDev(int id) {
  renderer.takeOverDisplay(devRunner);
}


And my function currently looks like this (messy as hell):
void devRunner(unsigned int encoderValue, RenderPressMode clicked) {
  int devTime = (menuSetDevTimeSeconds.getCurrentValue() + (menuSetDevTimeMinutes.getCurrentValue() * 60));
  int agitDur = (menuSetAgitationDurationSeconds.getCurrentValue() + (menuSetAgitationDurationMinutes.getCurrentValue() * 60));
  int agitInt = (menuSetAgitationIntervalSeconds.getCurrentValue() + (menuSetAgitationIntervalMinutes.getCurrentValue() * 60));
  int agitCount = 0;
  unsigned int agitMillis = 0;
  while (devTime >= 0) {
    if (interruptCounter > 0) {

      portENTER_CRITICAL(&timerMux);
      interruptCounter--;
      portEXIT_CRITICAL(&timerMux);

      // Decrement devTime
      devTime--;

      // if value reaches to zero, print done and wait for click
      if (devTime == 0) {
        timerAlarmDisable(timer);   // remeber we need to enable it again in start of next devrun
        Serial.println("Done");
        gfx.clear();
        gfx.print("Done!");
        // If encoder clicked, give back display
        if (clicked) {
          renderer.giveBackDisplay();
        }
      }
    }
    else {
      // Print time remaining to serial
      Serial.print("Dev Time Remaining: ");
      Serial.println(devTime);
      // Print time remaining to LCD
      String timeRemaining = (devTime / 60) + ":" + (devTime % 60) / 100;
      Serial.println(timeRemaining);
      gfx.clear();
      gfx.print("Developing..");
      gfx.setCursor(0, 32);
      gfx.print(timeRemaining);
      // If timer reaches the agitation interval, move servo and count down duration
      // If agitation frequency is zero, this means no occurance so ignore it
      if (agitInt, agitDur > 0) {
        if (devTime % agitInt == 0) {
          agitCount = agitDur;
        }
        if (millis() - agitMillis >= agitDur and agitCount > 0) {
          agitCount--;
          agitMillis = millis();
          moveServo();
        }
      }
    }
  }
}


Currently, nothing prints to the display.

I also have an issue with the section running 'moveServo()', where it only runs for around 2 seconds, rather than the 'agitDur' set from a combination of values from other menu options (menuSetAgitationDurationSeconds and menuSetAgitationDurationMinutes).

This is probably just something small, but the printing to display seems to clear the display, but print nothing.

Author: davetcc
17/07/2020 07:00:01
Firstly, the display remaining blank.

I think you are missing the u8g2 function to actually send the data to the display. These displays are buffered in memory, and only sent once all the rendering is done if you see what I mean. You need to call:

u8g2->sendBuffer();


Secondly, you don't need to do that timing loop in your function, tcMenu uses IoAbstraction library, and that has a task manager built in. Just start a task manager task for things that need to run on a schedule.

To schedule code to run every 200 millis until taskShouldRunAgain is false you'd call someTaskFunction once, then it woulld schedule itself until taskShouldRunAgain was false.

void someTaskFunction() {
   // do your task
   if(taskShouldRunAgain) taskManager.scheduleOnce(200, someTaskFunction);
}


To schedule something to repeat forever (or until cancelled)

auto taskId = taskManager.scheduleFixedRate(200, [] {
   // do your task here
});


There's lots of documentation around this: https://www.thecoderscorner.com/products/arduino-libraries/io-abstraction/




Register / Login  |  Desktop view  |  Jump to top of page