Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am phardy on github.
  • I am stibbons (https://keybase.io/stibbons) on keybase.
  • I have a public key ASCIK6J-9K0SjUIAMiGWKjLgGKrtfyfP80nAKOfyWqf_mgo

To claim this, I am signing this object:

@phardy
phardy / gist:57d53f38873ab948f6eb
Created November 18, 2014 10:08
rising-edge latching of bit field
void controlGroupLatch() {
uint16_t mask;
uint16_t state = controlGroupToggle[0];
// Only care about the first mux bank at the moment
mask = ~lastMuxState[0] & muxState[0]; // Mask of all changed inputs
mask = mask & muxState[0]; // Mask of changed inputs that are now high
state = state ^ mask; // Apply mask to toggle state
controlGroupToggle[0] = state;
}
uint16_t MuxShield::digitalReadBank(int mux)
{
digitalWrite(_OUTMD,LOW);
digitalWrite(_S0, LOW);
digitalWrite(_S1, LOW);
digitalWrite(_S2, LOW);
digitalWrite(_S3, LOW);
uint16_t val = 0;
switch (mux) {
case 1:
@phardy
phardy / test.c
Created March 7, 2014 12:42
Pebble SDK default sketch
#include <pebble.h>
static Window *window;
static TextLayer *text_layer;
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(text_layer, "Select");
}
static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
@phardy
phardy / strtol-test4.c
Created August 18, 2013 06:17
Pebble strtol test #4. This defines a long in the global scope, then attempts to assign the output of strtol to it. This code compiles but crashes at runtime.
#include "pebble_os.h"
#include "pebble_app.h"
#include "pebble_fonts.h"
#define MY_UUID { 0x92, 0x40, 0x44, 0xC0, 0xCA, 0x8A, 0x43, 0x64, 0x9D, 0xDE, 0x11, 0x33, 0x6F, 0x04, 0xA9, 0x3F }
PBL_APP_INFO(MY_UUID,
"strtol test", "Your Company",
1, 0, /* App version */
DEFAULT_MENU_ICON,
APP_INFO_STANDARD_APP);
@phardy
phardy / strtol-test3.c
Created August 18, 2013 06:12
Pebble strtol test #3. This declares a long in the same scope as assigning to it with strtol, but in a separate statement. gcc throws a warning about mynum being set but not used.
#include "pebble_os.h"
#include "pebble_app.h"
#include "pebble_fonts.h"
#define MY_UUID { 0x92, 0x40, 0x44, 0xC0, 0xCA, 0x8A, 0x43, 0x64, 0x9D, 0xDE, 0x11, 0x33, 0x6F, 0x04, 0xA9, 0x3F }
PBL_APP_INFO(MY_UUID,
"strtol test", "Your Company",
1, 0, /* App version */
DEFAULT_MENU_ICON,
APP_INFO_STANDARD_APP);
@phardy
phardy / strol-test2.c
Created August 18, 2013 06:07
Pebble strtol test #2. I declare a long and assign the output of strtol to it in the same statement. The long is not referenced again. This code compiles and runs to completion, showing "done" on the Pebble's display.
#include "pebble_os.h"
#include "pebble_app.h"
#include "pebble_fonts.h"
#define MY_UUID { 0x92, 0x40, 0x44, 0xC0, 0xCA, 0x8A, 0x43, 0x64, 0x9D, 0xDE, 0x11, 0x33, 0x6F, 0x04, 0xA9, 0x3F }
PBL_APP_INFO(MY_UUID,
"strtol test", "Your Company",
1, 0, /* App version */
DEFAULT_MENU_ICON,
APP_INFO_STANDARD_APP);
@phardy
phardy / strtol-test1.c
Created August 18, 2013 05:58
Pebble strtol test #1. This shows strtol returning 0 when compiled with SDK 1.12. When numstr is set to "-37" it causes a runtime crash.
#include "pebble_os.h"
#include "pebble_app.h"
#include "pebble_fonts.h"
#define MY_UUID { 0x92, 0x40, 0x44, 0xC0, 0xCA, 0x8A, 0x43, 0x64, 0x9D, 0xDE, 0x11, 0x33, 0x6F, 0x04, 0xA9, 0x3F }
PBL_APP_INFO(MY_UUID,
"strtol test", "Your Company",
1, 0, /* App version */
DEFAULT_MENU_ICON,
APP_INFO_STANDARD_APP);