#include "display.h"
#include <time.h>
-
inline static int readPin()
{
- return GPIORead(0);
-
+ return GPIORead(0);
}
static uint64_t nanos()
{
struct timespec now;
timespec_get(&now, TIME_UTC);
- return ((uint64_t) now.tv_sec) * 1000000000 + ((uint64_t) now.tv_nsec);
+ return ((uint64_t)now.tv_sec) * 1000000000 + ((uint64_t)now.tv_nsec);
}
+static void lines(const uint16_t line[chips*12]);
-static uint16_t pwmbuffer[chips][12];
-
+static void getDelay(uint64_t *delay, uint64_t *last);
-static void lines(uint16_t data[chips][12]);
-
-static void getDelay(uint64_t* delay, uint64_t* last);
-
-extern void display(bool* go,const uint16_t lester[degreesIn][chips*12],uint64_t* d){
+extern void display(bool *go, const uint16_t lester[3][degreesIn][chips * 12], bool *swap)
+{
GPIOInit();
- GPIOPinmode(0,IN);
+ GPIOPinmode(0, IN);
tlc59711_init("/dev/spidev0.1");
- uint64_t delay = 0,last=0;
+ uint64_t delay = 0, last = 0;
bool went_back = true;
-
+ int p = 0;
while (*go)
{ // main loop
for (int deg = 0; deg < degreesIn; deg++)
if (!readPin() && went_back) // we are still in the loop but we need to exit
goto end;
} // sleep between lines
- for (uint8_t i = 0; i < chips*12; i++)
- {
- pwmbuffer[(chips-1)-(i/12)][11-(i%12)] = lester[deg][i];
- }
- lines(pwmbuffer);
+
+ lines(lester[p][deg]);
}
end:
- while (readPin()); // wait till it goes low if we exited the loop early
+ while (readPin())
+ ; // wait till it goes low if we exited the loop early
getDelay(&delay, &last);
went_back = false; //make shure we trigger on the rising edge
- *d = delay
- printf("%llu\n",delay);
-
+ printf("%llu\n", delay);
+ if (p == 2)
+ p = 0;
+ else
+ p++;
+ *swap = true;
}
}
-static void getDelay(uint64_t* delay, uint64_t* last)
+static void getDelay(uint64_t *delay, uint64_t *last)
{
uint64_t tmp = *last;
*last = nanos();
- *delay = (*last - tmp) / degreesIn;
+ *delay = (*last - tmp) / degreesIn;
}
-static void lines(uint16_t line[chips][12])
+static void lines(const uint16_t line[chips*12])
{
- uint8_t* data = (uint8_t*)malloc(chips*28);
- for (int i = 0; i < chips; i++)
- tlc59711_create(line[i],data+(28*i));
- transfer(data,NULL,chips*28);
-
+ uint8_t data[chips*28];
+ uint16_t tmp[12];
+ for (int i = 0; i < chips; i++){
+ for(int b = 0; b < 12;b++)
+ tmp[11 - b] = line[(i*12)+b];
+
+ tlc59711_create(tmp, data + (28 * i));
+ }
+ transfer(data, NULL, chips * 28);
}