Пример #1
0
void HueSlider::setColor(const QColor& color)
{
    p->saturation = color.saturationF();
    p->value = color.valueF();
    p->updateGradient();
    setColorHue(color.hueF());
}
Пример #2
0
Lamp::Lamp(unsigned char ledPin, unsigned char audioPin)
{

  _menuIndex =0x0;
  _menuDepth = 0;

  this->lpin = ledPin;
  this->audPin = audioPin;
  this->LEDCycleRising = true;
  this->LEDPWM = 0;
  this->cycleStep = 1;  
  this->_sleeping = false;
  this->_lampOn = true;
  fadeTimer = Metro(1);

  _alarming = false;
  tAlarmStarted = 128;

  //Default Values if Lamp is starting for the first time
  if (!isInit())
  {
    setDisplayMode(0x1);
    setAlarmAM(true);
    setAlarmHour(7);
    setAlarmMin(30);
    setAlarmOn(false);

    //setLCDBrightness(255);
    setLampBrightness(128);
    setCycleFadeTime(15);
    setCycleHoldTime(15);
    setCycleSteps(15);
    setRandomFadeTime(15);
    setRandomHoldTime(15);
    setColorHue(150);
    setColorSat(150);

  }

  drawMenu(menuPosition());
}
Пример #3
0
void Lamp::updateMenuIndex(unsigned char dir)
{
  switch (dir)
  {
  case 't':
    //top
    this->_menuIndex=0x0;
    this->_menuDepth=0x0;
    break;
  case 'c':
    //set time

      if(menuPosition()==0x0)   break;
    if (menuPosition()==0x1111 || menuPosition()==0x2111 || menuPosition()==0x3111 || menuPosition()==0x1211 || menuPosition()==0x2211 || menuPosition()==0x3211 || menuPosition()==0x4211)
    {
      if (menuPosition() == 0x3111) this->_menuIndex = 0x1111;
      else if (menuPosition() == 0x4211)  this->_menuIndex = 0x1211;
      else this->_menuIndex = this->_menuIndex + (1 << menuDepth());
      break;
    } 
    //set alarm
    if (menuPosition()==0x1121 || menuPosition()==0x2121 || menuPosition()==0x3121 || menuPosition()==0x1221)
    {
      if (menuPosition() == 0x3121) this->_menuIndex = 0x1121;
      else if (menuPosition() == 0x1221)  this->_menuIndex = 0x1221;
      else this->_menuIndex = this->_menuIndex + (1 << menuDepth());
      break;
    }

    //brightness / LCD backlight / lcd sleep time
    if (menuPosition() == 0x122 || menuPosition() == 0x132 || menuPosition() == 0x142) {
      break;
    }

    //AudioViz
    if (menuPosition()==0x1112) break;
    if (menuPosition()==0x12)
    {
      this->_menuDepth +=4;
      //ignore 0x112  replace with 0x212;
      if (getDisplayMode()==0) this->_menuIndex = 0x212;
      if (getDisplayMode()==1) this->_menuIndex = 0x212;
      if (getDisplayMode()==2) this->_menuIndex = 0x312;
      if (getDisplayMode()==3) this->_menuIndex = 0x412;

      break;
    }

    //Cycle
    if (menuPosition()==0x1212 || menuPosition()==0x2212 || menuPosition()==0x3212)
    {
      if (menuPosition() == 0x1212) this->_menuIndex = 0x2212;
      else if (menuPosition() == 0x2212) this->_menuIndex = 0x3212;
      else if (menuPosition() == 0x3212) this->_menuIndex = 0x1212;
      break;
    }

    //Random
    if (menuPosition()==0x1312 || menuPosition()==0x2312)
    {
      if (menuPosition() == 0x1312) this->_menuIndex = 0x2312;
      else if (menuPosition() == 0x2312) this->_menuIndex = 0x1312;
      break;
    }

    //Solid
    if (menuPosition()==0x1412 || menuPosition()==0x2412)
    {
      if (menuPosition() == 0x1412) this->_menuIndex = 0x2412;
      else if (menuPosition() == 0x2412) this->_menuIndex = 0x1412;
      break;
    }

    this->_menuDepth +=4;
    this-> _menuIndex = this->_menuIndex + (1 << menuDepth());

    //ignore set weekday
    // if (menuPosition() == 0x1211) this->_menuIndex = 0x2211;

    break;
  case 'h':  
    if (_alarming == true)   _alarming = false;
    if (menuDepth() == 0x0)
    {
      this->_menuIndex=0x0;
      break;
    } 
    this->_menuIndex =this->_menuIndex - (this->_menuCurrent << menuDepth());
    this->_menuDepth -=4;

    break;

    //Going Left
  case 'l':

    //Clock
    if (menuPosition()==0x1111 || menuPosition()==0x2111 || menuPosition()==0x3111 || menuPosition()==0x1211 || menuPosition()==0x2211 || menuPosition()==0x3211 || menuPosition()==0x4211)
    {

      if (menuPosition()==0x01111 && tHour >0 ) tHour-- ; 
      else if (menuPosition()==0x01111 && tHour ==0 ) tHour = 23;  //hour
      
      if (menuPosition()==0x02111 && tMinute >0 ) tMinute-- ; 
      else if (menuPosition()==0x02111 && tMinute ==0 ) tMinute = 59;  //min
     
      if (menuPosition()==0x03111 && tHour >=12)  tHour-=12; //am
     
      if (menuPosition()==0x01211 && tDay>0 ) tDay-- ; 
      else if (menuPosition()==0x01211 && tDay ==0 ) tDay==6; //day
     
      if (menuPosition()==0x02211 && tDate >1 ) tDate-- ; 
      else if (menuPosition()==0x02211 && tDate ==1 ) tDate==31; //day
     
      if (menuPosition()==0x03211 && tMonth >1 ) tMonth-- ; 
      else if (menuPosition()==0x03211 && tMonth ==1 ) tMonth=12;  //month
      
      if (menuPosition()==0x04211 && tYear >0 ) tYear-- ; 
      else if (menuPosition()==0x04211 && tYear ==0 ) tYear=99; //year

      setDateTime();
      break;
    }

    //Alarm
    if (menuPosition()==0x1121 || menuPosition()==0x2121 || menuPosition()==0x3121 || menuPosition()==0x1221)
    {
      if (menuPosition()==0x1121 && getAlarmHour() >1 ) setAlarmHour(getAlarmHour() - 1 ); 
      else if (menuPosition()==0x1121 && getAlarmHour()==1) setAlarmHour(12);
      if (menuPosition()==0x2121 && getAlarmMin() >0 ) setAlarmMin(getAlarmMin() - 1 ); 
      else if (menuPosition()==0x2121 && getAlarmMin()==0) setAlarmMin(59);
      if (menuPosition()==0x3121) setAlarmAM(true);
      if (menuPosition()==0x1221) setAlarmOn(false);

      break;
    }

    //brightness / LCD backlight / lcd sleep time
    if (menuPosition() == 0x122 || menuPosition() == 0x132 || menuPosition() == 0x142) 
    {
      if (menuPosition()==0x122 && getLampBrightness()>1) setLampBrightness(getLampBrightness() - 1);
      if (menuPosition()==0x132 && getLCDBrightness()>1) setLCDBrightness(getLCDBrightness() - 1);
      //  if (menuPosition()==0x142 && getLCDSleepTime()>10) setLCDSleepTime(getLCDSleepTime() - 1);
      delay(5);
      break;
    }

    //AudioViz Fade Speed
    //   if (menuPosition()==0x1112)
    //  {
    //   if (getAudioFadeSpeed() >1 ) setAudioFadeSpeed(getAudioFadeSpeed()-1);
    //  break;
    //  }

    //Cycle
    if (menuPosition()==0x1212 || menuPosition()==0x2212 || menuPosition()==0x3212)
    {
      if (menuPosition()==0x1212 && getCycleHoldTime() >1 ) setCycleHoldTime(getCycleHoldTime() - 1 );
      if (menuPosition()==0x2212 && getCycleFadeTime() >1 ) setCycleFadeTime(getCycleFadeTime() - 1 );
      if (menuPosition()==0x3212 && getCycleSteps()  >1 ) setCycleSteps(getCycleSteps() - 1 );

      break;
    }

    //Random
    if (menuPosition()==0x1312 || menuPosition()==0x2312)
    {
      if (menuPosition()==0x1312 && getRandomHoldTime() >1 ) setRandomHoldTime(getRandomHoldTime() - 1 );
      if (menuPosition()==0x2312 && getRandomFadeTime() >1 ) setRandomFadeTime(getRandomFadeTime() - 1 );
      break;
    }

    //Solid
    if (menuPosition()==0x1412 || menuPosition()==0x2412)
    {
      if (menuPosition()==0x1412 && getColorHue() >0 ) setColorHue(getColorHue() - 1 );
      if (menuPosition()==0x2412 && getColorSat() >0 ) setColorSat(getColorSat() - 1 );
      break;
    }

    //limits moving left
    if (menuPosition() == 0x0) this->_menuIndex = 0x2;
    else if (menuPosition() == 0x11)  this->_menuIndex = 0x21;
    else if (menuPosition() == 0x111)  this->_menuIndex = 0x211;

    else if (menuPosition() == 0x121)  this->_menuIndex = 0x221;
    else if (menuPosition() == 0x12)  this->_menuIndex = 0x32;
    else if (menuPosition() == 0x212)  this->_menuIndex = 0x412;
    else this->_menuIndex = this->_menuIndex - (1 << menuDepth());

    //Display Mode
    if (menuPosition() == 0x112) setDisplayMode(0x0);
    if (menuPosition() == 0x212) setDisplayMode(0x1);
    if (menuPosition() == 0x312) setDisplayMode(0x2);
    if (menuPosition() == 0x412) setDisplayMode(0x3);

    break;

    //Going right
  case 'r':


    //Clock
    if (menuPosition()==0x1111 || menuPosition()==0x2111 || menuPosition()==0x3111 || menuPosition()==0x1211 || menuPosition()==0x2211 || menuPosition()==0x3211 || menuPosition()==0x4211)
    {

      if (menuPosition()==0x01111 && tHour <23 ) tHour++ ; 
      else if (menuPosition()==0x01111 && tHour ==23 ) tHour = 0;  //hour
    
      if (menuPosition()==0x02111 && tMinute <59 ) tMinute++ ; 
      else if (menuPosition()==0x02111 && tMinute ==59 ) tMinute = 0;  //min
     
      if (menuPosition()==0x03111 && tHour <=12)  tHour+=12; //am
     
      if (menuPosition()==0x01211 && tDay<6 ) tDay++ ; 
      else if (menuPosition()==0x01211 && tDay ==6 ) tDay==0; //day
     
      if (menuPosition()==0x02211 && tDate <31 ) tDate++ ; 
      else if (menuPosition()==0x02211 && tDate ==31 ) tDate==1; //day
     
      if (menuPosition()==0x03211 && tMonth <12 ) tMonth++ ; 
      else if (menuPosition()==0x03211 && tMonth ==12 ) tMonth=1;  //month
     
      if (menuPosition()==0x04211 && tYear <99 ) tYear++ ; 
      else if (menuPosition()==0x04211 && tYear ==99 ) tYear=0; //year

      setDateTime();
      break;
    }

    //Alarm
    if (menuPosition()==0x1121 || menuPosition()==0x2121 || menuPosition()==0x3121 || menuPosition()==0x1221)
    {
      if (menuPosition()==0x1121 && getAlarmHour() < 12 ) setAlarmHour(getAlarmHour() + 1 ); 
      else if (menuPosition()==0x1121 && getAlarmHour()==12) setAlarmHour(1);
      if (menuPosition()==0x2121 && getAlarmMin() < 59 ) setAlarmMin(getAlarmMin() + 1 ); 
      else if (menuPosition()==0x2121 && getAlarmMin()==59) setAlarmMin(0);
      if (menuPosition()==0x3121) setAlarmAM(false);
      if (menuPosition()==0x1221) setAlarmOn(true);

      break;
    }

    //brightness / LCD backlight / lcd sleep time
    if (menuPosition() == 0x122 || menuPosition() == 0x132 || menuPosition() == 0x142) {
      if (menuPosition()==0x122 && getLampBrightness()<255) setLampBrightness(getLampBrightness() + 1);
      if (menuPosition()==0x132 && getLCDBrightness()<26) setLCDBrightness(getLCDBrightness() + 1);
      // if (menuPosition()==0x142 && getLCDSleepTime()<31) setLCDSleepTime(getLCDSleepTime() + 1);
      delay(5);
      break;
    }

    //AudioViz Fade Speed
  //  if (menuPosition()==0x1112)
  //  {
  //    if (getAudioFadeSpeed() < 255 ) setAudioFadeSpeed(getAudioFadeSpeed()+1);
  //    break;
  //  }

    //Cycle
    if (menuPosition()==0x1212 || menuPosition()==0x2212 || menuPosition()==0x3212)
    {
      if (menuPosition()==0x1212 && getCycleHoldTime() <30 ) setCycleHoldTime(getCycleHoldTime() + 1 );
      if (menuPosition()==0x2212 && getCycleFadeTime() <30 ) setCycleFadeTime(getCycleFadeTime() + 1 );
      if (menuPosition()==0x3212 && getCycleSteps() <128 ) setCycleSteps(getCycleSteps() + 1 );
      break;
    }

    //Random
    if (menuPosition()==0x1312 || menuPosition()==0x2312)
    {
      if (menuPosition()==0x1312 && getRandomHoldTime() <30 ) setRandomHoldTime(getRandomHoldTime() + 1 );
      if (menuPosition()==0x2312 && getRandomFadeTime() <30) setRandomFadeTime(getRandomFadeTime() + 1 );
      break;
    }

    //Solid
    if (menuPosition()==0x1412 || menuPosition()==0x2412)
    {
      if (menuPosition()==0x1412 && getColorHue() <255 ) setColorHue(getColorHue() + 1 );
      if (menuPosition()==0x2412 && getColorSat() <255 ) setColorSat(getColorSat() + 1 );
      break;
    }


    //limits moving right
    if (menuPosition() == 0x2) this->_menuIndex = 0x0;
    else if (menuPosition() == 0x21)  this->_menuIndex = 0x11;
    else if (menuPosition() == 0x211)  this->_menuIndex = 0x111;
    else if (menuPosition() == 0x221)  this->_menuIndex = 0x121;
    else if (menuPosition() == 0x32)  this->_menuIndex = 0x12;
    else if (menuPosition() == 0x412)  this->_menuIndex = 0x212;
    else this->_menuIndex = this->_menuIndex + (1 << menuDepth());

    //Display Mode
    if (menuPosition() == 0x112) setDisplayMode(0x0);
    if (menuPosition() == 0x212) setDisplayMode(0x1);
    if (menuPosition() == 0x312) setDisplayMode(0x2);
    if (menuPosition() == 0x412) setDisplayMode(0x3);

  default:
    break;
  }

  this->_menuCurrent = menuPosition() >> menuDepth();

  drawMenu(menuPosition());
}