Subversion Repositories NaviCtrl

Rev

Rev 733 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
728 holgerb 1
#include <stdio.h>
2
#include <string.h>
3
#include "91x_lib.h"
4
#include "CamCtrl.h"
5
#include "i2c.h"
6
#include "timer1.h"
7
#include "led.h"
8
#include "main.h"
9
#include "uart1.h"
10
#include "compass.h"
11
#include "spi_slave.h"
12
#include "triggerlog.h"
13
 
14
FromCamCtrl_t FromCamCtrl;
15
ToCamCtrl_t ToCamCtrl;
16
u16 CamCtrlTimeout = 25000;
17
 
18
void InitCamCtrl(void)
19
{
20
 ToCamCtrl.CamCommand = 0;
21
 ToCamCtrl.ZoomInput = 128; // Middle -> no zoom
22
}
23
 
24
void CamCtrl_UpdateData(u8* pRxBuffer, u8 RxBufferSize)
25
{       // if crc is ok and number of byte are matching
26
  memcpy((u8 *)&FromCamCtrl, pRxBuffer, sizeof(FromCamCtrl));
27
//if(FromCamCtrl.CamStatus & CAM_STATE_PIC_CAPTURED) 
28
 
29
 
30
        if(FromCamCtrl.CamStatus & CAM_STATE_REC_ACTIVE)                CamCtrlCharacter = 'R';
31
        else if(FromCamCtrl.CamStatus & CAM_STATE_PHOTO_MODE)   CamCtrlCharacter = 'P';
732 holgerb 32
        else if(FromCamCtrl.CamStatus & CAM_STATE_CAM_DISCONN)  CamCtrlCharacter = '?';
728 holgerb 33
        else if(FromCamCtrl.CamStatus & CAM_STATE_OFF)                  CamCtrlCharacter = '!';
34
        else if(TrigLogging.CountExternal)                                              CamCtrlCharacter = TrigLogging.CountExternal % 10 + '0';
35
        else if(FromCamCtrl.PhotoCount)                                                 CamCtrlCharacter = FromCamCtrl.PhotoCount % 10 + '0';
36
        else if(FromCamCtrl.CamStatus & CAM_STATE_RDY)                  CamCtrlCharacter = 'c';
37
        else  CamCtrlCharacter = ' ';
38
 
39
// c = camera is ready
40
// R = Record active
41
// P = Cam in Photo mode (LANC Camcorders)
42
// ! = Camera is off but connected
43
// ? = disconnected
44
// 0-9 = Photo releases
45
 
46
  if(FromCamCtrl.CamStatus & CAM_STATE_I2C_OK) CamCtrlTimeout = 3000;
47
}
48
 
49
void CamCtrl_GetData(u8 timeout)
50
{
730 holgerb 51
 static u8 timing = 250, p63 = 0;
732 holgerb 52
 static u8 force1photo = 0, delay ;             // makes one photo when switching from Off to Photo
728 holgerb 53
 
54
 if(timing)
55
   {
56
    timing--;
57
   }
58
   else
59
        // try to catch the I2C buffer within timeout ms
60
   if(I2CBus_LockBuffer(I2C0, timeout))
61
        {
733 holgerb 62
                u8 RxBytes = sizeof(FromCamCtrl);
728 holgerb 63
                // initiate transmission
64
                ToCamCtrl.ZoomInput = 128 + PPM_In[EE_Parameter.CamCtrlZoomChannel];
65
                if(EE_Parameter.CamCtrlModeChannel)
66
                 {
67
                        if(PPM_In[EE_Parameter.CamCtrlModeChannel] > 50)        // max
68
                           {
69
                        ToCamCtrl.CamCommand &= ~CAM_CMD_REC_OFF;
70
                            ToCamCtrl.CamCommand |= CAM_CMD_REC_ON;
732 holgerb 71
                                force1photo = 0;
728 holgerb 72
                           }
73
                        else
74
                        if(PPM_In[EE_Parameter.CamCtrlModeChannel] < -50)        // min
75
                           {
76
                        ToCamCtrl.CamCommand &= ~CAM_CMD_REC_ON;
77
                            ToCamCtrl.CamCommand |= CAM_CMD_REC_OFF;
732 holgerb 78
                                force1photo = 1;
79
                                p63 = 0;
80
                                delay = 5;
728 holgerb 81
                                }
82
                    else         // Middle
732 holgerb 83
                          {
84
                           if(delay) delay--;
85
                                else
728 holgerb 86
                           {
732 holgerb 87
                        if(force1photo || ((UART_VersionInfo.HWMajor >= 30) && TRIGGER_PP_INTERN) || ((UART_VersionInfo.HWMajor < 30) && (FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE))) // internal Portpin or Flag
728 holgerb 88
                                 {
89
                                  if(!p63) ToCamCtrl.CamCommand |= CAM_CMD_SHUTTER; // combined with the FC trigger output
90
                                  p63 = 1;
732 holgerb 91
                                  force1photo = 0;
728 holgerb 92
                                 }
93
                                 else p63 = 0;
94
                           }
732 holgerb 95
                          }
728 holgerb 96
                }
97
 
733 holgerb 98
        I2CBus_Transmission(I2C0, CAM_SLAVE_ADDRESS, &ToCamCtrl, sizeof(ToCamCtrl), &CamCtrl_UpdateData, RxBytes);
728 holgerb 99
 
100
        if(!EE_Parameter.CamCtrlModeChannel) ToCamCtrl.CamCommand = 0; // delete REC_OFF
101
        ToCamCtrl.CamCommand = CAM_CMD_SWITCH_ON | (ToCamCtrl.CamCommand & (CAM_CMD_REC_ON | CAM_CMD_REC_OFF));
102
        timing = 66; // 66ms = 15Hz
103
   }
730 holgerb 104
   else timing = 11; // try again in 11ms
728 holgerb 105
}