コード例 #1
0
        public void Run()
        {
            this.IsRunning = true;
            bool goodToGo = InitializeNetwork();

            if (goodToGo)
            {
                Debug.Print("Sending capturing request");

                var jpeg = ArduCAM_Mini.SingleShotCapture();
                //ArduCAM_Mini.SingleShotCapture();
                //UploadFilesToRemoteUrl("http://192.168.0.102:5000/upload/");
                Debug.Print("Uploading to web server");

                WebRequest request = WebRequest.Create("http://192.168.0.102:5000/upload/");
                request.Method        = "POST";
                request.ContentType   = "image/jpeg";
                request.ContentLength = jpeg.Length;

                Debug.Print("Writing jpeg to data stream");
                Stream dataStream = request.GetRequestStream();
                dataStream.Write(jpeg, 0, jpeg.Length);
                dataStream.Close();

                Debug.Print("Getting response");
                WebResponse response = request.GetResponse();
                dataStream = response.GetResponseStream();
                StreamReader reader             = new StreamReader(dataStream);
                string       responseFromServer = reader.ReadToEnd();
                Debug.Print(responseFromServer);
                reader.Close();
                dataStream.Close();
                response.Close();
            }

            this.IsRunning = false;
        }
コード例 #2
0
        //public static void SingleShotCapture()
        public static byte[] SingleShotCapture()
        {
            // configure an output port for us to "write" to the LED
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

            //OutputPort CS_Port = new OutputPort(Pins.GPIO_PIN_D7, true);

            SDCard.OutputSDInfo();

            var volume = new VolumeInfo("SD");

            if (volume == null)
            {
                throw new IOException("No sdcard found!!");
            }

            Debug.Print("Attempting to instantiate ArduCAM_Mini");
            ArduCAM_Mini arduCAM = new ArduCAM_Mini();

            arduCAM.writeRegister(0x07, 0x80);
            Thread.Sleep(100);
            arduCAM.writeRegister(0x07, 0x80);
            Thread.Sleep(100);

            Thread.Sleep(10);
            arduCAM.writeRegister(ARDUCHIP_TEST1, 0x55);

            byte testByte = arduCAM.readRegister(ARDUCHIP_TEST1);

            if ((int)testByte == 0x55)
            {
                Debug.Print("Successfully wrote and read back " + testByte.ToString("X2") + " to test register");
            }
            else
            {
                throw new NotSupportedException("Test register didn't return 0x55!!");
            }

            arduCAM.ClearBit(ARDUCHIP_GPIO, GPIO_PWDN_MASK);

            arduCAM.writeI2CRegister(0xFF, 0x01);
            byte[] writeReadback = arduCAM.readI2CRegister(0xFF);
            if ((int)writeReadback[0] == 0x01)
            {
                Debug.Print("Successfully confirmed i2c WRITE OV2640_MINI_2MP");
            }
            else
            {
                throw new NotSupportedException("Unable to write to register!");
            }

            Debug.Print("--\n");
            byte[] chipVersionHigh = arduCAM.readI2CRegister(OV2640_CHIPID_HIGH);
            Thread.Sleep(10);
            Debug.Print("--\n");
            byte[] chipVersionLow = arduCAM.readI2CRegister(OV2640_CHIPID_LOW);
            Debug.Print("--\n");

            if ((int)chipVersionHigh[0] == 0x26 && ((int)chipVersionLow[0] == 0x41 || (int)chipVersionLow[0] == 0x42))
            {
                Debug.Print("Succesfully confirmed i2c READ OV2640_MINI_2MP");
            }
            else
            {
                throw new NotSupportedException("Unknown sensor!");
            }

            Debug.Print("I2C is operational!");


            arduCAM.InitCam();

            Debug.Print("Clearing FIFO flag");
            arduCAM.ClearFIFO_Flag();

            Thread.Sleep(10);
            arduCAM.writeRegister(ARDUCHIP_FRAMES, 0x00);

            Thread.Sleep(10);

            //Debug.Print("Setting brightness to 4");
            //arduCAM.writeRegister(0xff, 0x00);
            //arduCAM.writeRegister(0x7c, 0x00);
            //arduCAM.writeRegister(0x7d, 0x04);
            //arduCAM.writeRegister(0x7c, 0x09);
            //arduCAM.writeRegister(0x7d, 0x40);
            //arduCAM.writeRegister(0x7d, 0x00);

            Thread.Sleep(10);

            Debug.Print("Attempting single capture");
            arduCAM.FlushFIFO();
            arduCAM.ClearFIFO_Flag();
            arduCAM.StartCapture();

            Thread.Sleep(100);
            int bit = arduCAM.GetBit(ARDUCHIP_TRIG, CAP_DONE_MASK);

            if (bit > 0)
            {
                Debug.Print("Capture complete!");
                arduCAM.SetBit(ARDUCHIP_GPIO, GPIO_PWDN_MASK);
                Thread.Sleep(100);

                Debug.Print("Saving capture...");
                //var sdcardFile = Path.Combine("SD", "capture.jpg");
                //var file = File.OpenWrite(sdcardFile);
                using (MemoryStream output = new MemoryStream())
                {
                    int temp = 0, temp_last = 0;
                    while ((temp != 0xD9) | (temp_last != 0xFF))
                    {
                        temp_last = temp;
                        temp      = (int)arduCAM.ReadFIFO();
                        //file.WriteByte((byte)temp);
                        output.Write(new byte[] { (byte)temp }, 0, 1);

                        Thread.Sleep(20);
                    }
                    //volume.FlushAll();
                    //Clear the capture done flag
                    arduCAM.ClearFIFO_Flag();
                    Debug.Print("Cleared FIFO flag after capture");
                    var outputArray = output.ToArray();
                    //var fixedArray = new byte[outputArray.Length - 1];

                    //Array.Copy(outputArray, 1, fixedArray, 0, outputArray.Length - 1);
                    //return fixedArray;
                    return(outputArray);
                }
            }
            else
            {
                throw new IOException("Capture not complete,  got bit as " + bit.ToString());
            }
        }