/// <summary> /// </summary> /// <param name="port">COM port name</param> /// <param name="contactsPath">Path to contacts VCF file</param> public BluetoothOVC3860(string port, string contactsPath = null) { Name = "Bluetooth"; queue = new QueueThreadWorker(ProcessSendCommand); this.port = new SerialInterruptPort(new SerialPortConfiguration(port, BaudRate.Baudrate115200), Cpu.Pin.GPIO_NONE, 0, 16, 10); this.port.DataReceived += port_DataReceived; if (contactsPath != null) { if (File.Exists(contactsPath)) { this.contactsPath = contactsPath; } else { Logger.Info("No contacts file " + contactsPath); } } HomeScreen.Instance.PhoneScreen = CreatePhoneScreen(); //SendCommand("MH"); // disable auto conn VolumeUp(); // TODO make loop: volume up }
public BluetoothWT32(string port, string pin = "0000") { Name = "Bluetooth"; this.pin = pin; SPPLink = Link.Unset; queue = new QueueThreadWorker(ProcessSendCommand); this.port = new SerialInterruptPort(new SerialPortConfiguration(port, BaudRate.Baudrate115200, Parity.None, 8, StopBits.One, true), Cpu.Pin.GPIO_NONE, 0, 60, 0); this.port.NewLine = "\n"; this.port.DataReceived += port_DataReceived; BTCommandReceived += (s, link, data) => { if (link == Link.Control) { ProcessBTNotification(Encoding.UTF8.GetString(data)); } }; IsMuxMode = true; //Thread.Sleep(1000); IsMuxMode = false; throw new Exception("WOW"); SendCommand("RESET"); }
static E65Seats() { DriverSeat = new E65SeatInfo(); PassengerSeat = new E65SeatInfo(); queueWorker = new QueueThreadWorker(ProcessQueue); }
public SerialPortHub(params ISerialPort[] ports) { this.ports = ports; queues = new QueueThreadWorker[ports.Length]; for (int i = 0; i < ports.Length; i++) { int index = i; ISerialPort port = ports[index]; queues[index] = new QueueThreadWorker((o) => { byte[] data = (byte[])o; port.Write(data, 0, data.Length); }); } for (int i = 0; i < ports.Length; i++) { int index = i; ISerialPort port = ports[index]; // Read each port and forward data to other ports port.DataReceived += (s, e) => { byte[] data = port.ReadAvailable(); Write(data, 0, data.Length, index); OnDataReceived(data, data.Length); }; } }
public static void Init(ISerialPort port) { messageWriteQueue = new QueueThreadWorker(SendMessage); //messageReadQueue = new QueueThreadWorker(ProcessMessage); iBus = port; iBus.DataReceived += new SerialDataReceivedEventHandler(iBus_DataReceived); }
public void InitPort(ISerialPort port, string queueThreadWorkerName = "", ThreadPriority threadPriority = ThreadPriority.AboveNormal) { messageWriteQueue = new QueueThreadWorker(SendMessage, queueThreadWorkerName, threadPriority); //messageReadQueue = new QueueThreadWorker(ProcessMessage); _port = port; _portName = queueThreadWorkerName; _port.DataReceived += bus_DataReceived; Inited = true; }
public iPodViaHeadset(Cpu.Pin headsetControl, Cpu.Pin volumeUp = Cpu.Pin.GPIO_NONE, Cpu.Pin volumeDown = Cpu.Pin.GPIO_NONE) { Name = "iPod"; iPod = new OutputPort(headsetControl, false); canControlVolume = volumeUp != Cpu.Pin.GPIO_NONE && volumeDown != Cpu.Pin.GPIO_NONE; if (canControlVolume) { iPodVolumeUp = new OutputPort(volumeUp, false); iPodVolumeDown = new OutputPort(volumeDown, false); } iPodCommands = new QueueThreadWorker(ExecuteIPodCommand); }
public VolumioRestApiPlayer(Cpu.Pin chipSelect, Cpu.Pin externalInterrupt, Cpu.Pin reset) { commands = new QueueThreadWorker(ProcessCommand, "httpRequestsThread", ThreadPriority.Lowest); var netif = new EthernetENC28J60(SPI.SPI_module.SPI2, chipSelect, externalInterrupt /*, reset*/); netif.Open(); ////netif.EnableDhcp(); ////netif.EnableDynamicDns(); netif.EnableStaticIP("169.254.194.93", "255.255.0.0", "0.0.0.0"); int attemps = 0; while (netif.IPAddress != "169.254.194.93" && attemps++ < 4) { System.Threading.Thread.Sleep(250); } Inited = true; CheckStatusThread.Start(); }
public VS1003Player(Cpu.Pin MP3_DREQ, Cpu.Pin MP3_CS, Cpu.Pin MP3_DCS, Cpu.Pin MP3_RST) { generateNextTrackQueue = new QueueThreadWorker(GenerateNextTrack, "generateNextTrackQueue", ThreadPriority.Lowest); #region prepare dataConfig = new SPI.Configuration(MP3_DCS, false, 0, 0, false, true, 1000, SPI.SPI_module.SPI2); cmdConfig = new SPI.Configuration(MP3_CS, false, 0, 0, false, true, 1000, SPI.SPI_module.SPI2); DREQ = new InputPort(MP3_DREQ, false, Port.ResistorMode.PullUp); spi = new SPI(dataConfig); DisableMidi(); Thread.Sleep(100); //Reset(); SCIWrite(SCI_CLOCKF, 0x8800); SCIWrite(SCI_VOL, 0x2828); //ClearPlayback(); if (SCIRead(SCI_VOL) != (0x2828)) { throw new Exception("VS1053: Failed to initialize MP3 Decoder."); } else { Logger.Log(LogPriority.Info, "VS1053: Initialized MP3 Decoder."); } #endregion SetVolume((byte)255); Logger.Trace("Getting files and folders:"); if (VolumeInfo.GetVolumes().Length > 0 && VolumeInfo.GetVolumes()[0].IsFormatted) { //byte[] testBuffer = new byte[256]; //FileStream stream = null; string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory; try { for (byte diskNumber = 1; diskNumber <= 6; diskNumber++) { var folder = rootDirectory + "\\" + diskNumber; byte filesCount = 0; byte erroredFilesCounts = 0; var files = Directory.EnumerateFiles(folder); foreach (var fileObj in files) { if (((string)fileObj).EndsWith(".mp3") /* || file.EndsWith(".m4a")*/) { //#if DEBUG // if (Debugger.IsAttached) // { // try // { // stream = new FileStream((string) fileObj, FileMode.Open, FileAccess.Read); // stream.Read(testBuffer, 0, testBuffer.Length); // } // catch (Exception ex) // { // erroredFilesCounts++; // Logger.Trace("Error during test reading if file - " + (string) fileObj); // } // finally // { // stream.Close(); // } // } //#endif filesCount++; } else { Logger.Trace("File is not mp3 file - " + (string)fileObj); } } files = null; StorageInfo[diskNumber] = filesCount; ErrorsInfo[diskNumber] = erroredFilesCounts; totalTracksCount += filesCount; Logger.Trace("Files count on " + diskNumber + " = " + filesCount); Logger.Trace("Error files count on " + diskNumber + " = " + erroredFilesCounts); } } catch (Exception ex) { Logger.Error(ex, "while Directory.EnumerateFiles"); } FileStream dataFile = null; byte[] lastTrackInfo = new byte[7] { 1, 1, 0, 0, 0, 0, 0 }; try { dataFile = File.Open(rootDirectory + "\\data.bin", FileMode.OpenOrCreate); dataFile.Read(lastTrackInfo, 0, lastTrackInfo.Length); DiskNumber = lastTrackInfo[0]; TrackNumber = lastTrackInfo[1]; IsRandom = lastTrackInfo[2] == 1; CurrentPosition = BitConverter.ToInt32(lastTrackInfo, 3); } catch (Exception ex) { Logger.Error(ex, "while reading lastTrackInfo"); } finally { if (dataFile != null) { dataFile.Close(); } } try { var diskAndTrack = GenerateConcreteDiskAndTrack(DiskNumber, TrackNumber); FileName = diskAndTrack.fileName; CurrentTrack = new TrackInfo(diskAndTrack.fileName); } catch (Exception ex) { DiskNumber = TrackNumber = 1; Logger.Error(ex, "while generating CurrentTrack "); } // generate prepared next random tracks GeneratePreparedNextTracks(DiskNumber); Action saveHistory = () => { FileStream dataFileWrite = null; try { dataFileWrite = File.Open(rootDirectory + "\\data.bin", FileMode.OpenOrCreate); var cp = BitConverter.GetBytes(CurrentPosition); byte isRandomValue = IsRandom ? (byte)1 : (byte)0; byte[] lastTrackInfoWrite = new byte[7] { DiskNumber, TrackNumber, isRandomValue, cp[0], cp[1], cp[2], cp[3] }; dataFileWrite.Write(lastTrackInfoWrite, 0, lastTrackInfo.Length); } finally { if (dataFileWrite != null) { dataFileWrite.Close(); VolumeInfo.GetVolumes()[0].FlushAll(); } } }; //TrackChanged += (sender, trackInfo) => { saveHistory(); }; IsPlayingChanging += (sender, isPlayingBeforeChaning) => { if (isPlaying) { saveHistory(); } }; Inited = true; } else { CurrentTrack = new TrackInfo("\\_-_.mp3"); Inited = false; Logger.Log(LogPriority.Warning, "Storage is not formatted. " + "Format on PC with FAT32/FAT16 first!"); } }
static Comfort() { commands = new QueueThreadWorker(ProcessCommand); InstrumentClusterElectronics.SpeedRPMChanged += (e) => { if (needLockDoors && e.Speed > DoorsLockSpeed) { if (AutoLockDoors) { BodyModule.LockDoors(); } needLockDoors = false; needUnlockDoors = true; } if (e.Speed == 0) { needLockDoors = true; } }; InstrumentClusterElectronics.IgnitionStateChanged += (e) => { if (!needComfortClose && e.CurrentIgnitionState != IgnitionState.Off && e.PreviousIgnitionState == IgnitionState.Off) { needComfortClose = true; } if (needUnlockDoors && e.CurrentIgnitionState == IgnitionState.Off) { if (AutoUnlockDoors) { BodyModule.UnlockDoors(); } needUnlockDoors = false; needLockDoors = true; } }; BodyModule.RemoteKeyButtonPressed += (e) => { if (e.Button == RemoteKeyButton.Lock && needComfortClose) { needComfortClose = false; if (AutoCloseWindows) { commands.Enqueue(Command.FullCloseWindows); } if (AutoCloseSunroof) { BodyModule.CloseSunroof(); } if (AutoFoldMirrors) { BodyModule.FoldMirrors(); } } if (e.Button == RemoteKeyButton.Unlock) { if (AutoUnfoldMirrors) { BodyModule.UnfoldMirrors(); } } }; }
static Comfort() { // uncomment when will use comfort commands = new QueueThreadWorker(ProcessCommand, "comfortThread", ThreadPriority.Lowest); //InstrumentClusterElectronics.SpeedRPMChanged += (e) => //{ // if (needLockDoors && e.Speed > DoorsLockSpeed) // { // if (AutoLockDoors) // { // BodyModule.LockDoors(); // } // needLockDoors = false; // needUnlockDoors = true; // } // if (e.Speed == 0) // { // needLockDoors = true; // } //}; //InstrumentClusterElectronics.IgnitionStateChanged += (e) => //{ // if (!needComfortClose // && e.CurrentIgnitionState != IgnitionState.Off // && e.PreviousIgnitionState == IgnitionState.Off) // { // needComfortClose = true; // } // if (needUnlockDoors && e.CurrentIgnitionState == IgnitionState.Off) // { // if (AutoUnlockDoors) // { // BodyModule.UnlockDoors(); // } // needUnlockDoors = false; // needLockDoors = true; // } //}; BodyModule.RemoteKeyButtonPressed += (e) => { if (e.Button == RemoteKeyButton.Lock) { //if (needComfortClose) //{ // needComfortClose = false; // if (AutoCloseWindows) // { // //commands.Enqueue(Command.FullCloseWindows); // } // if (AutoCloseSunroof) // { // BodyModule.CloseSunroof(); // } // if (AutoFoldMirrors) // { // BodyModule.FoldMirrors(); // } //} BlinkLamps(); } if (e.Button == RemoteKeyButton.Unlock) { //if (AutoUnfoldMirrors) //{ // BodyModule.UnfoldMirrors(); //} BlinkLamps(); } }; }