void sane_close (SANE_Handle h) { TScanner *s; HP5400_DBG (DBG_MSG, "sane_close\n"); s = (TScanner *) h; /* turn of scanner lamp */ SetLamp (&s->HWParams, FALSE); /* close scanner */ HP5400Close (&s->HWParams); /* free scanner object memory */ free ((void *) s); }
//int main(void) __attribute__((noreturn)); // Main never returns so don't waste stack space on it. int main(void) { Uint8 RxBuf[BCMsgSize]; Uint8 Destination; // Address we will reply to Uint8 RetryTime; Uint8 RetryCount; bool PowerOnTest; Uint16 Phase; Uint8 OldKey; Uint8 NewKey; Uint8 LampSet; bool OnSet; Uint8 BrightnessSet; Uint8 TempByte; // Set up the I/O lines DDRB = PortDirB; DDRC = PortDirC; DDRD = PortDirD; PINB = PortPullUpB; PINC = PortPullUpC; PIND = PortPullUpD; SetBit(MosLEDPort,MosLED); // Init the periphials InitLamps(); SetLamp(0); Timer_Init(); // Set up timers sei(); // Enable global interrupts // Keyboard test /* OldKey = 0; Destination = 0xff; SetLamps(Destination); for(;;){ if (OldKey != GetKey()) { OldKey = GetKey(); if (OldKey) { Destination ^= 1 << (OldKey - 1); SetLamps(Destination); DelayMS(100); } } } */ // Final set up BCMessageInit(BCAKeypadController); // Set up the UART BCMessageReceive(RxBuf); // Kick off receive PowerOnTest = true; Phase = 0; RetryTime = 0; RetryCount = 0; OldKey = 0; LampSet = 0; OnSet = false; BrightnessSet = 0; SetLamps(0b11111111); // Enter the main loop for( ; ; ) { // Run forever DelayMS(LoopRate); /* Phase++; LED1; // Look for new commands if (BCRXAvail) { // We have a new message if ((RxBuf[BCPAddr] & 0b1111) == BCAKeypadController) { // Check it is for us Destination = RxBuf[BCPAddr] >> 4; // Preset up assuming we will reply Destination &= 0b1111; Destination |= BCAKeypadController << 4; TxBuf[BCPAddr] = Destination; DelayMS(2); // Allow line turn around delay switch (RxBuf[BCPType]) { case BCTAck: // An ack of our key event RetryTime = 0; // They got it so cancel retry counter break; case BCTNAck: // Negative acknowledge break; case BCTLamps: // Set lamps PowerOnTest = false; SetLamps(RxBuf[BCPParam1]); TxBuf[BCPType] = BCTAck; TxBuf[BCPParam1] = 0; TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf, true); // Send the reply break; case BCTLampBrightness: // Set lamp brightness TxBuf[BCPParam1] = 0; TxBuf[BCPParam2] = 0; LampSet = RxBuf[BCPParam1] >> 4; OnSet = RxBuf[BCPParam1] & 0b00001000; BrightnessSet = (RxBuf[BCPParam1] & 0b111) << 2; if (BrightnessSet == 0b11100) BrightnessSet = 255; if (LampSet == 0b1111) { // If all lamps for (TempByte = 0; TempByte < MaxLamp; TempByte++) if (OnSet) LampsOn[TempByte] = BrightnessSet; else LampsOff[TempByte] = BrightnessSet; } else if (LampSet < MaxLamp) { // Valid individual lamp // TxBuf[BCPParam1] = LampSet; // TxBuf[BCPParam2] = BrightnessSet; if (OnSet) LampsOn[LampSet] = BrightnessSet; else LampsOff[LampSet] = BrightnessSet; } else { // Invalid lamp so NAck it TxBuf[BCPType] = BCTNAck; TxBuf[BCPParam1] = BCNBadParam1; TxBuf[BCPParam2] = RxBuf[BCPParam1]; } BCMessageSend(TxBuf, true); // Send the reply break; default: // Unknown command TxBuf[BCPType] = BCTNAck; TxBuf[BCPParam1] = BCNUnkownType; TxBuf[BCPParam2] = RxBuf[BCPType]; BCMessageSend(TxBuf, true); // Send the reply break; } } BCMessageReceive(RxBuf); // Kick off receive of next frame } // Look for change of key state if (!RetryTime) { // Don't send a new key while waiting for the last one to be acknowledged NewKey = GetKey(); if (NewKey != OldKey) { // If change of key state // if ((NewKey != OldKey) && // If change of key state // (RetryTime < (RetryTimePeriod - KeyDebouncePeriod))) { // and not too soon after the last one (debounce) SendKey(NewKey); RetryTime = RetryTimePeriod; RetryCount = 0; OldKey = NewKey; } } // Handle retry of key message if (RetryTime) if (!--RetryTime) { if (RetryCount++ < 3) { SendKey(OldKey); RetryTime = RetryTimePeriod; } } */ // Test LEDs //if (PowerOnTest) { //SetLamp((~Phase >> 7) & 0b111); // Rotate clockwise, the negate makes this opposite of what 031-517-202 does //} NewKey = GetKey(); //SetLamp((~NewKey) & 0b111); if(NewKey > 0) { SetLamps((~(1 << (NewKey-1))) & 0b11111111); DelayMS(500); } else { SetLamps(0b11111111); } } }
//int main(void) __attribute__((noreturn)); // Main never returns so don't waste stack space on it. int main(void) { Uint16 TempInt; // Set up the I/O lines DDRA = PortDirA; DDRB = PortDirB; SD_PowerOn(); DDRC = PortDirC; DDRD = PortDirD; PINA = PortPullUpA; PINB = PortPullUpB; PINC = PortPullUpC; PIND = PortPullUpD; //set the channel is the keyboard. //mp3 init finish ,after reset the slave board have volume; SetBit(SelAPort, Sel0A); SetBit(SelAPort, Sel1A); SetBit(SelBPort, Sel0B); SetBit(SelBPort, Sel1B); SetBit(SelCPort, Sel0C); SetBit(SelCPort, Sel1C); LastError = 0; // Indicate no errors yet // Init the peripherals Timer_Init(); // Set up timers UART_Init(); InitKey(); BCMessageInit(BCAMP3Contoller); wdt_enable(WDTO_8S);//wdt 8s // Set up key vars UART_Rx(CmdRxBuf, 1); Track = 1; IdleTime = 0; FlashPhase = 0; Volume = 0; PreMuteVolume = 0; Ramp = NoRamp; LastKey = 0; for(Bay = LeftBay; Bay <= NoBay; Bay++) { BayProduct[Bay] = UnknownProduct; BaySource[Bay] = 0xff; } Bay = LeftBay; SlaveMode = false; SlaveModePara = 0; sei(); // Enable global interrupts // Print product build banner wdt_reset(); UART_TxStr("\r\n======================================\r\n031-517-202 "); UART_TxChar('0' + SWVerMajor); UART_TxChar('.'); UART_TxChar('0' + SWVerMinor); UART_TxChar('.'); UART_TxChar('0' + SWVerFix); UART_TxChar(' '); UART_TxStr(__TIME__); UART_TxChar(' '); UART_TxStr(__DATE__); UART_TxStr("\r\n======================================\r\n"); // For reset the slave board maybe volume very high so have noise // so first set volume is 0 wdt_reset(); BCMessageReceive(RxBuf); // Finished with it so get ready for next msg ExchangeBoardMsg(BCALeftBay, BCTVolume, 0, 0, BCTAck); BCMessageReceive(RxBuf); // Finished with it so get ready for next msg ExchangeBoardMsg(BCACenterBay, BCTVolume, 0, 0, BCTAck); BCMessageReceive(RxBuf); // Finished with it so get ready for next msg ExchangeBoardMsg(BCARightBay, BCTVolume, 0, 0, BCTAck); BCMessageReceive(RxBuf); // Finished with it so get ready for next msg // Test the LEDs while bays boot up DelayMS(100); // Allow some time for keypad to boot up UART_TxStr("Testing LEDs\r\n"); for (TempInt = 1; TempInt <= 2; TempInt++){ for (Key = 1; Key <= MaxKey; Key++) { if(!SetLamp(Key)){ SlaveMode = true; break; } DelayMS(250); wdt_reset();//feed the watchdog } if(SlaveMode) break; } // Show version number if(!SlaveMode){ SetLamps(0); DelayMS(1000); SetLamps(LeftLEDs | SWVerMajor); DelayMS(2000); wdt_reset(); SetLamps(RightLEDs | SWVerMinor); DelayMS(2000); wdt_reset(); SetLamps(LeftLEDs | RightLEDs | SWVerFix); DelayMS(2000); wdt_reset(); } // Load EEPROM settings SetLamp(1); LoadEEPROMSetting(); UART_TxStr("Settings:\r\n"); PrintSettings(); //wait for tablet ready wait 60 seconds if(SlaveMode) { UART_TxStr("Wait for tablet ready\r\n"); for(TempInt = 0; TempInt < 6000; TempInt++) { DelayMS(10); CheckForBoardMsg(); wdt_reset(); } } // Prepare MP3 decoder for work wdt_reset(); // Feed the watchdog DelayMS(500); SetLamp(4); Timer_Clear(); for (TempInt = 1; TempInt <= 5; TempInt++) { if (MP3_Init()) break; // If init ok exit loop wdt_reset(); // Feed the watchdog DelayMS(250); // Wait before trying again } MP3_Volume(250); UART_TxStr("MP3 init time = "); UART_TxNum(Timer_Read(), 1); UART_TxStr("mS\r\n"); // Find the last track on the card wdt_reset(); SetLamp(3); for (Tracks = 1; Tracks <= 99; Tracks++) { if (!MP3_OpenFile(Tracks)) break; } Tracks--; SetBassTreble(); // Set the audio curve // Determine what is connected wdt_reset(); SetLamp(2); SearchDevices(); if(!SlaveMode) { ConfigDevices(); // Configure connected devices SetIdleState(); MP3_Track(1); if (!InputPresent[MP3In]) // If no MP3 player display error ShowError(ErrorNoMP3, false); } UART_TxStr("Start up complete\r\n"); // // Enter the main loop // Timer_Clear(); SlaveModeTimerClear(); for( ; ; ) { // Run forever if (SlaveMode) { // In slave mode only handle slave mode messages CheckForBoardMsg(); if(SlaveModeTimerRead() > 5000) { UART_TxNum(SlaveModeTimerRead(),5); UART_TxStr("\r\nMore than 5 seconds change to normal mode\r\n"); SlaveMode = false;//return to Normal mode SearchDevices(); Volume = 99; //if Volume == IdleVolume the not need send the volume so need give the diffent IdleVolume value Bay = RightBay; SetIdleState(); SetMux(Input,LeftBay); SetMux(Input,CenterBay); SetMux(Input,RightBay); } wdt_reset(); // Update the watchdog } else { // Not in slave mode so feed the MP3 engine if (MP3Ready && !MP3_Process()) MainLoop(0); // Tell the main loop we have stopped playback // Call the main loop if it is due if (Timer_Read() >= LoopPeriod) { // Run the main loop at 10Hz Timer_Clear(); MainLoop(1); // Tell the main loop we are still playing a track } } } return 0; }