mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2024-11-22 07:36:17 +02:00
tornado/fw/sim/alg.c: separate data processing from sample generation
This commit is contained in:
parent
4d09658036
commit
07e0df0d6a
@ -44,28 +44,37 @@ static uint16_t sample(double t)
|
|||||||
#define E_SHIFT 3 /* ~ 0.1 */
|
#define E_SHIFT 3 /* ~ 0.1 */
|
||||||
#define M_SHIFT 10 /* ~ 1/S */
|
#define M_SHIFT 10 /* ~ 1/S */
|
||||||
|
|
||||||
int main(void)
|
|
||||||
|
static void process(unsigned v)
|
||||||
{
|
{
|
||||||
uint16_t e = MID << E_SHIFT;
|
uint16_t e = MID << E_SHIFT;
|
||||||
uint32_t m = MID << M_SHIFT;
|
uint32_t m = MID << M_SHIFT;
|
||||||
int d;
|
int d;
|
||||||
int i;
|
|
||||||
bool up = 0;
|
bool up = 0;
|
||||||
|
|
||||||
|
e = v+(e-(e >> E_SHIFT));
|
||||||
|
m = v+(m-(m >> M_SHIFT));
|
||||||
|
d = (e >> E_SHIFT)-(m >> M_SHIFT);
|
||||||
|
if (up) {
|
||||||
|
if (d < -H)
|
||||||
|
up = 0;
|
||||||
|
} else {
|
||||||
|
if (d > H)
|
||||||
|
up = 1;
|
||||||
|
}
|
||||||
|
printf("%d %d %d %d %d\n",
|
||||||
|
v, e >> E_SHIFT, m >> M_SHIFT, d, up);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
for (i = 0; i != 10*S; i++) {
|
for (i = 0; i != 10*S; i++) {
|
||||||
unsigned v = sample((double) i/S);
|
unsigned v = sample((double) i/S);
|
||||||
e = v+(e-(e >> E_SHIFT));
|
|
||||||
m = v+(m-(m >> M_SHIFT));
|
process(v);
|
||||||
d = (e >> E_SHIFT)-(m >> M_SHIFT);
|
|
||||||
if (up) {
|
|
||||||
if (d < -H)
|
|
||||||
up = 0;
|
|
||||||
} else {
|
|
||||||
if (d > H)
|
|
||||||
up = 1;
|
|
||||||
}
|
|
||||||
printf("%d %d %d %d %d\n",
|
|
||||||
v, e >> E_SHIFT, m >> M_SHIFT, d, up);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user