Skip to content

Instantly share code, notes, and snippets.

@msloth
Created June 29, 2018 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msloth/e6a6cde5afdc1d2af6321b9cade97f77 to your computer and use it in GitHub Desktop.
Save msloth/e6a6cde5afdc1d2af6321b9cade97f77 to your computer and use it in GitHub Desktop.
Modified client launchpad
#include "thsq.h"
#include "ti-lib.h"
#include "gpio-interrupt.h"
#include "lib/sensors.h"
#include "batmon-sensor.h"
#include "dev/leds-arch.h"
#include "dev/cc26xx-uart.h"
/*---------------------------------------------------------------------------*/
/* defines to help set default schedules */
#define MON (1 << 0)
#define TUE (1 << 1)
#define WED (1 << 2)
#define THU (1 << 3)
#define FRI (1 << 4)
#define SAT (1 << 5)
#define SUN (1 << 6)
#define WEEKDAYS (MON | TUE | WED | THU | FRI)
#define WEEKEND (SAT | SUN)
#define ALL_WEEK (WEEKDAYS | WEEKEND)
#define LEN_PER_DEFAULT_SCHEDULE 7 /* if RGB, then each schedule entry is 7 bytes */
/*---------------------------------------------------------------------------*/
void
init_leds(void)
{
leds_arch_set_pins(IOID_6, IOID_7, IOID_UNUSED);
}
/*---------------------------------------------------------------------------*/
void
init_uart(void)
{
cc26xx_uart_init(IOID_3, IOID_2, IOID_UNUSED, IOID_UNUSED);
}
/*---------------------------------------------------------------------------*/
static void
callback_thsq(enum thsq_reason r, const char *msg, int len)
{
if(r == THSQ_PERIOD) {
int value;
value = batmon_sensor.value(BATMON_SENSOR_TYPE_VOLT);
thsq_sset_printf("b", "%d.%03d", value / 1000, value % 1000);
thsq_sset("t", batmon_sensor.value(BATMON_SENSOR_TYPE_TEMP));
thsq_push();
}
}
/*---------------------------------------------------------------------------*/
static void
lighting_cb(const uint8_t *rgb, int len, const char *reason)
{
printf("lighting %u, %s\n", rgb[0], reason);
}
/*---------------------------------------------------------------------------*/
void
app(void)
{
/* Initialize the lighting module */
thsq_lighting_init();
thsq_lighting_set_lamp();
static struct thsq_lighting_callback tlcb;
thsq_lighting_add_callback(&tlcb, lighting_cb);
/* let motion sensor burn full for a short while, and local control as well */
thsq_lighting_set_default_pir(2, 15, 100, 100, 100);
thsq_lighting_set_default_lc(4, 30);
/* Initialize the configurable GPIO module */
thsq_gpio_init();
/*
* GPIO defaults
* aabbccddD
*
* aa = gpio out
* bb = adc in
* cc = pwm out
* dd = gpio in, D = U/D/N (pullup/down/none)
* aa/bb/cc/dd are zero-padded integers corresponding to IOID_n, or -- for none/remove
*/
thsq_gpio_set_default("07230515D");
thsq_gpio_trigger_pir_on_gpio(1);
/* Make the GPIO module listen to events from the lighting module. */
thsq_gpio_attach_lighting();
/* default schedule */
uint8_t default_sch[] = {'w',WEEKDAYS,8,0,50,50,50,
'w',WEEKDAYS,10,15,0,0,0,
'w',WEEKDAYS,12,0,50,50,50,
'w',WEEKDAYS,17,0,0,0,0};
thsq_schedule_set_default(default_sch, LEN_PER_DEFAULT_SCHEDULE * 4);
/* Restore lighting settings from before last reboot. This must be
called after attaching the GPIO module to the lighting module to
make the lighting settings be transported to the GPIO module. */
thsq_lighting_apply_last();
/* Setup the periodic callback for the temperature sensor */
static struct thsq_callback cb;
thsq_add_callback(&cb, callback_thsq);
SENSORS_ACTIVATE(batmon_sensor);
}
/*---------------------------------------------------------------------------*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment