예제 #1
0
        public static LinuxEventDevice[] WaitEvents(params LinuxEventDevice[] fds)
        {
            unsafe
            {
                // Build up fd_set for read:
                const int FD_SETSIZE = 256;
                const int NFDBITS    = 8 * sizeof(ulong);
                const int fd_size    = FD_SETSIZE / NFDBITS;
                ulong *   fd_ptr     = stackalloc ulong[fd_size];
                int       maxfd      = 0;
                foreach (var dev in fds)
                {
                    int fd = dev;
                    if (fd > maxfd)
                    {
                        maxfd = fd;
                    }
                    fd_ptr[(fd / NFDBITS)] |= (1UL << (fd % NFDBITS));
                }

                // Await for read readiness:
                //Debug.WriteLine("fd_ptr[0] = {0:X08}", fd_ptr[0]);
                //Debug.WriteLine("select() blocked");
                select(maxfd + 1, fd_ptr, null, null, IntPtr.Zero);
                //Debug.WriteLine("select() unblocked");

                // Count number of fds ready:
                int numReady = 0;
                for (int i = 0; i < fd_size; i++)
                {
                    numReady += BitCount(fd_ptr[i]);
                }

                // Build set of fds that are ready:
                var ready = new LinuxEventDevice[numReady];
                int n     = 0;
                foreach (var dev in fds)
                {
                    int   fd   = dev;
                    ulong mask = (1UL << (fd % NFDBITS));
                    if ((fd_ptr[(fd / NFDBITS)] & mask) == mask)
                    {
                        ready[n] = dev;
                        n++;
                    }
                }

                return(ready);
            }
        }
예제 #2
0
        public void WaitEvents()
        {
            // Wait for events from our input files:
            var ready = LinuxEventDevice.WaitEvents(fsw, touchScreen);

            if (ready.Contains(fsw))
            {
                //Debug.WriteLine("fsw.PollEvents()");
                fsw.PollEvents();
            }
            if (ready.Contains(touchScreen))
            {
                //Debug.WriteLine("touchScreen.PollEvents()");
                touchScreen.PollEvents();
            }
        }
예제 #3
0
 private unsafe void writeBytes(byte *buf, int count)
 {
     LinuxEventDevice.write(fd, buf, (uint)count);
 }
예제 #4
0
 public void Dispose()
 {
     LinuxEventDevice.close(fd);
 }
예제 #5
0
 public MidiAlsaOut(string devicePath = "/dev/snd/midiC1D0")
 {
     this.devicePath = devicePath;
     this.fd         = LinuxEventDevice.open(this.devicePath, LinuxEventDevice.OpenFlags.WriteOnly | LinuxEventDevice.OpenFlags.NonBlock);
 }
예제 #6
0
        public RpiPlatform(int display)
        {
            midi        = new MidiAlsaOut();
            fsw         = new LinuxEventDevice("/dev/input/by-id/usb-413d_2107-event-mouse");
            touchScreen = new LinuxEventDevice("/dev/input/event1");

            fsw.EventListener         += Fsw_EventListener;
            touchScreen.EventListener += TouchScreen_EventListener;

            bcmDisplay = (ushort)display;

            bcm_host_init();

            uint bcmWidth, bcmHeight;

            graphics_get_display_size(bcmDisplay, out bcmWidth, out bcmHeight);

            FramebufferWidth  = Width = (int)bcmWidth;
            FramebufferHeight = Height = (int)bcmHeight;

            VC_RECT_T dst_rect;
            VC_RECT_T src_rect;

            dst_rect.x      = 0;
            dst_rect.y      = 0;
            dst_rect.width  = Width;
            dst_rect.height = Height;

            src_rect.x      = 0;
            src_rect.y      = 0;
            src_rect.width  = Width << 16;
            src_rect.height = Height << 16;

            // TODO: translate error codes into exceptions?
            Debug.WriteLine("vc_dispmanx_display_open(...)");
            dispman_display = vc_dispmanx_display_open(bcmDisplay);
            Debug.WriteLine("dispman_display = {0}", dispman_display);
            Debug.WriteLine("vc_dispmanx_update_start(...)");
            dispman_update = vc_dispmanx_update_start(0 /* priority */);
            Debug.WriteLine("dispman_update = {0}", dispman_update);

            Debug.WriteLine("vc_dispmanx_element_add(...)");
            dispman_element = vc_dispmanx_element_add(
                dispman_update,
                dispman_display,
                0 /*layer*/,
                ref dst_rect,
                0 /*src*/,
                ref src_rect,
                DISPMANX_PROTECTION_T.DISPMANX_PROTECTION_NONE,
                IntPtr.Zero /*alpha*/,
                IntPtr.Zero /*clamp*/,
                0 /*transform*/
                );
            Debug.WriteLine("dispman_element = {0}", dispman_element);

            Debug.WriteLine("vc_dispmanx_update_submit_sync(dispman_update)");
            checkError(vc_dispmanx_update_submit_sync(dispman_update));

            // Create OpenVGContext:
            Debug.WriteLine("new OpenVGContext()");
            vg = new OpenVGContext();
        }