1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-01 11:28:26 +02:00
antorcha/fw/antorcha.c
Werner Almesberger 695bc5a25a fw/: reduce image width from 100 to 80 square pixels
To achieve square 100 pixels (1:6.25 image aspect ratio), very vigorous
movement is needed. 80 pixels (still 1:5) are easier. Initial estimates
suggested a usable range of 1:4-1:5, so this is still good.

Note that we may want to change the aspect ratio of the pixels themselves
in the future (for smoother letters), so the pixel count may go up again.

80 pixels correspond to 11 characters in a 7x5 font with 2 pixels
separation between characters. We may want to go up to 82 pixels
to allow a 12th character - or use a proportional font.
2012-06-23 21:57:18 -03:00

136 lines
2.4 KiB
C

/*
* fw/antorcha.c - Initialization of Antorcha application firmware
*
* Written 2012 by Werner Almesberger
* Copyright 2012 Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <stddef.h>
#include <stdint.h>
#include "rf.h"
#include "dispatch.h"
#include "sweep.h"
#include "accel.h"
#include "image.h"
#include <avr/interrupt.h>
#include "io.h"
static struct sweep sweep = {
.wait_ticks = 60000, /* 60 ms */
.pixel_ticks = 1000, /* 1 ms */
.left = 0,
.right = MAX_LINES-1,
.forward = 1,
};
static volatile enum sync_state {
IDLE,
LEFT_DECEL,
LEFT_ACCEL,
FWD_START_SWEEP,
FWD_SWEEP,
} state = IDLE;
#define LEFT_DECEL_THRESH 850
#define LEFT_REVERSE_THRESH 900
#define LEFT_ACCEL_THRESH 850
#define RIGHT_DECEL_THRESH 200
static void sync_sweep(bool x, uint16_t v)
{
static uint32_t t;
if (!x)
return;
switch (state) {
default:
case IDLE:
if (v < LEFT_DECEL_THRESH)
break;
state = LEFT_DECEL;
t = uptime_irq();
break;
case LEFT_DECEL:
if (v < LEFT_DECEL_THRESH) {
t = uptime_irq();
break;
}
#if 0
if (v > LEFT_REVERSE_THRESH)
state = LEFT_ACCEL;
break;
case LEFT_ACCEL:
if (v > LEFT_ACCEL_THRESH)
break;
#else
if (v < LEFT_REVERSE_THRESH)
break;
#endif
if (sweeping) { /* we're confused */
state = IDLE;
break;
}
state = FWD_START_SWEEP;
/* t = t1-(t1+t0)/2 = (t1-t0)/2 */
t = (uptime_irq()-t) >> 1;
// sweep.wait_ticks = kkkkkk
break;
case FWD_START_SWEEP:
break;
case FWD_SWEEP:
if (v > RIGHT_DECEL_THRESH)
break;
state = IDLE;
break;
}
}
static const struct handler *protos[] = {
&image_handler,
&reset_handler,
&sample_handler,
NULL
};
int main(void)
{
uint8_t buf[PAYLOAD+5]; /* 3 bytes header, 2 bytes CRC */
uint8_t got;
/*
* The boot loader has already initialized PORTx, DDRx, and MCUCR.PUD.
* It has also brought up RF and the underlying SPI.
*/
sweep_init();
sample = sync_sweep;
accel_start();
sei();
while (1) {
got = rf_recv(buf, sizeof(buf));
if (got > 2)
dispatch(buf, got-2, protos);
#if 1
if (state == FWD_START_SWEEP && !sweeping) {
state = FWD_SWEEP;
sweep_image(&sweep);
}
#endif
}
}