Beispiel #1
0
void Light::task()
{
	if(lastSeconds == 0) return;

    if(clock.Seconds() > lastSeconds + ((integration * 60) / LIGHT_INTEGRATION_COUNT))
    {
        lastSeconds = clock.Seconds();
        iev[pos] = readEv();
        pos++;
        if(pos >= LIGHT_INTEGRATION_COUNT) pos = 0;
        iev[pos] = 0;
    }
}
volatile char viewSeconds(char key, char first)
{
	if(first)
	{
		lcd.cls();
		lcd.writeString(1, 18, TEXT("Clock:"));
		menu.setTitle(TEXT("Clock"));
		menu.setBar(TEXT("TARE"), TEXT("RETURN"));
	}

	lcd.eraseBox(36, 18, 83, 18 + 8);
	/*char x =*/ lcd.writeNumber(83, 18, clock.Seconds(), 'F', 'R');
	lcd.update();

	switch(key)
	{
	   case FL_KEY:
		   clock.tare();
		   break;

	   case FR_KEY:
		   return FN_CANCEL;
	}

	return FN_CONTINUE;
}
Beispiel #3
0
void Light::integrationStart(uint8_t integration_minutes, int8_t darkOffset)
{
	start();
    integration = integration_minutes;
    pos = 0;
    lastSeconds = clock.Seconds() + 1; // +1 so it can never be zero
    for(uint8_t i = 0; i < LIGHT_INTEGRATION_COUNT; i++)
    {
    	iev[i] = readEv(); // initialize array with readings //
    	wdt_reset();
    }
}
Beispiel #4
0
char shutter::run()
{
	char cancel = 0;
	static uint8_t enter, photos, exps, run_state = RUN_DELAY, old_state = 255;    
	static uint32_t last_photo_ms;

	if(MIRROR_IS_DOWN)
	{
		CHECK_CABLE;
	}
	if(!running)
	{
	if(enter) cancel = 1; else return 0;
	}

	uint16_t value;

	if(enter == 0) // Initialize variables and setup I/O pins
	{
		enter = 1;
		run_state = RUN_DELAY;
		clock.tare();
		photos = 0;
		exps = 0;
		
		ENABLE_MIRROR;
		ENABLE_SHUTTER;
		MIRROR_DOWN;
		SHUTTER_CLOSE;
	}	

	/////// RUNNING PROCEDURE ///////
	if(run_state == RUN_DELAY)
	{
		#ifdef DEBUG
		if(old_state != run_state)
		{
			if(conf.devMode)
			{
				debug("State: RUN_DELAY");
				debug_nl();
			}
			old_state = run_state;
		}
		#endif

		if(((unsigned long) clock.event_ms / 1000) > current.Delay)
		{
			clock.tare();
			clock.reset();
			last_photo_ms = 0;
			run_state = RUN_PHOTO;
		}
		else
		{
			if(((unsigned long) clock.event_ms / 1000) + settings_mirror_up_time >= current.Delay)
			{
	    		// Mirror Up //
				half();
			}	
			if((settings_warn_time > 0) && (((unsigned long) clock.event_ms / 1000) + settings_warn_time >= current.Delay))
			{
	    		// Flash Light //
				_delay_ms(50);
			}	
		}
	}
	if(run_state == RUN_PHOTO)
	{
		#ifdef DEBUG
		if(old_state != run_state)
		{
			if(conf.devMode)
			{
				debug("State: RUN_PHOTO");
				debug_nl();
			}
			old_state = run_state;
		}
		#endif

		if(current.Exp > 0 || (current.Mode & RAMP))
		{
			clock.tare();
			run_state = RUN_BULB;
		}
		else
		{
			exps++;
	 		bulb = false;
			full();
			_delay_ms(50);
			off();
			_delay_ms(50);
			if(current.Gap <= settings_mirror_up_time) half(); // Mirror Up //
			run_state = RUN_NEXT;
		}
	}
	if(run_state == RUN_BULB)
	{
		#ifdef DEBUG
		if(old_state != run_state)
		{
			if(conf.devMode)
			{
				debug("State: RUN_BULB");
				debug_nl();
			}
			old_state = run_state;
		}
		#endif

		bulb = true;
		full();
		static uint8_t calc = true;
		static uint16_t bulb_length, exp;
		if(calc)
		{
			calc = false;
			exp = current.Exp * 100;
			if(current.Mode & RAMP)
			{
				float key1, key2, key3, key4;
				char found = 0;
				uint8_t i;

				// Bulb ramp algorithm goes here
				for(i = 1; i <= current.Keyframes; i++)
				{
					if(clock.Seconds() <= current.Key[i - 1])
					{
						found = 1;
						key1 = (float) current.Bulb[i > 1 ? i - 2 : i - 1] * 100;
						key2 = (float) current.Bulb[i - 1] * 100;
						key3 = (float) current.Bulb[i] * 100;
						key4 = (float) current.Bulb[i < current.Keyframes ? i + 1 : i] * 100;
						break;
					}
				}
				if(found)
				{
					exp = (uint16_t) curve(key1, key2, key3, key4, ((float)clock.Seconds() - (i > 1 ? (float)current.Key[i - 2] : 0.0) ) / ((float)current.Key[i - 1] - (i > 1 ? (float)current.Key[i - 2] : 0.0)) );
				}
				else
				{
					exp = current.Bulb[current.Keyframes] * 100;
				}
				bulb_length = exp;
				if(conf.devMode)
				{
					debug("Seconds: ");
					debug((uint16_t) clock.Seconds());
					debug_nl();
					debug("Ramp: ");
					debug(bulb_length);
					if(found) debug(" (calculated)");
					debug_nl();
				}
			}
			if(current.Mode & HDR)
			{
				uint16_t tmp = exps - (current.Exps >> 1); 
				bulb_length = (tmp < 32768) ? exp * (1 << tmp) : exp / (1 << (0 - tmp));

				if(conf.devMode)
				{
					debug("exps - (current.Exps >> 1): ");
					if(tmp < 32768)
					{
						debug(tmp);
					}
					else
					{
						debug("-");
						debug(0 - tmp);
					}
					debug_nl();
					debug("Bulb: ");
					debug(bulb_length);
					debug_nl();
				}
			}
			if((current.Mode & (HDR | RAMP)) == 0)
			{
				if(conf.devMode)
				{
					debug("***Using exp");
					debug_nl();
				}
				bulb_length = exp;
			}
		}
		if(((unsigned long) clock.eventMs()) >= bulb_length )
		{
			calc = true;
			exps++;
			off();
			_delay_ms(50);
			if(current.Gap <= settings_mirror_up_time) half(); // Mirror Up //
			run_state = RUN_NEXT;
		}
	}
void Light::task()
{
	if(!initialized || !integrationActive) return;

  if(skipTask) return;

  if(paused)
  {
    lcd.backlight(255);
    wasPaused = 5;
    return;
  }

  if(wasPaused > 0)
  {
    lcd.backlight(0);
    wasPaused--;
    return;
  }


  if(lastSeconds == 0 || (clock.Seconds() > lastSeconds + (uint32_t)((integration * 60) / LIGHT_INTEGRATION_COUNT)))
  {
    lastSeconds = clock.Seconds();
    for(uint8_t i = 0; i < LIGHT_INTEGRATION_COUNT - 1; i++)
    {
      iev[i] = iev[i + 1];
    }
    iev[LIGHT_INTEGRATION_COUNT - 1] = readEv();
    slope = readIntegratedSlopeMedian();

    if(iev[LIGHT_INTEGRATION_COUNT - 1] <= NIGHT_THRESHOLD)
    {
      underThreshold = true;
      if(lockedSlope == 0.0 && slope) lockedSlope = slope;
    }
    else if(iev[LIGHT_INTEGRATION_COUNT - 1] > NIGHT_THRESHOLD + NIGHT_THRESHOLD_HYSTERESIS)
    {
      underThreshold = false;
      lockedSlope = 0.0;
    }

    median = arrayMedian50(iev, LIGHT_INTEGRATION_COUNT);

    float sum = 0.0;
    for(uint8_t i = 0; i < LIGHT_INTEGRATION_COUNT; i++) sum += iev[i];
    integrated = sum / (float)(LIGHT_INTEGRATION_COUNT);

    if(conf.debugEnabled)
    {
      //DEBUG(STR("\r\nIEV: "));
      //for(uint8_t i = 0; i < LIGHT_INTEGRATION_COUNT; i++)
      //{
      //  DEBUG(iev[i]);
      //  DEBUG(STR(","));
      //}
      //DEBUG_NL();
//
      //DEBUG(STR("#######LOCKED "));
      //DEBUG(lockedSlope);
      //DEBUG(STR(" #######\r\n"));
//
      //DEBUG(STR("####### SLOPE "));
      //DEBUG(slope);
      //DEBUG(STR(" #######\r\n"));
//
//
      //DEBUG(STR("#######   INT "));
      //DEBUG(integrated);
      //DEBUG(STR(" #######\r\n"));
//
      //DEBUG(STR("#######   MED "));
      //DEBUG(median);
      //DEBUG(STR(" #######\r\n"));
//
      //DEBUG(STR("#######    EV "));
      //DEBUG(iev[LIGHT_INTEGRATION_COUNT - 1]);
      //DEBUG(STR(" #######\r\n"));
    }
  }
}