[qwaq] Implement device management for input-app

Currently shows only the axes (along with dev "path" and name), but it
has done a good job of pushing dev of other bits of code :)
This commit is contained in:
Bill Currie 2021-09-25 14:22:19 +09:00
parent 1a5cce4374
commit 4057500acc
12 changed files with 288 additions and 24 deletions

View file

@ -57,6 +57,10 @@ qwaq_app_dat_src= \
ruamoko/qwaq/editor/status.r ruamoko/qwaq/editor/status.r
qwaq_input_app_dat_src= \ qwaq_input_app_dat_src= \
ruamoko/qwaq/device/axisdata.r \
ruamoko/qwaq/device/axisview.r \
ruamoko/qwaq/device/nameview.r \
ruamoko/qwaq/device/device.r \
ruamoko/qwaq/qwaq-input.r \ ruamoko/qwaq/qwaq-input.r \
ruamoko/qwaq/input-app.r ruamoko/qwaq/input-app.r

View file

@ -625,7 +625,6 @@ bi_get_device_info (progs_t *pr)
qwaq_input_resources_t *res = PR_Resources_Find (pr, "input"); qwaq_input_resources_t *res = PR_Resources_Find (pr, "input");
int devid = P_INT (pr, 0); int devid = P_INT (pr, 0);
Sys_Printf ("qwaq_get_device_info: %d\n", devid);
int command[] = { int command[] = {
qwaq_cmd_get_device_info, 0, qwaq_cmd_get_device_info, 0,
devid, devid,

View file

@ -0,0 +1,19 @@
#ifndef __qwaq_device_axisdata_h
#define __qwaq_device_axisdata_h
#include "ruamoko/qwaq/qwaq-input.h"
#include "ruamoko/qwaq/ui/tableview.h"
@class AxisView;
@interface AxisData : Object <TableViewDataSource>
{
int numaxes;
in_axisinfo_t *axes;
AxisView **axis_views;
}
+withDevice:(qwaq_devinfo_t *)device;
-updateAxis:(int)axis value:(int)value;
@end
#endif//__qwaq_device_axisdata_h

View file

@ -0,0 +1,58 @@
#include "ruamoko/qwaq/device/axisdata.h"
#include "ruamoko/qwaq/device/axisview.h"
@implementation AxisData
-initWithDevice:(qwaq_devinfo_t *)device
{
if (!(self = [super init])) {
return nil;
}
numaxes = device.numaxes;
axes = device.axes;
axis_views = obj_malloc (numaxes);
for (int i = 0; i < numaxes; i++) {
axis_views[i] = [[AxisView withAxis:&axes[i]] retain];
}
return self;
}
+withDevice:(qwaq_devinfo_t *)device
{
return [[[self alloc] initWithDevice:device] autorelease];
}
-(void)dalloc
{
}
-updateAxis:(int)axis value:(int)value
{
axes[axis].value = value;
return self;
}
-(ListenerGroup *)onRowCountChanged
{
return nil;
}
-(int)numberOfRows:(TableView *)tableview
{
return numaxes;
}
-(View *)tableView:(TableView *)tableview
forColumn:(TableViewColumn *)column
row:(int)row
{
View *view = nil;
if (row >= 0 && row < numaxes) {
AxisView *av = axis_views[row];
view = [av viewAtRow:0 forColumn:column];
}
return view;
}
@end

View file

@ -0,0 +1,18 @@
#ifndef __qwaq_device_axisview_h
#define __qwaq_device_axisview_h
#include "ruamoko/qwaq/qwaq-input.h"
#include "ruamoko/qwaq/ui/view.h"
@class TableViewColumn;
@interface AxisView : View
{
in_axisinfo_t *axis;
}
+withAxis:(in_axisinfo_t *)axis;
-(int)rows;
-(View *)viewAtRow:(int)row forColumn:(TableViewColumn *)column;
@end
#endif//__qwaq_device_axisview_h

View file

@ -0,0 +1,42 @@
#include <string.h>
#include "ruamoko/qwaq/ui/tableview.h"
#include "ruamoko/qwaq/device/axisview.h"
#include "ruamoko/qwaq/device/nameview.h"
@implementation AxisView
-initWithAxis:(in_axisinfo_t *)axis
{
if (!(self = [super init])) {
return nil;
}
self.axis = axis;
return self;
}
+withAxis:(in_axisinfo_t *)axis
{
return [[[self alloc] initWithAxis:axis] retain];
}
-draw
{
[super draw];
[self mvprintf:{0, 0}, "%*.*d", xlen, xlen, axis.value];
return self;
}
-(int)rows
{
return 1;
}
-(View *)viewAtRow:(int)row forColumn:(TableViewColumn *)column
{
if ([column name] == "axis") {
return [NameView withName:sprintf("%d", axis.axis)];
}
return self;
}
@end

View file

@ -0,0 +1,26 @@
#ifndef __qwaq_device_device_h
#define __qwaq_device_device_h
#include "ruamoko/qwaq/qwaq-input.h"
@class Window;
@class TableView;
@class AxisData;
@interface Device : Object
{
int devid;
qwaq_devinfo_t *device;
Window *window;
TableView *axis_view;
AxisData *axis_data;
}
+withDevice:(qwaq_devinfo_t *)device id:(int)devid;
-updateAxis:(int)axis value:(int)value;
-updateButton:(int)button state:(int)state;
-(int)devid;
-redraw;
@end
#endif//__qwaq_device_device_h

View file

@ -0,0 +1,77 @@
#include <string.h>
#include "ruamoko/qwaq/input-app.h"
#include "ruamoko/qwaq/ui/scrollbar.h"
#include "ruamoko/qwaq/ui/stringview.h"
#include "ruamoko/qwaq/ui/tableview.h"
#include "ruamoko/qwaq/ui/window.h"
#include "ruamoko/qwaq/device/axisdata.h"
#include "ruamoko/qwaq/device/device.h"
@implementation Device
-initWithDevice:(qwaq_devinfo_t *)device id:(int)devid
{
if (!(self = [super init])) {
return nil;
}
self.device = device;
self.devid = devid;
window = [Window withRect:{{0, 0}, {40, 10}}];
[window setBackground: color_palette[064]];
[window setTitle: device.id];
[window insert:[StringView withRect:{{1, 1}, {38, 1}} string:device.name]];
axis_data = [[AxisData withDevice:device] retain];
axis_view = [TableView withRect:{{1, 2}, {38, 7}}];
[axis_view addColumn:[TableViewColumn named:"axis" width:3]];
[axis_view addColumn:[TableViewColumn named:"value" width:6]];
ScrollBar *sb = [ScrollBar vertical:7 at:{39, 2}];
[axis_view setVerticalScrollBar:sb];
[axis_view setDataSource:axis_data];
[window insertSelected: axis_view];
[window insert: sb];
[application addView: window];
return self;
}
+withDevice:(qwaq_devinfo_t *)device id:(int)devid
{
return [[[self alloc] initWithDevice:device id:devid] autorelease];
}
-(void)dealloc
{
obj_free (device.axes);
obj_free (device.buttons);
str_free (device.name);
str_free (device.id);
obj_free (device);
[application removeView:window];
}
-updateAxis:(int)axis value:(int)value
{
[axis_data updateAxis:axis value:value];
return self;
}
-updateButton:(int)button state:(int)state
{
return self;
}
-(int)devid
{
return devid;
}
-redraw
{
[axis_view redraw];
return self;
}
@end

View file

@ -3,7 +3,7 @@
#include "ruamoko/qwaq/debugger/views/defview.h" #include "ruamoko/qwaq/debugger/views/defview.h"
@interface NameView : DefView @interface NameView : View
{ {
string name; string name;
} }

View file

@ -1,11 +1,11 @@
#include <string.h> #include <string.h>
#include "ruamoko/qwaq/debugger/views/nameview.h" #include "ruamoko/qwaq/device/nameview.h"
@implementation NameView @implementation NameView
-initWithName:(string)name -initWithName:(string)name
{ {
if (!(self = [super initWithDef:def type:nil])) { if (!(self = [super init])) {
return nil; return nil;
} }
self.name = name; self.name = name;

View file

@ -23,10 +23,13 @@ extern int color_palette[64];
TextContext *screen; TextContext *screen;
Extent screenSize; Extent screenSize;
int autocount; int autocount;
Array *devices;
} }
-(Extent)size; -(Extent)size;
-(TextContext *)screen; -(TextContext *)screen;
-addView:(View *)view; -addView:(View *)view;
-removeView:(View *)view;
-run; -run;
@end @end

View file

@ -8,6 +8,7 @@ int fence;
#include "ruamoko/qwaq/ui/curses.h" #include "ruamoko/qwaq/ui/curses.h"
#include "ruamoko/qwaq/ui/group.h" #include "ruamoko/qwaq/ui/group.h"
#include "ruamoko/qwaq/ui/view.h" #include "ruamoko/qwaq/ui/view.h"
#include "ruamoko/qwaq/device/device.h"
#include "ruamoko/qwaq/qwaq-input.h" #include "ruamoko/qwaq/qwaq-input.h"
#include "ruamoko/qwaq/input-app.h" #include "ruamoko/qwaq/input-app.h"
@ -58,6 +59,8 @@ arp_end (void)
[screen clear]; [screen clear];
wrefresh (stdscr);//FIXME wrefresh (stdscr);//FIXME
devices = [[Array array] retain];
send_connected_devices (); send_connected_devices ();
return self; return self;
@ -105,33 +108,41 @@ arp_end (void)
{ {
int devid = event.message.int_val; int devid = event.message.int_val;
qwaq_devinfo_t *dev = get_device_info (devid); qwaq_devinfo_t *dev = get_device_info (devid);
[screen printf:"dev add: %d %s %s\n", devid, dev.id, dev.name]; Device *device = [Device withDevice:dev id:devid];
[screen printf:" : %d %d\n", dev.numaxes, dev.numbuttons]; [devices addObject:device];
for (int i = 0; i < dev.numaxes; i++) {
[screen printf:" : %d %d %d\n", dev.axes[i].value,
dev.axes[i].min, dev.axes[i].max];
}
[screen refresh];
obj_free (dev.axes);
obj_free (dev.buttons);
str_free (dev.name);
str_free (dev.id);
obj_free (dev);
} }
break; break;
case qe_dev_rem: case qe_dev_rem:
[screen printf:"dev rem: %d\n", event.message.int_val]; for (int i = [devices count]; i-- > 0; ) {
[screen refresh]; Device *device = [devices objectAtIndex:i];
if ([device devid] == event.message.ivector_val[0]) {
[devices removeObjectAtIndex:i];
break;
}
}
break; break;
case qe_axis: case qe_axis:
[screen printf:"axis: %d %d %d\n", event.message.ivector_val[0], for (int i = [devices count]; i-- > 0; ) {
event.message.ivector_val[1], event.message.ivector_val[2]]; Device *device = [devices objectAtIndex:i];
[screen refresh]; if ([device devid] == event.message.ivector_val[0]) {
[device updateAxis:event.message.ivector_val[1]
value:event.message.ivector_val[2]];
[device redraw];
break;
}
}
break; break;
case qe_button: case qe_button:
[screen printf:"button: %d %d %d\n", event.message.ivector_val[0], for (int i = [devices count]; i-- > 0; ) {
event.message.ivector_val[1], event.message.ivector_val[2]]; Device *device = [devices objectAtIndex:i];
[screen refresh]; if ([device devid] == event.message.ivector_val[0]) {
[device updateButton:event.message.ivector_val[1]
state:event.message.ivector_val[2]];
[device redraw];
break;
}
}
break;
} }
if (event.what != qe_none) { if (event.what != qe_none) {
[objects handleEvent: event]; [objects handleEvent: event];
@ -162,6 +173,13 @@ arp_end (void)
[screen refresh]; [screen refresh];
return self; return self;
} }
-removeView:(View *)view
{
[objects remove: view];
[screen refresh];
return self;
}
@end @end
InputApplication *application; InputApplication *application;