urbit/v/batz.c

92 lines
1.5 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* v/batz.c
**
** This file is in the public domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <setjmp.h>
#include <gmp.h>
#include <dirent.h>
#include <stdint.h>
#include <uv.h>
#include <curses.h>
#include <termios.h>
#include <term.h>
#include <errno.h>
#include "all.h"
#include "v/vere.h"
2014-09-11 04:01:32 +04:00
/* u3_batz_io_init(): initialize batz timer.
2013-09-29 00:21:18 +04:00
*/
void
2014-09-11 04:01:32 +04:00
u3_batz_io_init(void)
2013-09-29 00:21:18 +04:00
{
2014-09-11 04:01:32 +04:00
u3_batz* beh_u = &u3_Host.beh_u;
2013-09-29 00:21:18 +04:00
2014-09-11 04:01:32 +04:00
uv_timer_init(u3L, &beh_u->tim_u);
2014-11-05 04:18:47 +03:00
beh_u->alm = c3n;
2013-09-29 00:21:18 +04:00
}
2014-09-11 04:01:32 +04:00
/* u3_batz_io_exit(): terminate timer.
2013-09-29 00:21:18 +04:00
*/
void
2014-09-11 04:01:32 +04:00
u3_batz_io_exit(void)
2013-09-29 00:21:18 +04:00
{
}
/* _batz_time_cb(): timer callback.
*/
static void
2014-08-21 02:09:51 +04:00
_batz_time_cb(uv_timer_t* tim_u)
2013-09-29 00:21:18 +04:00
{
2014-09-11 04:01:32 +04:00
u3_batz* beh_u = &u3_Host.beh_u;
2014-08-01 18:54:31 +04:00
if(beh_u->run_w < 1024) {
beh_u->run_w++;
}
2014-09-11 04:01:32 +04:00
u3_lo_open();
2013-09-29 00:21:18 +04:00
{
2014-11-06 03:20:01 +03:00
u3v_plan
2014-09-11 04:01:32 +04:00
(u3nt(u3_blip, c3__batz, u3_nul),
u3nc(c3__wake, u3_nul));
2013-09-29 00:21:18 +04:00
}
2014-11-05 04:18:47 +03:00
u3_lo_shut(c3n);
2013-09-29 00:21:18 +04:00
}
2014-09-11 04:01:32 +04:00
/* u3_batz_io_poll(): update batz IO state.
2013-09-29 00:21:18 +04:00
*/
void
2014-09-11 04:01:32 +04:00
u3_batz_io_poll(void)
2013-09-29 00:21:18 +04:00
{
2014-09-11 04:01:32 +04:00
u3_batz* beh_u = &u3_Host.beh_u;
2014-11-06 03:20:01 +03:00
u3_noun wen = u3v_keep(u3nt(u3_blip, c3__batz, u3_nul));
2014-09-11 04:01:32 +04:00
if ( (u3_nul != wen) &&
2014-11-05 04:18:47 +03:00
(c3y == u3du(wen)) &&
(c3y == u3ud(u3t(wen))) )
2013-09-29 00:21:18 +04:00
{
2014-09-11 04:01:32 +04:00
c3_d gap_d = u3_time_gap_ms(u3k(u3A->now), u3k(u3t(wen)));
2013-09-29 00:21:18 +04:00
2013-11-21 10:43:12 +04:00
gap_d += beh_u->run_w;
2014-11-05 04:18:47 +03:00
if ( c3y == beh_u->alm ) {
2013-09-29 00:21:18 +04:00
uv_timer_stop(&beh_u->tim_u);
}
2014-11-05 04:18:47 +03:00
else beh_u->alm = c3y;
2013-09-29 00:21:18 +04:00
uv_timer_start(&beh_u->tim_u, _batz_time_cb, gap_d, 0);
}
else {
2014-11-05 04:18:47 +03:00
if ( c3y == beh_u->alm ) {
2013-09-29 00:21:18 +04:00
uv_timer_stop(&beh_u->tim_u);
}
2014-11-05 04:18:47 +03:00
beh_u->alm = c3n;
2013-09-29 00:21:18 +04:00
}
2014-09-11 04:01:32 +04:00
u3z(wen);
2013-09-29 00:21:18 +04:00
}