Timer not triggering?



  • Following the examples, I added a simple timer to change the color of the text label in the Hello World starter project.

    //inside AppController::AppController()
        Timer timr(1500);
        timr.setCallback<AppController>(this, &AppController::timerCallback);
        timr.Start();
    

    which ties into:

    void AppController::timerCallback()
    {
        // set another text color
        int newColorCase = rand() % 6;
        printf("new color choice: %i\t\n", newColorCase);
        //...
        helloLabel.repaint();
    }
    

    But the color never changes, and minicom never sees the debug statements.

    What am I missing, please?

    Thanks!



  • @pktm I don't know about your serial connection except usually it's the bit rate that isn't set properly. It should be 9600bps. As to why your text label doesn't change colour, I think you're missing a call to setForeground() on your text object, and also you're generating a number between 0 and 5 which won't make much of a difference. The resolution I believe is 5 bits (or is it 6?) so you need to take mod 32.

    -- maz



  • @maz Thanks for the reply.

    I changed the bit rate in minicom, but I'm still not seeing any output, frustratingly.

    I guess I should have posted the full switch block, but it doesn't use the rand() value directly:

        switch (newColorCase) {
            case 0:
                helloLabel.setTextColor(display::WetAsphaltColor);
                break;
    //...
    

    Thanks!



  • @pktm OK, so the trick with minicom was related to settings. Not only did I have to put it to 9600bps, I also had to turn hardware flow control off and save the settings as minicom defaults. ($ minicom -s).

    I'm documenting that here to help others, and I'll add it to the serial debug article in the docs, too.



  • Now I've got a different problem, in that I appear to have bricked my device, and can't get it to respond to my reset. (With paperclip and user button.)



  • In relation to the timer, there is an issue with your code:

    AppController::AppController()
    {
        Timer timr(1500);   // Creates a timer on the stack
        timr.setCallback<AppController>(this, &AppController::timerCallback);
        timr.Start();
    } // The stack frame is popped, along with the timer
    

    The variable timrdoes not stick around to call you function, it gets a dealloc when the function returns. Add your timer as a member variable on AppController, and change the code to this:

    app_controller.h:

    class AppController : mono::IApplication
    {
         // member variables
        mono::Timer timr;
    }
    

    app_controller.cpp:

    // Inside AppController constructor
    timr.setInterval(1500);
    timr.setCallback<AppController>(this, &AppController::timerCallback);
    timr.Start();
    

    I can't see why changing the baudrate or H/W flow control should affect this. In fact, I find that the baudrate set in minicom does not have any effect in general :-/


Log in to reply