Go to most recent revision | Details | 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 | ToCamCtrl.ControlInput = 0; |
||
23 | } |
||
24 | |||
25 | void CamCtrl_UpdateData(u8* pRxBuffer, u8 RxBufferSize) |
||
26 | { // if crc is ok and number of byte are matching |
||
27 | memcpy((u8 *)&FromCamCtrl, pRxBuffer, sizeof(FromCamCtrl)); |
||
28 | //if(FromCamCtrl.CamStatus & CAM_STATE_PIC_CAPTURED) |
||
29 | |||
30 | |||
31 | if(FromCamCtrl.CamStatus & CAM_STATE_REC_ACTIVE) CamCtrlCharacter = 'R'; |
||
32 | else if(FromCamCtrl.CamStatus & CAM_STATE_PHOTO_MODE) CamCtrlCharacter = 'P'; |
||
33 | else if(FromCamCtrl.CamStatus & CAM_STATE_OFF) CamCtrlCharacter = '!'; |
||
34 | else if(FromCamCtrl.CamStatus & CAM_STATE_CAM_DISCONN) CamCtrlCharacter = '?'; |
||
35 | else if(TrigLogging.CountExternal) CamCtrlCharacter = TrigLogging.CountExternal % 10 + '0'; |
||
36 | else if(FromCamCtrl.PhotoCount) CamCtrlCharacter = FromCamCtrl.PhotoCount % 10 + '0'; |
||
37 | else if(FromCamCtrl.CamStatus & CAM_STATE_RDY) CamCtrlCharacter = 'c'; |
||
38 | else CamCtrlCharacter = ' '; |
||
39 | |||
40 | // c = camera is ready |
||
41 | // R = Record active |
||
42 | // P = Cam in Photo mode (LANC Camcorders) |
||
43 | // ! = Camera is off but connected |
||
44 | // ? = disconnected |
||
45 | // 0-9 = Photo releases |
||
46 | |||
47 | if(FromCamCtrl.CamStatus & CAM_STATE_I2C_OK) CamCtrlTimeout = 3000; |
||
48 | } |
||
49 | |||
50 | void CamCtrl_GetData(u8 timeout) |
||
51 | { |
||
730 | holgerb | 52 | static u8 timing = 250, p63 = 0; |
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 | { |
||
62 | u8 TxBytes = 0, RxBytes = sizeof(FromCamCtrl); |
||
63 | TxBytes = 4; |
||
64 | // initiate transmission |
||
65 | ToCamCtrl.ZoomInput = 128 + PPM_In[EE_Parameter.CamCtrlZoomChannel]; |
||
66 | if(EE_Parameter.CamCtrlModeChannel) |
||
67 | { |
||
68 | if(PPM_In[EE_Parameter.CamCtrlModeChannel] > 50) // max |
||
69 | { |
||
70 | ToCamCtrl.CamCommand &= ~CAM_CMD_REC_OFF; |
||
71 | ToCamCtrl.CamCommand |= CAM_CMD_REC_ON; |
||
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; |
||
78 | } |
||
79 | else // Middle |
||
80 | { |
||
730 | holgerb | 81 | if(((UART_VersionInfo.HWMajor >= 30) && TRIGGER_PP_INTERN) || ((UART_VersionInfo.HWMajor < 30) && (FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE))) // internal Portpin or Flag |
728 | holgerb | 82 | { |
83 | if(!p63) ToCamCtrl.CamCommand |= CAM_CMD_SHUTTER; // combined with the FC trigger output |
||
84 | p63 = 1; |
||
85 | } |
||
86 | else p63 = 0; |
||
87 | } |
||
88 | } |
||
89 | |||
90 | I2CBus_Transmission(I2C0, CAM_SLAVE_ADDRESS, &ToCamCtrl, TxBytes, &CamCtrl_UpdateData, RxBytes); |
||
91 | |||
92 | if(!EE_Parameter.CamCtrlModeChannel) ToCamCtrl.CamCommand = 0; // delete REC_OFF |
||
93 | ToCamCtrl.CamCommand = CAM_CMD_SWITCH_ON | (ToCamCtrl.CamCommand & (CAM_CMD_REC_ON | CAM_CMD_REC_OFF)); |
||
94 | timing = 66; // 66ms = 15Hz |
||
95 | } |
||
730 | holgerb | 96 | else timing = 11; // try again in 11ms |
728 | holgerb | 97 | } |