[Logo] TCC discussion forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 


This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.

u8glib2 print to display issue, as well as some timing issues RSS feed
Forum Index » tcMenu Arduinio library
Author Message
shed


Joined: May 23, 2020
Messages: 5
Offline
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.
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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/
 
Forum Index » tcMenu Arduinio library
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.