Skip to content

Commit

Permalink
introduce config.h and rework ds aux switch code
Browse files Browse the repository at this point in the history
  • Loading branch information
wertarbyte committed Jun 15, 2012
1 parent 9e347ce commit 432713c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
15 changes: 15 additions & 0 deletions config.h
@@ -0,0 +1,15 @@
/*** Funkenschlag configuration file ***/


/* Datenschlag configuration */

#define DS_RETRANSMITS 0

// transmit switches 1, 2 and 3 via data channel as AUX2-AUX4
#define DS_SEND_AUX_SWITCHES {-1, 1, 2, 3}

// transmit gimbal data
//#define DS_SEND_GIMBAL_ANGLE

// transmit reference heading
//#define DS_SEND_MAG_HEADING
9 changes: 7 additions & 2 deletions datenschlag.c
Expand Up @@ -6,9 +6,14 @@
#include "datenschlag.h"
#include "datenschlag_structs.h"

#define DS_RETRANSMITS 2
#include "config.h"

#define DS_TX_BUFFER_SIZE 5

#if !defined(DS_RETRANSMITS)
#define DS_RETRANSMITS 0
#endif

struct ds_qframe {
struct ds_frame frame;
uint8_t transmits;
Expand Down Expand Up @@ -59,7 +64,7 @@ uint8_t ds_add_frame(uint8_t cmd, uint8_t *payload, uint8_t size) {

/* clear the next free slot in the tx queue */
struct ds_qframe *qf = &tx_buffer[(tx_buffer_start+tx_buffer_items)%DS_TX_BUFFER_SIZE];
qf->transmits = DS_RETRANSMITS;
qf->transmits = (1+DS_RETRANSMITS);
struct ds_frame *f = &qf->frame;
memset(f, 0, sizeof(*f));
/* fill the frame */
Expand Down
24 changes: 12 additions & 12 deletions src_ds.c
Expand Up @@ -8,18 +8,20 @@
#include "src_ds.h"
#include "datenschlag_structs.h"
#include "datenschlag.h"
#include "config.h"

void ds_prepare(void) {
#define DS_CMD_ANY 0xFF

uint8_t ds_payload[DS_MAX_PAYLOAD_LENGTH] = {0};
#ifdef DS_SEND_AUX_SWITCHES
/* check switch for Datenschlag */
static uint8_t old_switch = 0;
uint8_t ds_payload[DS_MAX_PAYLOAD_LENGTH] = {0};
#define DS_CMD_ANY 0xFF
#define SEND_AUX_SWITCHES
#ifdef SEND_AUX_SWITCHES
#define DS_AUX_SW_START 1
#define DS_AUX_SW_END 3
for (uint8_t i=DS_AUX_SW_START; i<=DS_AUX_SW_END; i++) {
switch (sw_get_raw(i)) {
uint8_t sw[] = DS_SEND_AUX_SWITCHES;
for (uint8_t i=0; i<sizeof(sw)/sizeof(sw[0]) && i<4; i++) {
int8_t n=sw[i];
if (n<0) continue; // -1 ignores the switch channel
switch (sw_get_raw(n)) {
case 0:
ds_payload[0] |= 1<<i;
break;
Expand All @@ -44,8 +46,7 @@ void ds_prepare(void) {
ds_add_frame(DS_CMD_AUX, &ds_payload[0], 1);
}
#endif
//#define SEND_MAG_HEADING
#ifdef SEND_MAG_HEADING
#ifdef DS_SEND_MAG_HEADING
/* send orientation */
#define DS_CMD_SET_HEADING (2<<5 | 0x04)
static int16_t dir = 0; // set real orientation here
Expand All @@ -55,8 +56,7 @@ void ds_prepare(void) {
ds_add_frame(DS_CMD_SET_HEADING, &ds_payload[0], 2);
}
#endif
//#define SEND_GIMBAL_ANGLE
#ifdef SEND_GIMBAL_ANGLE
#ifdef DS_SEND_GIMBAL_ANGLE
#define DS_GIMBAL_ANGLE_THRESHOLD 30
/* send orientation */
#define DS_CMD_SET_GIMBAL (1<<5 | 0x0C)
Expand Down

0 comments on commit 432713c

Please sign in to comment.