Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 744 → Rev 745

/tags/V2.14b/CamCtrl.c
0,0 → 1,105
#include <stdio.h>
#include <string.h>
#include "91x_lib.h"
#include "CamCtrl.h"
#include "i2c.h"
#include "timer1.h"
#include "led.h"
#include "main.h"
#include "uart1.h"
#include "compass.h"
#include "spi_slave.h"
#include "triggerlog.h"
 
FromCamCtrl_t FromCamCtrl;
ToCamCtrl_t ToCamCtrl;
u16 CamCtrlTimeout = 25000;
 
void InitCamCtrl(void)
{
ToCamCtrl.CamCommand = 0;
ToCamCtrl.ZoomInput = 128; // Middle -> no zoom
}
 
void CamCtrl_UpdateData(u8* pRxBuffer, u8 RxBufferSize)
{ // if crc is ok and number of byte are matching
memcpy((u8 *)&FromCamCtrl, pRxBuffer, sizeof(FromCamCtrl));
//if(FromCamCtrl.CamStatus & CAM_STATE_PIC_CAPTURED)
 
 
if(FromCamCtrl.CamStatus & CAM_STATE_REC_ACTIVE) CamCtrlCharacter = 'R';
else if(FromCamCtrl.CamStatus & CAM_STATE_PHOTO_MODE) CamCtrlCharacter = 'P';
else if(FromCamCtrl.CamStatus & CAM_STATE_CAM_DISCONN) CamCtrlCharacter = '?';
else if(FromCamCtrl.CamStatus & CAM_STATE_OFF) CamCtrlCharacter = '!';
else if(TrigLogging.CountExternal) CamCtrlCharacter = TrigLogging.CountExternal % 10 + '0';
else if(FromCamCtrl.PhotoCount) CamCtrlCharacter = FromCamCtrl.PhotoCount % 10 + '0';
else if(FromCamCtrl.CamStatus & CAM_STATE_RDY) CamCtrlCharacter = 'c';
else CamCtrlCharacter = ' ';
 
// c = camera is ready
// R = Record active
// P = Cam in Photo mode (LANC Camcorders)
// ! = Camera is off but connected
// ? = disconnected
// 0-9 = Photo releases
 
if(FromCamCtrl.CamStatus & CAM_STATE_I2C_OK) CamCtrlTimeout = 3000;
}
 
void CamCtrl_GetData(u8 timeout)
{
static u8 timing = 250, p63 = 0;
static u8 force1photo = 0, delay ; // makes one photo when switching from Off to Photo
 
if(timing)
{
timing--;
}
else
// try to catch the I2C buffer within timeout ms
if(I2CBus_LockBuffer(I2C0, timeout))
{
u8 RxBytes = sizeof(FromCamCtrl);
// initiate transmission
ToCamCtrl.ZoomInput = 128 + PPM_In[EE_Parameter.CamCtrlZoomChannel];
if(EE_Parameter.CamCtrlModeChannel)
{
if(PPM_In[EE_Parameter.CamCtrlModeChannel] > 50) // max
{
ToCamCtrl.CamCommand &= ~CAM_CMD_REC_OFF;
ToCamCtrl.CamCommand |= CAM_CMD_REC_ON;
force1photo = 0;
}
else
if(PPM_In[EE_Parameter.CamCtrlModeChannel] < -50) // min
{
ToCamCtrl.CamCommand &= ~CAM_CMD_REC_ON;
ToCamCtrl.CamCommand |= CAM_CMD_REC_OFF;
force1photo = 1;
p63 = 0;
delay = 5;
}
else // Middle
{
if(delay) delay--;
else
{
if(force1photo || ((UART_VersionInfo.HWMajor >= 30) && TRIGGER_PP_INTERN) || ((UART_VersionInfo.HWMajor < 30) && (FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE))) // internal Portpin or Flag
{
if(!p63) ToCamCtrl.CamCommand |= CAM_CMD_SHUTTER; // combined with the FC trigger output
p63 = 1;
force1photo = 0;
}
else p63 = 0;
}
}
}
 
I2CBus_Transmission(I2C0, CAM_SLAVE_ADDRESS, &ToCamCtrl, sizeof(ToCamCtrl), &CamCtrl_UpdateData, RxBytes);
 
if(!EE_Parameter.CamCtrlModeChannel) ToCamCtrl.CamCommand = 0; // delete REC_OFF
ToCamCtrl.CamCommand = CAM_CMD_SWITCH_ON | (ToCamCtrl.CamCommand & (CAM_CMD_REC_ON | CAM_CMD_REC_OFF));
timing = 66; // 66ms = 15Hz
}
else timing = 11; // try again in 11ms
}