pebblisp/src/pebcom.c

52 lines
1.2 KiB
C

#include "pebcom.h"
#include <pebble.h>
struct tm* getTime()
{
time_t t = time(NULL);
return localtime(&t);
}
Object getSeconds(Object o1, Object o2, struct Environment* env)
{
return numberObject(getTime()->tm_sec);
}
Object getMinutes(Object o1, Object o2, struct Environment* env)
{
return numberObject(getTime()->tm_min);
}
Object getHours(Object o1, Object o2, struct Environment* env)
{
return numberObject(getTime()->tm_hour);
}
Object getTwelveHours(Object o1, Object o2, struct Environment* env)
{
int hour = (getTime()->tm_hour % 12) ?: 12;
return numberObject(hour);
}
Object doVibe(Object patternList, Object o2, struct Environment* env)
{
int length = listLength(&patternList);
uint32_t pattern[length];
if (length > 0) {
int i = 0;
Object* pl = &patternList;
FOR_POINTER_IN_LIST(pl) {
if (POINTER->type == TYPE_NUMBER) {
pattern[i] = POINTER->number;
}
i++;
}
vibes_enqueue_custom_pattern(
(VibePattern) {.durations = pattern, .num_segments = length});
return boolObject(1);
} else {
return errorObject(NOT_A_LIST);
}
}