Skip to content

Instantly share code, notes, and snippets.

View adrianstevens's full-sized avatar

Adrian Stevens adrianstevens

View GitHub Profile
@adrianstevens
adrianstevens / gist:33452d648bd76bbd284213cf194f352d
Last active January 8, 2023 05:18
MicroGraphics with update governing and frame rate limiter
using Meadow.Foundation.Graphics.Buffers;
using System;
using System.Threading.Tasks;
namespace Meadow.Foundation.Graphics
{
/// <summary>
/// Feature extended version of MicroGraphics
/// </summary>
public class MicroGraphicsEx : MicroGraphics
@adrianstevens
adrianstevens / comet.cs
Created September 28, 2021 00:17
Snippet showing comet effect on a APA102 RGB led strip light powered by Wilderness Labs Meadow
void Comet(Apa102 ledStrip)
{
Random rand = new Random();
int length1 = 1;
float position1 = 0;
float speed1 = 1f;
Color cometColor1 = Color.Cyan;
int length2 = 1;
@adrianstevens
adrianstevens / MeadowThermApp
Created December 4, 2019 03:38
App class from Meadow Therm reference project
using System;
using System.Threading;
using Meadow;
using Meadow.Devices;
using Meadow.Hardware;
using Meadow.Peripherals.Sensors.Temperature;
using Meadow.Foundation.Sensors.Temperature;
using Meadow.Peripherals.Sensors.Atmospheric;
using System.Threading.Tasks;
@adrianstevens
adrianstevens / MeadowStaticDevice.cs
Created December 4, 2019 03:32
Example of accessing the static Device class
using System;
using System.Threading.Tasks;
using Meadow.Foundation;
using Meadow.Foundation.Displays.Tft;
using Meadow.Foundation.Graphics;
using Meadow.Hardware;
namespace Therm
{
/// <summary>
@adrianstevens
adrianstevens / gist:6483a24538431b9573c0dca525be91b1
Created August 13, 2019 05:01
Meadow Beta 3 USB deployment notes
Mount Meadow the F7 Test board (pogo board)
Cut JP101 & JP102 if you haven't already
Connect a microUSB cable to the Meadow Micro F7
Connect a microUSB cable to the connecter on the test board labelled "EDGE"
Open a terminal and connect it to the serial port for the EDGE connection (115,200, data bits 8, parity none, stop bits 1) CP210x on Windows
Put Meadow into DFU mode (disconnect, hold the boot button, add power, release boot button)
Verify Meadow is in DFU mode: dfu-util --list
Download latest nuttx bins https://drive.google.com/drive/u/0/folders/1-aHM8pmGQltHugIlxlhvkFhU_6lVLt1W
Flash nuttx dfu-util -a 0 -S 336B335B3036 -D nuttx.bin -s 0x08000000 && dfu-util -a 0 -S 336B335B3036 -D nuttx_user.bin -s 0x08040000
@adrianstevens
adrianstevens / MeadowBuildSteps.md
Last active July 17, 2021 05:48
Meadow build steps
  1. Install pre-reqs: ARM CCC, STLink utilities and ccache using BREW (brew.sh)
  2. Create a Meadow folder
  3. clone Meadow (https://github.com/WildernessLabs/Meadow) [Meadow/Nuttx]
  4. switch to wip-semihosting branch
  5. clone Nuttx tools (git clone https://bitbucket.org/nuttx/tools.git) [Meadow/tools]
  6. clone Nuttx apps (git clone https://github.com/WildernessLabs/apps) [Meadow/apps]
  7. switch apps to wip branch
  8. configure tools/kconfig
  • cd tools/kconfig-frontends
  • ./configure --enable-mconf --disable-nconf --disable-gconf --disable-qconf
namespace MoonPhase
{
public class MoonPhase
{
static double MoonCycleLength = 29.53059;
public int GetJulianDate(int day, int month, int year)
{
year = year - (12 - month) / 10;
/// <summary>
/// Compares two byte arrays in length-constant time. This comparison
/// method is used so that password hashes cannot be extracted from
/// on-line systems using a timing attack and then attacked off-line.
/// </summary>
/// <param name="a">The first byte array.</param>
/// <param name="b">The second byte array.</param>
/// <returns>True if both byte arrays are equal. False otherwise.</returns>
private static bool SlowEquals(byte[] a, byte[] b)
{
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
var password = "9a55W0rd!!";
var salt = Encoding.Unicode.GetBytes("5a1t");
byte[] keymaterial = NetFxCrypto.DeriveBytes.GetBytes(password, salt, 1000, 32);
@adrianstevens
adrianstevens / gist:5c1c33e20d911cf9121c
Created April 10, 2015 23:49
IOS mapping - distance between two points
using System;
using CoreGraphics;
using Foundation;
using UIKit;
using MapKit;
using CoreLocation;
using System.Diagnostics;
namespace MappingApp
{