Wii Nunchuk via RFM69HW to Duplo 9203 Remote Control Car Kit using ARM mbed on a FRDM-KL25Z
Dependencies: CRC FastPWM RFM69 USBDevice WakeUp WiiChuk_compat mbed-rtos mbed tlc59108
Fork of wiiNunchuk_compat by
Diff: main.cpp
- Revision:
- 16:3490cdea4986
- Parent:
- 15:8888e36afe43
- Child:
- 17:b9030e94b622
diff -r 8888e36afe43 -r 3490cdea4986 main.cpp --- a/main.cpp Tue Jun 28 10:43:05 2016 +0000 +++ b/main.cpp Tue Jun 28 11:54:04 2016 +0000 @@ -372,6 +372,21 @@ bool read = false; while(1) { if (sender) { + if (central_time.read() > 20) { + #if DEBUG + pc.printf("snooze tx %f\r\n", central_time.read()); + g = 0; Thread::wait(10); g = 1; Thread::wait(10); + #endif + Thread::wait(10); + WakeUp::set(1); + deepsleep(); + nun.Read(&n->X, &n->Y, &n->aX, &n->aY, &n->aZ, &n->C, &n->Z); + Thread::wait(10); + #if DEBUG + r = 0; Thread::wait(10); r = 1; Thread::wait(10); + pc.printf("unsnooze tx\r\n"); + #endif + } read = nun.Read(&n->X, &n->Y, &n->aX, &n->aY, &n->aZ, &n->C, &n->Z); n->sum = 0; n->sum = calculate_crc8((char*)n, sizeof(struct nunchuk)); @@ -423,8 +438,11 @@ //radio.send(GATEWAY_ID, (const void*)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 50, false); #endif - if (sender && central_time.read() < 10) - radio.send(GATEWAY_ID, (const void*)n, sizeof(struct nunchuk), false); + if (sender) + if (central_time.read() < 10) + radio.send(GATEWAY_ID, (const void*)n, sizeof(struct nunchuk), false); + else + radio.sleep(); #ifdef TARGET_KL25Z if (R < 20) {