Hi,
I’m currently working on a projekt where I want to controll the movements of three 3pi (equipped with wixels) from my computer also connected to a wixel.
Its kind of the reverse from the example wireless_tilt_mouse example with the difference that the wixel connected to the computer does the sending.
But when I try to use the wireless_tilt_mouse app with the modification that the sender and receiver changes the status of the red light every time they send/receive data.
The problem is that the sender keeps swithching the led (ie sending) while the receiver doesn’t change at all.
I thought the radioQueueRxDoneWithPacket(); had to be excecuted at the receiving end before the sender was done with the data transmition, is this incorrect?
Anybody have any ideas why there seems to be no data incomming to the receiving end and why the sender keeps sending even if nothing is received?
the code i use for the sender is:
#include <wixel.h>
#include <usb.h>
#include <usb_com.h>
#include <usb_hid_constants.h>
#include <radio_queue.h>
#include <math.h>
#define TX_INTERVAL 1000 // time between transmissions (ms)
int32 CODE param_invert_x = 0;
int32 CODE param_invert_y = 0;
int32 CODE param_speed = 100;
void updateLeds()
{
usbShowStatusWithGreenLed();
LED_YELLOW(vinPowerPresent());
}
void txMouseState()
{
uint8 XDATA * txBuf;
static uint32 lastTx = 0;
if ((uint32)(getMs() - lastTx) > TX_INTERVAL && (txBuf = radioQueueTxCurrentPacket()))
{
float fx, fy, multiplier;
int8 x, y;
fx = -((float)adcRead(2 | ADC_BITS_12) - 1024) / 128; // fx = Acceleration in X direction (floating point)
fy = ((float)adcRead(1 | ADC_BITS_12) - 1024) / 128; // fy = Acceleration in Y direction
multiplier = sqrtf(fx * fx + fy * fy) * param_speed/100;
// Compute the x and y mouse change values to send.
x = (int8)(fx * multiplier);
y = (int8)(fy * multiplier);
if (param_invert_x){ x = -x; }
if (param_invert_y){ y = -y; }
// Construct a packet and transmit it on the radio.
txBuf[0] = 3; // Packet length in bytes.
txBuf[1] = 1;
txBuf[2] = 1;
txBuf[3] = 0;
radioQueueTxSendPacket();
LED_RED(!LED_RED_STATE);
lastTx = getMs();
}
}
void main()
{
systemInit();
usbInit();
radioQueueInit();
// disable pull-ups on accelerometer outputs
setDigitalInput(1, HIGH_IMPEDANCE);
setDigitalInput(2, HIGH_IMPEDANCE);
while(1)
{
updateLeds();
boardService();
usbComService();
txMouseState();
}
}
The code for the receiver:
#include <wixel.h>
#include <usb.h>
#include <usb_hid.h>
#include <radio_queue.h>
void updateLeds()
{
usbShowStatusWithGreenLed();
}
void rxMouseState(void)
{
uint8 XDATA * rxBuf;
if (rxBuf = radioQueueRxCurrentPacket())
{
radioQueueRxDoneWithPacket();
if((uint32)getMs()%500==0){ // atmost every 0.5s wouldnt notice if blinking/receiveing was to fast.
LED_RED(!LED_RED_STATE);
}
}
}
void main()
{
systemInit();
usbInit();
radioQueueInit();
while(1)
{
updateLeds();
boardService();
//usbHidService();
rxMouseState();
}
}
Thankfull for any help I can get!
/Simon Larson