/*
  TeleLed.h 
Oggetto per testare il funzionamento di Telepati; usato in
fase di sviluppo per scopi di debug.
*/

#ifndef TELELED_H_DEFINED
#define TELELED_H_DEFINED

#include "../lib/Packages/Packages.h"
#include <OPENR/OObject.h>
#include <OPENR/OSubject.h>
#include <OPENR/OObserver.h>
#include <OPENR/RCRegion.h>
#include "def.h"

#define TLLD_BEG_COLOR "\e[34m"
#define TLLD_END_COLOR "\e[0m"
#define TLLD_NAME TLLD_BEG_COLOR"TeleLed"TLLD_END_COLOR


using namespace std;

static const char* const LED3_LOCATOR[] = {
    "PRM:/r1/c1/c2/c3/la-LED3:la", // Face light1
    "PRM:/r1/c1/c2/c3/lb-LED3:lb", // Face light2
    "PRM:/r1/c1/c2/c3/lc-LED3:lc", // Face light3
    "PRM:/r1/c1/c2/c3/ld-LED3:ld", // Face light4
    "PRM:/r1/c1/c2/c3/le-LED3:le", // Face light5
    "PRM:/r1/c1/c2/c3/lf-LED3:lf", // Face light6
    "PRM:/r1/c1/c2/c3/lg-LED3:lg", // Face light7
    "PRM:/r1/c1/c2/c3/lh-LED3:lh", // Face light8
    "PRM:/r1/c1/c2/c3/li-LED3:li", // Face light9
    "PRM:/r1/c1/c2/c3/lj-LED3:lj", // Face light10
    "PRM:/r1/c1/c2/c3/lk-LED3:lk", // Face light11
    "PRM:/r1/c1/c2/c3/ll-LED3:ll", // Face light12
    "PRM:/r1/c1/c2/c3/lm-LED3:lm", // Face light13
    "PRM:/r1/c1/c2/c3/ln-LED3:ln"  // Face light14
};

class TeleLed : public OObject {
 public:
    
  TeleLed();
  virtual ~TeleLed();
  
  OSubject*    subject[numOfSubject];
  OObserver*   observer[numOfObserver];
   
  virtual OStatus DoInit   (const OSystemEvent& event);
  virtual OStatus DoStart  (const OSystemEvent& event);
  virtual OStatus DoStop   (const OSystemEvent& event);
  virtual OStatus DoDestroy(const OSystemEvent& event);
  
  void ObjReady(const OReadyEvent& event);
  void Receive(const ONotifyEvent& event);
  
  void Ready(const OReadyEvent& event);
  
 private:
  void OpenPrimitives();
  void NewCommandVectorData();
  RCRegion* FindFreeRegion();
  void SetLED3Value(RCRegion* rgn, sword intensity, OLED3Mode mode);

  static const size_t NUM_LEDS           = 14;
  static const size_t NUM_COMMAND_VECTOR = 2;
  static const int    MAX_LEVEL          = 15;
  static const int    POSITIVE_SLOPE     = 1;
  static const int    NEGATIVE_SLOPE     = -1;
  
  OPrimitiveID          ledID[NUM_LEDS];
  RCRegion*             region[NUM_COMMAND_VECTOR];
  
  int aibos;  /**<numero di aibo nel campo*/
  AiboInfoPkg* info; /**<AiboInfoPkg aggiornato*/
  int* msgToSend; /**< Numero di messaggi da spedire perogni aibo*/
  bool* canSend;
  int rubbia;
  int sendMsg;
  int recvMsg;
};
#endif  //TELELED_H_DEFINED:
