Skip to content

Thingsquare Lighting development tips

Time synchronization

int thsq_has_time(void);
uint32_t thsq_get_time(void);

Observe lighting decisions

static void
callback_thsq(enum thsq_reason reason, const char *msg, int len)
{
  if(reason == THSQ_LIGHTING_CHANGED) {
    printf("lighting event: %.*s\n", len, msg);
    printf(" * red:   %d\n", thsq_lighting_current_red());
    printf(" * green: %d\n", thsq_lighting_current_green());
    printf(" * blue:  %d\n", thsq_lighting_current_blue());
  }
}

Test lighting locally

void thsq_lighting_set_lights(thsq_lighting_prio_t prio, int r, int g, int b, uint32_t dur);
thsq_lighting_set_lights(4, 100, 100, 100, 600);

Test PWM locally

thsq_pwm_cc26xx_cc13xx_conf(thsq_gpio_get_pwm_red(), IOID_6, 5000UL, GPT0_BASE, 0);
thsq_pwm_set_dutycycle(thsq_gpio_get_pwm_red(), 100);

Light switch example

const char * thsq_zones_get_zone(void);
int thsq_lighting_send(enum thsq_lighting_type t,
                       const uint8_t *zones, int zoneslen,
                       const uint8_t *data, int datalen, int broadcast);

static void
callback_thsq(enum thsq_reason reason, const char *msg, int len)
{
  if(reason == THSQ_GPIO_INPUT) {
   char *z = thsq_zones_get_zone();
   thsq_lighting_send(THSQ_LIGHTING_SWITCH, z, strlen(z), NULL, 0, 1);
  }
}