static int protothreadExplode(struct pt *pt) { static unsigned long ts = 0; PT_BEGIN(pt); while(1) { PT_WAIT_UNTIL(pt, state == STATE_EXPLODE); ts = millis(); // countdown before explode int tDelay = 100; while (millis() - ts < 3000) { redInd(true); piezo(true); _delay_ms(tDelay); redInd(false); piezo(false); _delay_ms(tDelay); if (tDelay > 10) tDelay -= 10; } // explode unsigned long data; data = 0b100000110000000011101000; for (int i = 1; i < 4; i++) { redInd(true); piezo(true); sendSony(data, 24); _delay_ms(200); redInd(false); piezo(false); _delay_ms(100); } state = STATE_FIND_ME; } PT_END(pt); }
void sony_chdown(void) { int i = 0; for (i = 0; i < 3; i++) { sendSony(0x890, 12); // Sony TV power code usleep(10000); //delayMicroseconds(10000); } }
void sendCode(int repeat) { if (codeType == NEC) { if (repeat) { sendNEC(REPEAT, codeLen); printf("Sent NEC repeat\n"); } else { sendNEC(codeValue, codeLen); printf("Sent NEC "); printf("%X", codeValue); } } else if (codeType == SONY) { sendSony(codeValue, codeLen); printf("Sent Sony "); printf("%X", codeValue); } else if (codeType == RC5 || codeType == RC6) { if (!repeat) { // Flip the toggle bit for a new button press toggle = 1 - toggle; } // Put the toggle bit into the code to send codeValue = codeValue & ~(1 << (codeLen - 1)); codeValue = codeValue | (toggle << (codeLen - 1)); if (codeType == RC5) { printf("Sent RC5 "); printf("%X", codeValue); sendRC5(codeValue, codeLen); } else { sendRC6(codeValue, codeLen); printf("Sent RC6 "); printf("%X\n", codeValue); } } else if (codeType == UNKNOWN /* i.e. raw */) { // Assume 38 KHz sendRaw(rawCodes, codeLen, 38000); printf("Sent raw\n"); } }