示例#1
0
        public StillCam(string imageFolder)
        {
            imgcounter = 1;
            folder     = imageFolder;
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            foreach (var file in Directory.EnumerateFiles(folder))
            {
                int count = Int32.Parse(file.Remove(file.IndexOf('.')).Substring(file.LastIndexOf('/') + 1));
                if (imgcounter <= count)
                {
                    imgcounter = count + 1;
                }
            }
            int interval = PiDashcamSettings.Load().StillCamInterval;

            timer          = new System.Timers.Timer(interval);
            timer.Elapsed += Timer_Elapsed;
            timer.Start();
        }
示例#2
0
        public static void Main(string[] args)
        {
            IRecorder    recorder = null;
            DashCamState state    = DashCamState.IDLE_NO_NETWORK;

            driver.Allocate(VEHICLE_PIN, PinDirection.Input);

            settings = PiDashcamSettings.Load();
            if (settings == null)
            {
                settings = new PiDashcamSettings();
                settings.Save();
            }

            if (settings.RecordMode == "still")
            {
                recorder = new StillCam("image");
            }
            else
            {
            }

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    if (Console.ReadKey().KeyChar.Equals('q'))
                    {
                        break;
                    }
                }
                Thread.Sleep(1000);
                switch (state)
                {
                case DashCamState.IDLE_NO_NETWORK:
                    if (IsVehicleRunning())
                    {
                        state = DashCamState.VEHICLE_RUNNING;
                        recorder.Start();
                    }
                    if (IsConnectedToInternet())
                    {
                        state = DashCamState.IDLE_WITH_NETWORK;
                    }
                    break;

                case DashCamState.IDLE_WITH_NETWORK:
                    if (IsVehicleRunning())
                    {
                        state = DashCamState.VEHICLE_RUNNING;
                        recorder.Start();
                    }
                    if (!IsConnectedToInternet())
                    {
                        state = DashCamState.IDLE_NO_NETWORK;
                    }
                    UploadData();
                    break;

                case DashCamState.VEHICLE_RUNNING:
                    if (!IsVehicleRunning())
                    {
                        state = DashCamState.IDLE_NO_NETWORK;
                        recorder.Stop();
                    }
                    break;
                }
            }
            if (recorder != null)
            {
                recorder.Stop();
            }
        }