summaryrefslogtreecommitdiff
path: root/c/menu/digilines.c
blob: 620d61fba83d89cb3d60e3ae14569b687a9d24ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* Menu Thing for RVController - Digilines
 * A product of Advanced Mesecons Devices, a Cheapie Systems company
 * This is free and unencumbered software released into the public domain.
 * See http://unlicense.org/ for more information */

#include <stdint.h>
#include <stdbool.h>
#include "rvcontroller-ecalls.h"

char dispbuf[] = "\nLast channel:\n(none)              \nLast message:\n(none)              \ns: Send\nq: Quit";

void dispWrite(char *text,int pos) {
	int outpos;
	for (int i=0;;i++) {
		if (text[i] == 0) { break; }
		outpos = pos + i;
		dispbuf[outpos] = text[i];
	}
}

void sendUI(void) {
	char channeloutbuf[19];
	char msgoutbuf[19];
	printstr("\n\n\n\n\nEnter channel:\n> ");
	readstr(channeloutbuf,19);
	printstr(channeloutbuf);
	printstr("\nEnter message:\n> ");
	readstr(msgoutbuf,19);
	printstr(msgoutbuf);
	digiline_send(channeloutbuf,msgoutbuf);
	printstr("\nSent!\nPress any key");
	readstr(channeloutbuf,1);
}

void runDigilines(void) {
	char channelinbuf[21];
	char msginbuf[21];
	char kbinput;
	bool quit = false;

	console_clearbuffer();
	digiline_clearbuffer();
	dispWrite("(none)              ",15);
	dispWrite("(none)              ",50);

	while (!quit) {
		if (digiline_bufferlevel() > 0) {
			digiline_receive(channelinbuf,21,msginbuf,21);
			dispWrite("                    ",15);
			dispWrite("                    ",50);
			dispWrite(channelinbuf,15);
			dispWrite(msginbuf,50);
		}
		printstr(dispbuf);

		kbinput = console_readchar();
		switch (kbinput) {
			case 's':
				sendUI();
				break;
			case 'q':
				quit = true;
				break;
		}
	}
}