Skip to content

Instantly share code, notes, and snippets.

/// <summary>
/// The SerialRead callback returns the text read from the Read method
/// </summary>
public delegate void SerialRead(SerialPort port, string text);
/// <summary>
/// Read text from the port using a callback when text is ready
/// </summary>
public void Read(SerialRead readComplete)
{
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace Ports
{
/// <summary>
/// The partity to use when opening a serial port
public static void ReadNext(SerialPort port, string s)
{
Console.Write(s);
port.Read(ReadNext);
}
public static void TestRead()
{
Console.WriteLine("Testing serial port reads");
/// <summary>
/// The SerialRead callback returns the text read from the Read method
/// </summary>
public delegate void SerialRead(SerialPort port, string text);
/// <summary>
/// Read text from the port using a callback when text is ready
/// </summary>
public void Read(SerialRead readComplete)
{
@sysrpl
sysrpl / gist:d642bdbf9406aa21d77338f7873a32c4
Created March 3, 2020 14:46
An interface to libgphoto2 for Free Pascal
unit GPhoto2;
{$mode delphi}
interface
uses
Classes, SysUtils;
type
(********************************************************)
(* *)
(* Bare Game Library *)
(* http://www.baregame.org *)
(* 2.0.0.0 Released under the LGPL license 2017 *)
(* *)
(********************************************************)
{ <include docs/bare.system.txt> }
unit Bare.System;
{$ifndef fpc}
'This library requires the free pascal compiler'
{$endif}
{$if fpc_fullversion < 30000}
'This library requires the free pascal compiler 3.0.0 or greater'
{$endif}
{$mode delphi}
{$macro on}
{$packrecords c}
#region Safer functions
public static unsafe void glDeleteBuffers(ref int[] buffers)
{
var n = buffers.Length;
fixed (int* b = buffers)
_glDeleteBuffers(n, b);
}
public static unsafe int[] glGenBuffers(int n)
{
var buffers = new int[n];
namespace Bare.Geometry
{
public struct Mat4
{
float m00;
float m01;
float m02;
float m03;
float m10;
float m11;
@sysrpl
sysrpl / gist:55ab2a0d142a2f96f0fd2f44bb845cc2
Created June 6, 2017 15:27
Dynamic loading of opengl es 2.o
/// <summary>
/// Delegates contains the function definitions for OpenGL ES 2.0.
/// </summary>
public static class Delegates
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void glActiveTexture(int texture);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void glAttachShader(int program, int shader);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]