Projekt

Allgemein

Profil

Aktionen

Eval » Historie » Revision 28

« Zurück | Revision 28/46 (diff) | Weiter »
Maximilian Seesslen, 24.08.2022 14:13


Eval

Widgets

There is a ODesktop that holds a list of OScreens (or only the curent).
There is a OScreen that holds a list of OWidgets.
When the touch is pressed, the corresponding button can be determined.
An signal can be emmited.
An press-event can be queued, An release-event can be queued. An click-event can be queued if current button matches original pressed button.

  • OButton::draw(): completely draws the widget
  • OButton::update(): only draw status-relevant items, e.g. pressed, released, time changed...

All screens can be prepared at start.
A Screen can be active or inactive.

Only one screen is active plus an navigation-screen?

Touch

There is an touch class that helps converting raw values to X-Y-coordinates. touch
CTouch will emit signals "pressed, released, clicked" that can be connected to libocelli.

Watch

  • the OWatch class shows an clock with specific style, analog or digital

Example: Minutnik

  • Main screen; CWatch, Add-Button
  • Add-Screen
    • Espresso, Weisswurst, Weiches Ei, Hartes Ei, Nudeln, Pizza, Waschmaschine, Cancel; Height 32
  • Alarm Screen
  • Logo, Splash screen at boot time and stand-by-screen
  • Release v2.0.0: Mode-Screen: Minutnik, Clock, StopWatch

Example: CANDis

  • Main screen
    • Button for Light, Sensemux-Diagram, Activity (TV, Musik, Solder, Off), Miniminutnik
    • Header with Clock
  • Light-Screen
    • Power-Widget
    • Ok-Button
  • Clock-Screen (Screen saver)
    • Clock, Date, Temperature, Quick-Access-Buttons

Pointers

Like in Qt an widget has an parent.

Single App class vs. Screens

Having everything in an single class may be confusing. It should be splited to per-Screen-classes. The screens have access to the app.


enum EEvent
{
   pressed,
   released,
   clicked
};

class OWidget
{
   static GDisplay *m_display;
   public:
   CSignal signalClicked();

   virtual event(int x, int y, EEvent event);
}

OWidget::m_display=nullptr;

class OScreen
{
      CColor background;
      CList <OWidget *>m_widgets;
   public:
      virtual event(int x,int y, EEvent event)
      {
         OWidget *widget=getWidget(x,y);
         if(widget)
             widget->event( x, y, event);
      }
}

class Ocelli
{
   private:
      OScreen *currentScreen;
      OScreen *previousScreen;
      bool m_darkened=false;

   public:
      Ocelli(CGDisplay &display, CTouch &touch)
      {
         OWidget::m_pDisplay=&display;
         touch.signalClicked.connect( this, Ocelli::clicked );
      }
      setCurrentScreen(OScreen *screen);
      setPreviousScreen();
      event( int x, int y, EEvent event)
      {
         if(currentScreen)
         {
            currentScreen->event( x, y, event);
         }
      }
      eventLoop()
      {
         if(currentScreen)
         {
            currentScreen->eventLoop();
         }
      }
}

class CApp: Ocelli
{
   public:

      CScreenMain *screenMain;
      CScreenAlarm *screenAlarm;
      CApp()
      {
         addScreen( screenMain = new CScreenMain() );
      }
}

class CScreenClock: public OScreen
{
      CApp &app;
      OButton buttonAddTimer;
      OLabel labelTime;
      OLabel labelDate;
      lrtimer_t clickTimer;

   public:

      CScreenMain()
         :buttonAddTimer(this)
      {
      }
      virtual clicked(int x,int y)
      {
         clickTimer=ltNow();
         app.m_pwmBacklight.setPwmValue(800);
      }
      void eventLoop()
      {
         app.m_pwmBacklight.setPwmValue(100);
      }
      addItemPressed()
      {
         app.switchScreen( eDesktopItems );
      }
}

class CScreenMain: public OScreen
{
      CApp &app;

   public:

      virtual clicked(int x,int y);
}

class CScreenAlarm: public OScreen
{
      CApp &app;
      OLabel alarmText;
      lrtimer_t activationTimer;

   public:
      CScreenAlarm()
         :alarmText( centerX, centerY-200, "-")
      {
      }
      virtual avctivate() override
      {
         app.m_buzzer.setBeepMode(alarm);
         activationTimer=lrNow();
      }
      virtual clicked(int x,int y) override
      {
         // Dont allow to quit alarm immediately by accident 
         // when playing with the device; 500ms must elapse
         if( ! lrElapsed(activationTimer, MSECS_PER_SEC / 2 ) )
         {
            return;
         }
         app.m_buzzer.setBeepMode(nullptr);
         app.activatePreviousScreen();
      }
}

Von Maximilian Seesslen vor mehr als 2 Jahren aktualisiert · 28 Revisionen