diff --git a/conf/modules/digital_cam.xml b/conf/modules/digital_cam.xml index 8507667bfd..f03907a0b3 100644 --- a/conf/modules/digital_cam.xml +++ b/conf/modules/digital_cam.xml @@ -1,21 +1,42 @@ - -
- -
- - - - + + + +
+ +
+ + + + + + + + + + + +
diff --git a/conf/modules/digital_cam_i2c.xml b/conf/modules/digital_cam_i2c.xml new file mode 100644 index 0000000000..17a91367ce --- /dev/null +++ b/conf/modules/digital_cam_i2c.xml @@ -0,0 +1,29 @@ + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + +
+ diff --git a/conf/settings/dc.xml b/conf/settings/dc.xml index 6cb5d9c9a7..b2e44f1e56 100644 --- a/conf/settings/dc.xml +++ b/conf/settings/dc.xml @@ -1,21 +1,24 @@ - - - - - - - - - - + + - - - + + + + + + + + + + + + + + diff --git a/sw/airborne/modules/digital_cam/atmega_i2c_cam_ctrl.c b/sw/airborne/modules/digital_cam/atmega_i2c_cam_ctrl.c new file mode 100644 index 0000000000..645cbe1294 --- /dev/null +++ b/sw/airborne/modules/digital_cam/atmega_i2c_cam_ctrl.c @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2010 The Paparazzi Team + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + + +/** \file atmega_i2c_cam_ctrl.c + * \brief Interface with digital camera though AVR AtMega chip + * + * Send Commands over I2C + */ + + +#include "atmega_i2c_cam_ctrl.h" + +#include "i2c.h" +#include "led.h" + +#ifndef DOWNLINK_DEVICE +#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE +#endif +#include "uart.h" +#include "messages.h" +#include "downlink.h" +#include "estimator.h" + + +static struct i2c_transaction atmega_i2c_cam_ctrl_trans; + +#ifndef ATMEGA_I2C_DEV +#define ATMEGA_I2C_DEV i2c0 +#endif + + +#ifndef ATMEGA_SLAVE_ADDR +#define ATMEGA_SLAVE_ADDR 0x68 +#endif + +uint8_t atmega_i2c_cam_ctrl_just_sent_command = 0; + +void atmega_i2c_cam_ctrl_init(void) +{ + atmega_i2c_cam_ctrl_trans.status = I2CTransDone; + dc_init(); +} + +void atmega_i2c_cam_ctrl_periodic (void) +{ + atmega_i2c_cam_ctrl_just_sent_command = 0; + dc_periodic_4Hz(); + + // Request Status + if (atmega_i2c_cam_ctrl_just_sent_command == 0) + { + atmega_i2c_cam_ctrl_send(DC_GET_STATUS); + } +} + + + +void atmega_i2c_cam_ctrl_send(uint8_t cmd) +{ + atmega_i2c_cam_ctrl_just_sent_command = 1; + + // Send Command + atmega_i2c_cam_ctrl_trans.buf[0] = cmd; + I2CTransceive(ATMEGA_I2C_DEV, atmega_i2c_cam_ctrl_trans, ATMEGA_SLAVE_ADDR, 1, 1); + + if (cmd == DC_SHOOT) + { + dc_send_shot_position(); + } +} + +void atmega_i2c_cam_ctrl_event( void ) +{ + if (atmega_i2c_cam_ctrl_trans.status == I2CTransSuccess) + { + unsigned char cam_ret[1]; + cam_ret[0] = atmega_i2c_cam_ctrl_trans.buf[0]; + RunOnceEvery(6,DOWNLINK_SEND_PAYLOAD(DefaultChannel, 1, cam_ret )); + atmega_i2c_cam_ctrl_trans.status = I2CTransDone; + } +} diff --git a/sw/airborne/modules/digital_cam/atmega_i2c_cam_ctrl.h b/sw/airborne/modules/digital_cam/atmega_i2c_cam_ctrl.h new file mode 100644 index 0000000000..e825df002b --- /dev/null +++ b/sw/airborne/modules/digital_cam/atmega_i2c_cam_ctrl.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 The Paparazzi Team + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#ifndef ATMEGA_I2C_CAM_CTRL_H +#define ATMEGA_I2C_CAM_CTRL_H + +// Include Standard Camera Control Interface +#include "dc.h" + + +void atmega_i2c_cam_ctrl_init(void); +void atmega_i2c_cam_ctrl_periodic(void); +void atmega_i2c_cam_ctrl_event(void); +void atmega_i2c_cam_ctrl_send(uint8_t cmd); + +// In I2C mode we can not inline this function: +static inline void dc_send_command(uint8_t cmd) +{ + atmega_i2c_cam_ctrl_send(cmd); +} + +// Allow commands to be set by datalink +#define ParseCameraCommand() { \ + { \ + if ( DL_PAYLOAD_COMMAND_command_length(dl_buffer) == 1){ \ + dc_send_command(DL_PAYLOAD_COMMAND_command(dl_buffer)[0]); \ + } \ + } \ +} + + +#endif diff --git a/sw/airborne/modules/digital_cam/dc.c b/sw/airborne/modules/digital_cam/dc.c index 4d0ba12a99..29543af74a 100644 --- a/sw/airborne/modules/digital_cam/dc.c +++ b/sw/airborne/modules/digital_cam/dc.c @@ -1,37 +1,91 @@ +/* + * Copyright (C) 2010 The Paparazzi Team + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + + #include "dc.h" -uint8_t dc_timer; -uint8_t dc_periodic_shutter; -uint8_t dc_shutter_timer; -uint8_t dc_utm_threshold; +// Variables with boot defaults +uint8_t dc_autoshoot_meter_grid = 100; +uint8_t dc_autoshoot_quartersec_period = 2; +dc_autoshoot_type dc_autoshoot = DC_AUTOSHOOT_STOP; + + + + +#ifdef SENSOR_SYNC_SEND + uint16_t dc_photo_nr = 0; -uint8_t dc_shoot = 0; - - #ifndef DOWNLINK_DEVICE #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE #endif #include "uart.h" #include "messages.h" #include "downlink.h" +#include "estimator.h" + + void dc_send_shot_position(void) + { + int16_t phi = DegOfRad(estimator_phi*10.0f); + int16_t theta = DegOfRad(estimator_theta*10.0f); + float gps_z = ((float)gps_alt) / 100.0f; + DOWNLINK_SEND_DC_SHOT(DefaultChannel, &dc_photo_nr, &gps_utm_east, &gps_utm_north, &gps_z, &gps_utm_zone, &phi, &theta, &gps_course, &gps_gspeed, &gps_itow); + dc_photo_nr++; + } + +#endif -void dc_send_shot_position(void) -{ - int16_t phi = DegOfRad(estimator_phi*10.0f); - int16_t theta = DegOfRad(estimator_theta*10.0f); - float gps_z = ((float)gps_alt) / 100.0f; - DOWNLINK_SEND_DC_SHOT(DefaultChannel, &dc_photo_nr, &gps_utm_east, &gps_utm_north, &gps_z, &gps_utm_zone, &phi, &theta, &gps_course, &gps_gspeed, &gps_itow); - dc_photo_nr++; -} - -uint8_t dc_shutter( void ) -{ - dc_timer = SHUTTER_DELAY; - DC_PUSH(DC_SHUTTER_LED); - dc_send_shot_position(); - - return 0; + +/* +#ifndef DC_GPS_TRIGGER_START +#define DC_GPS_TRIGGER_START 1 +#endif +#ifndef DC_GPS_TRIGGER_STOP +#define DC_GPS_TRIGGER_STOP 3 +#endif + + +static inline void dc_shoot_on_gps( void ) { + static uint8_t gps_msg_counter = 0; + + if (dc_shoot > 0) + { + + if (gps_msg_counter == 0) + { + DC_PUSH(DC_SHUTTER_LED); + + dc_send_shot_position(); + } + else if (gps_msg_counter == DC_GPS_TRIGGER_START) + { + DC_RELEASE(DC_SHUTTER_LED); + } + + gps_msg_counter++; + if (gps_msg_counter >= DC_GPS_TRIGGER_STOP) + gps_msg_counter = 0; + } } +*/ diff --git a/sw/airborne/modules/digital_cam/dc.h b/sw/airborne/modules/digital_cam/dc.h index 9d5bb6e063..06fc9d1f0e 100644 --- a/sw/airborne/modules/digital_cam/dc.h +++ b/sw/airborne/modules/digital_cam/dc.h @@ -1,7 +1,5 @@ /* - * Paparazzi $Id$ - * - * Copyright (C) 2003-2008 Pascal Brisset, Antoine Drouin + * Copyright (C) 2010 The Paparazzi Team * * This file is part of paparazzi. * @@ -22,29 +20,18 @@ * */ + /** \file dc.h - * \brief Digital Camera Control + * \brief Standard Digital Camera Control Interface * - * Provides the control of the shutter and the zoom of a digital camera - * through standard binary IOs of the board. + * -Standard IO + * -I2C Control * - * Configuration: - * Since the API of led.h is used, connected pins must be defined as led - * numbers (usually in the airframe file): - * - * - * Related bank and pin must also be defined: - * - * - * The required initialization (dc_init()) and periodic (4Hz) process - * (dc_periodic()) are called if the DIGITAL_CAM flag is set: - * ap.CFLAGS += -DDIGITAL_CAM - * - * Usage (from the flight plan, the settings or any airborne code): - * - dc_Shutter(_) sets the DC_SHUTTER_LED pin output to 1 for 0.5s and sends - * a DC_SHOT message - * - dc_Zoom(_) sets the DC_ZOOM_LED pin output to 1 for 0.5s - * - dc_Periodic(s) activates a periodic call to dc_Shutter() every s seconds + * Usage: (from the flight plan, the settings or any airborne code): + * - dc_send_command( ) + * - set the appropriate autoshoot mode (off/time/distance/trigger) + * - use the module periodic function to set the autorepeat interval + * - define SENSOR_SYNC_SEND to get the DC_SHOT_MESSAGE on every SHOOT command */ #ifndef DC_H @@ -53,124 +40,111 @@ #include "std.h" #include "led.h" #include "generated/airframe.h" -#include "estimator.h" #include "gps.h" -extern uint8_t dc_timer; +/* Generic Set of Digital Camera Commands */ +typedef enum { + DC_GET_STATUS = 0, -extern uint8_t dc_periodic_shutter; -/* In s. If non zero, period of automatic calls to dc_shutter() */ -extern uint8_t dc_shutter_timer; -/* In s. Related counter */ + DC_HOLD = 13, + DC_SHOOT = 32, -extern uint8_t dc_utm_threshold; -/* In m. If non zero, automatic shots when greater than utm_north % 100 */ + DC_WIDER = 'w', + DC_TALLER = 't', -/* Picture Number starting from zero */ -extern uint16_t dc_photo_nr; -extern uint8_t dc_shoot; + DC_UP = 'u', + DC_DOWN = 'd', + DC_CENTER = 'c', + DC_LEFT = 'l', + DC_RIGHT = 'r', -#ifndef DC_PUSH -#define DC_PUSH LED_ON -#endif + DC_MENU = 'm', + DC_HOME = 'h', + DC_PLAY = 'p', -#ifndef DC_RELEASE -#define DC_RELEASE LED_OFF -#endif + DC_ON = 'O', + DC_OFF = 'o', -#define SHUTTER_DELAY 2 /* 4Hz -> 0.5s */ +} dc_command_type; -uint8_t dc_shutter( void ); +/* Send Command To Camera */ +static inline void dc_send_command(uint8_t cmd); -static inline uint8_t dc_zoom( void ) { - dc_timer = SHUTTER_DELAY; -#ifdef DC_ZOOM_LED - DC_PUSH(DC_ZOOM_LED); -#endif - return 0; -} +/* Auotmatic Digital Camera Photo Triggering */ +typedef enum { + DC_AUTOSHOOT_STOP = 0, + DC_AUTOSHOOT_PERIODIC = 1, + DC_AUTOSHOOT_DISTANCE = 2, + DC_AUTOSHOOT_EXT_TRIG = 3 +} dc_autoshoot_type; +extern dc_autoshoot_type dc_autoshoot; -#define dc_Shutter(_) ({ dc_shutter(); 0; }) -#define dc_Zoom(_) ({ dc_zoom(); 0; }) -#define dc_Periodic(s) ({ dc_periodic_shutter = s; dc_shutter_timer = s; 0; }) +/* AutoShoot photos every X quarter_second */ +extern uint8_t dc_autoshoot_quartersec_period; -#ifndef DC_PERIODIC_SHUTTER -#define DC_PERIODIC_SHUTTER 0 -#endif - -#define dc_init() { /* initialized as leds */ dc_periodic_shutter = DC_PERIODIC_SHUTTER; DC_PUSH(DC_SHUTTER_LED);} /* Output */ - - -#ifndef DC_GPS_TRIGGER_START -#define DC_GPS_TRIGGER_START 1 -#endif -#ifndef DC_GPS_TRIGGER_STOP -#define DC_GPS_TRIGGER_STOP 3 -#endif +/* AutoShoot photos on a X meter Local Tangent Plane Grid */ +extern uint8_t dc_autoshoot_meter_grid; +/* Send Down the coordinates of where the photo was taken */ +#ifdef SENSOR_SYNC_SEND void dc_send_shot_position(void); - -static inline void dc_shoot_on_gps( void ) { - static uint8_t gps_msg_counter = 0; - - if (dc_shoot > 0) - { - - if (gps_msg_counter == 0) - { - DC_PUSH(DC_SHUTTER_LED); - - dc_send_shot_position(); - } - else if (gps_msg_counter == DC_GPS_TRIGGER_START) - { - DC_RELEASE(DC_SHUTTER_LED); - } - - gps_msg_counter++; - if (gps_msg_counter >= DC_GPS_TRIGGER_STOP) - gps_msg_counter = 0; - } -} - -/* 4Hz */ -static inline void dc_periodic( void ) { - if (dc_timer) { - dc_timer--; - } else { - DC_RELEASE(DC_SHUTTER_LED); -#ifdef DC_ZOOM_LED - DC_RELEASE(DC_ZOOM_LED); +#else +#define dc_send_shot_position() {} #endif - } - if (dc_shoot > 0) +/****************************************************************** + * FUNCTIONS + *****************************************************************/ + +/* get settings */ +static inline void dc_init(void) +{ +#ifdef DC_AUTOSHOOT_QUARTERSEC_PERIOD + dc_autoshoot_quartersec_period = DC_AUTOSHOOT_QUARTERSEC_PERIOD; +#endif +#ifdef DC_AUTOSHOOT_METER_GRID + dc_autoshoot_meter_grid = DC_AUTOSHOOT_METER_GRID; +#endif +} + +/* shoot on grid */ +static inline void dc_shot_on_utm_north_close_to_100m_grid( void ) +{ + uint32_t dist_to_100m_grid = (gps_utm_north / 100) % 100; + if (dist_to_100m_grid < dc_autoshoot_meter_grid || 100 - dist_to_100m_grid < dc_autoshoot_meter_grid) { - if (dc_periodic_shutter) { - RunOnceEvery(2, - { - if (dc_shutter_timer) { - dc_shutter_timer--; - } else { - dc_shutter(); - dc_shutter_timer = dc_periodic_shutter; - } - }); + dc_send_command(DC_SHOOT); + } +} + +/* periodic 4Hz function */ +static inline void dc_periodic_4Hz( void ) +{ + static uint8_t dc_shutter_timer = 0; + +#ifdef DC_AUTOSHOOT_QUARTERSEC_PERIOD + if (dc_autoshoot == DC_AUTOSHOOT_PERIODIC) + { + if (dc_shutter_timer) + { + dc_shutter_timer--; + } else { + dc_send_command(DC_SHOOT); + dc_shutter_timer = dc_autoshoot_quartersec_period; } } - else +#endif +#ifdef DC_AUTOSHOOT_METER_GRID + if (dc_autoshoot == DC_AUTOSHOOT_DISTANCE) { - dc_shutter_timer = 0; + // Shoot + dc_shot_on_utm_north_close_to_100m_grid(); } +#endif } -static inline void dc_shot_on_utm_north_close_to_100m_grid( void ) { - if (dc_utm_threshold && !dc_timer) { - uint32_t dist_to_100m_grid = (gps_utm_north / 100) % 100; - if (dist_to_100m_grid < dc_utm_threshold || 100 - dist_to_100m_grid < dc_utm_threshold) - dc_shutter(); - } -} + + #endif // DC_H diff --git a/sw/airborne/modules/digital_cam/led_cam_ctrl.c b/sw/airborne/modules/digital_cam/led_cam_ctrl.c new file mode 100644 index 0000000000..af9acb254a --- /dev/null +++ b/sw/airborne/modules/digital_cam/led_cam_ctrl.c @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2010 The Paparazzi Team + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#include "led_cam_ctrl.h" + +// Include Digital IO +#include "led.h" + +// Button Timer +uint8_t dc_timer; + + + + diff --git a/sw/airborne/modules/digital_cam/led_cam_ctrl.h b/sw/airborne/modules/digital_cam/led_cam_ctrl.h new file mode 100644 index 0000000000..fcf6a17b88 --- /dev/null +++ b/sw/airborne/modules/digital_cam/led_cam_ctrl.h @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2010 The Paparazzi Team + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + + +/** \file led_cam_ctrl.h + * \brief Digital Camera Control + * + * Provides the control of the shutter and the zoom of a digital camera + * through standard binary IOs of the board. + * + * Configuration: + * Since the API of led.h is used, connected pins must be defined as led + * numbers (usually in the airframe file): + * + * + * + * + * Related bank and pin must also be defined: + * + * + * The required initialization (dc_init()) and periodic (4Hz) process + * + */ + +#ifndef LED_CAM_CTRL_H +#define LED_CAM_CTRL_H + +// Include Standard Camera Control Interface +#include "dc.h" + +extern uint8_t dc_timer; + +static inline void led_cam_ctrl_init(void) +{ + // Call common DC init + dc_init(); + + // Do LED specific DC init + dc_timer = 0; +} + +#ifndef DC_PUSH +#define DC_PUSH LED_ON +#endif + +#ifndef DC_RELEASE +#define DC_RELEASE LED_OFF +#endif + +#ifndef SHUTTER_DELAY +#define SHUTTER_DELAY 2 /* 4Hz -> 0.5s */ +#endif + +#ifndef DC_SHUTTER_LED +#error DC: Please specify at least a SHUTTER LED +#endif + +/* Command The Camera */ +static inline void dc_send_command(uint8_t cmd) +{ + dc_timer = SHUTTER_DELAY; + switch (cmd) + { + case DC_SHOOT: + DC_PUSH(DC_SHUTTER_LED); + dc_send_shot_position(); + break; +#ifdef DC_ZOOM_IN_LED + case DC_ZOOM_IN: + DC_PUSH(DC_ZOOM_IN_LED); + break; +#endif +#ifdef DC_ZOOM_OUT_LED + case DC_ZOOM_OUT: + DC_PUSH(DC_ZOOM_OUT_LED); + break; +#endif +#ifdef DC_POWER_LED + case DC_POWER: + DC_PUSH(DC_POWER_LED); + break; +#endif + } +} + + +/* 4Hz Periodic */ +static inline void led_cam_ctrl_periodic( void ) +{ + if (dc_timer) { + dc_timer--; + } else { + DC_RELEASE(DC_SHUTTER_LED); +#ifdef DC_ZOOM_IN_LED + DC_RELEASE(DC_ZOOM_IN_LED); +#endif +#ifdef DC_ZOOM_OUT_LED + DC_RELEASE(DC_ZOOM_OUT_LED); +#endif +#ifdef DC_POWER_LED + DC_RELEASE(DC_POWER_LED); +#endif + } + + // Common DC Periodic task + dc_periodic_4Hz(); +} + + + + + +#endif // DC_H diff --git a/sw/airborne/modules/digital_cam/sim_i2c_cam_ctrl.c b/sw/airborne/modules/digital_cam/sim_i2c_cam_ctrl.c new file mode 100644 index 0000000000..c682e4ae37 --- /dev/null +++ b/sw/airborne/modules/digital_cam/sim_i2c_cam_ctrl.c @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2010 The Paparazzi Team + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + + +/** \file sim_i2c_cam_ctrl.c + * \brief Simulated Interface with digital camera + * + */ + + +#include "atmega_i2c_cam_ctrl.h" + + +#ifndef DOWNLINK_DEVICE +#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE +#endif +#include "uart.h" +#include "messages.h" +#include "downlink.h" +#include "estimator.h" + + +void atmega_i2c_cam_ctrl_init(void) +{ + dc_init(); +} + +void atmega_i2c_cam_ctrl_periodic (void) +{ + dc_periodic_4Hz(); + + // Request Status + dc_send_command(DC_GET_STATUS); +} + + + +void atmega_i2c_cam_ctrl_send(uint8_t cmd) +{ + static uint8_t zoom = 0; + static uint8_t mode = 0; + unsigned char cam_ret[1]; + + if (cmd == DC_SHOOT) + { + dc_send_shot_position(); + } + else if (cmd == DC_TALLER) + { + zoom = 1; + } + else if (cmd == DC_WIDER) + { + zoom = 0; + } + else if (cmd == DC_GET_STATUS) + { + mode++; + if (mode > 15) + mode = 0; + } + + cam_ret[0] = mode + zoom * 0x20; + RunOnceEvery(6,DOWNLINK_SEND_PAYLOAD(DefaultChannel, 1, cam_ret )); + +} + +void atmega_i2c_cam_ctrl_event( void ) +{ +} + + +