volatile char shutterLagTest(char key, char first)
{
//  static uint8_t cable;
	uint16_t start_lag, end_lag;

	if(first)
	{
//    cable = 0;
		lcd.cls();
		menu.setTitle(TEXT("Shutter Lag Test"));
		menu.setBar(TEXT("Test 1"), TEXT("Test 2 "));
		lcd.update();
	}

	if(key == FL_KEY || key == FR_KEY)
	{
		lcd.eraseBox(10, 18, 80, 38);
		lcd.writeString(10, 18, TEXT("Result:"));

		ENABLE_SHUTTER;
		ENABLE_MIRROR;
		ENABLE_AUX_PORT;

		_delay_ms(100);

		if(key == FR_KEY)
		{
			MIRROR_UP;
			_delay_ms(1000);
		}

		SHUTTER_OPEN;
		clock.tare();

		while(!AUX_INPUT1)
		{
			if(clock.eventMs() >= 1000)
				break;
		}

		start_lag = (uint16_t)clock.eventMs();

		_delay_ms(50);

		SHUTTER_CLOSE;
		clock.tare();

		while(AUX_INPUT1)
		{
			if(clock.eventMs() > 1000)
				break;
		}

		end_lag = (uint16_t)clock.eventMs();

		lcd.writeNumber(56, 18, start_lag, 'U', 'L');
		lcd.writeNumber(56, 28, end_lag, 'U', 'L');

		lcd.update();
	}

	if(key == LEFT_KEY)
		return FN_CANCEL;

	return FN_CONTINUE;
}
Example #2
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;
		}
	}
volatile char motionTrigger(char key, char first)
{
	uint8_t i;
	uint16_t val;
	static uint16_t lv[3];
	static uint8_t threshold = 2;

	if(key == LEFT_KEY)
	{
		if(threshold > 0) threshold--;
		first = 1;
	}
	if(key == RIGHT_KEY)
	{
		if(threshold < 4) threshold++;
		first = 1;
	}

	if(first)
	{
		sleepOk = 0;
		clock.tare();
		lcd.cls();
		menu.setTitle(TEXT("Motion Sensor"));
		menu.setBar(TEXT("RETURN"), BLANK_STR);

		lcd.drawLine(10, 22, 84-10, 22);
		lcd.drawLine(11, 21, 11, 23);
		lcd.drawLine(84-11, 21, 84-11, 23);
		lcd.drawLine(12, 20, 12, 24);
		lcd.drawLine(84-12, 20, 84-12, 24);
		lcd.drawLine(13, 20, 13, 24);
		lcd.drawLine(84-13, 20, 84-13, 24);
		lcd.setPixel(42, 21);
		lcd.setPixel(42+10, 21);
		lcd.setPixel(42-10, 21);
		lcd.setPixel(42+20, 21);
		lcd.setPixel(42-20, 21);

		i = threshold * 10;
		lcd.drawLine(42-3-20+i, 16, 42+3-20+i, 16);
		lcd.drawLine(42-2-20+i, 17, 42+2-20+i, 17);
		lcd.drawLine(42-1-20+i, 18, 42+1-20+i, 18);
		lcd.setPixel(42-20+i, 19);

		lcd.writeStringTiny(19, 25, TEXT("SENSITIVITY"));

		lcd.update();
		lcd.backlight(0);
		hardware_flashlight(0);
		_delay_ms(50);
		for(i = 0; i < 3; i++)
		{
			lv[i] = (uint16_t)hardware_readLight(i);
		}
	}

	uint8_t thres = 4 - threshold + 2;
	if((4 - threshold) > 2) thres += ((4 - threshold) - 1) * 2;

	for(i = 0; i < 3; i++)
	{
		val = (uint16_t)hardware_readLight(i);
		if(clock.eventMs() > 1000 && val > thres && (val < (lv[i] - thres) || val > (lv[i] + thres)))
		{
			clock.tare();
			shutter_capture();
		}
		lv[i] = val;
	}

	if(key == FL_KEY)
	{
		sleepOk = 1;
		lcd.backlight(255);
		return FN_CANCEL;
	}

	return FN_CONTINUE;
}