2016-07-28 18:12:07 +02:00
|
|
|
#include "gintdemo.h"
|
|
|
|
#include <gray.h>
|
|
|
|
#include <keyboard.h>
|
|
|
|
#include <mpu.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
test_gray()
|
|
|
|
Lets the user set the gray delays and see the results.
|
|
|
|
*/
|
|
|
|
|
2017-07-11 13:51:56 +02:00
|
|
|
static void draw(int delay1, int delay2, int selected, int gran)
|
2016-07-28 18:12:07 +02:00
|
|
|
{
|
2017-03-26 18:38:32 +02:00
|
|
|
extern image_t res_opt_gray;
|
|
|
|
uint32_t *vl = gray_lightVRAM();
|
|
|
|
uint32_t *vd = gray_darkVRAM();
|
2016-07-28 18:12:07 +02:00
|
|
|
|
|
|
|
gclear();
|
2016-08-29 11:29:07 +02:00
|
|
|
locate(1, 1, "Gray engine");
|
2016-07-28 18:12:07 +02:00
|
|
|
|
2017-07-05 21:38:12 +02:00
|
|
|
for(int i = 0; i < 64; i++)
|
2016-07-28 18:12:07 +02:00
|
|
|
{
|
2017-07-05 21:38:12 +02:00
|
|
|
int offset = (i << 2) + 3;
|
|
|
|
vl[offset] = -(!(i & 16));
|
|
|
|
vd[offset] = -(i < 32);
|
2016-07-28 18:12:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 13:51:56 +02:00
|
|
|
print(2, 3, "light %d", delay1);
|
|
|
|
print(2, 4, " dark %d", delay2);
|
|
|
|
print(2, 6, "Mode: \x04%d", gran);
|
2016-07-28 18:12:07 +02:00
|
|
|
|
2017-07-11 13:51:56 +02:00
|
|
|
int lengths[2] = {
|
|
|
|
4 - (delay1 < 1000),
|
|
|
|
4 - (delay2 < 1000)
|
|
|
|
};
|
|
|
|
print(8, 3 + selected, "\x01");
|
|
|
|
print(9 + lengths[selected], 3 + selected, "\x02");
|
2016-07-28 18:12:07 +02:00
|
|
|
|
2016-09-04 11:35:41 +02:00
|
|
|
gimage(0, 56, &res_opt_gray);
|
2016-07-28 18:12:07 +02:00
|
|
|
gupdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_gray(void)
|
|
|
|
{
|
|
|
|
int delays[2]; // { light, dark }
|
|
|
|
int key, changed = 1;
|
|
|
|
int selected = 0;
|
2017-07-11 13:51:56 +02:00
|
|
|
int gran = 1;
|
2016-07-28 18:12:07 +02:00
|
|
|
|
|
|
|
gray_getDelays(delays, delays + 1);
|
|
|
|
gray_start();
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
if(changed)
|
|
|
|
{
|
|
|
|
gray_setDelays(delays[0], delays[1]);
|
2017-07-11 13:51:56 +02:00
|
|
|
draw(delays[0], delays[1], selected, gran);
|
2016-07-28 18:12:07 +02:00
|
|
|
}
|
|
|
|
changed = 0;
|
|
|
|
|
2017-07-11 13:51:56 +02:00
|
|
|
key = getkey_opt(getkey_default, 25);
|
2016-07-28 18:12:07 +02:00
|
|
|
if(key == KEY_EXIT) break;
|
|
|
|
|
|
|
|
changed = 1;
|
|
|
|
|
|
|
|
switch(key)
|
|
|
|
{
|
|
|
|
case KEY_F1:
|
2016-08-29 11:29:07 +02:00
|
|
|
delays[0] = 912;
|
|
|
|
delays[1] = 1343;
|
2016-07-28 18:12:07 +02:00
|
|
|
break;
|
2017-07-11 13:51:56 +02:00
|
|
|
case KEY_F2:
|
2016-08-29 11:29:07 +02:00
|
|
|
delays[0] = 993;
|
|
|
|
delays[1] = 1609;
|
|
|
|
break;
|
2017-07-11 13:51:56 +02:00
|
|
|
case KEY_F3:
|
2016-07-28 18:12:07 +02:00
|
|
|
delays[0] = 860;
|
|
|
|
delays[1] = 1298;
|
|
|
|
break;
|
2017-07-11 13:51:56 +02:00
|
|
|
case KEY_F5:
|
|
|
|
if(gran >= 100) gran = 1;
|
|
|
|
else gran *= 10;
|
2016-07-28 18:12:07 +02:00
|
|
|
case KEY_UP:
|
2017-07-11 13:51:56 +02:00
|
|
|
selected = 0;
|
2016-07-28 18:12:07 +02:00
|
|
|
break;
|
|
|
|
case KEY_DOWN:
|
2017-07-11 13:51:56 +02:00
|
|
|
selected = 1;
|
2016-07-28 18:12:07 +02:00
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
2017-07-11 13:51:56 +02:00
|
|
|
if(delays[selected] - gran >= 100)
|
|
|
|
delays[selected] -= gran;
|
|
|
|
break;
|
|
|
|
case KEY_RIGHT:
|
|
|
|
if(delays[selected] + gran < 10000)
|
|
|
|
delays[selected] += gran;
|
2016-07-28 18:12:07 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
changed = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gray_stop();
|
|
|
|
}
|