123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- let device = require('./device');
- let blessed = require('blessed');
- let screen = blessed.screen({
- smartCSR: true
- });
- screen.title = 'OpenPrepPad';
- let container = blessed.box({
- top: 'center',
- left: 'center',
- width: 50,
- height: 17,
- border: {
- type: 'line'
- },
- style: {
- bg: 'cyan-bg'
- }
- })
- let box = blessed.BigText({
- top: 0,
- right: 0,
- width: 'shrink',
- height: 'shrink',
- tags: true,
- style: {
- fg: 'white'
- }
- });
- container.append(box);
- screen.append(container);
- let statusLine = blessed.Text({
- bottom: 0,
- width: '100%',
- height: 'shrink',
- content: 'Connecting...',
- style: {
- fg: 'white',
- bg: 'blue'
- }
- });
- screen.append(statusLine);
- let helpBox = blessed.box({
- top: 0,
- left: 0,
- width: 'shrink',
- height: 'shrink',
- content: 'q - Quit\nz - Zero/Tare'
- });
- screen.append(helpBox);
- let dataTable = blessed.Table({
- bottom: 1,
- right: 0,
- width: 19,
- height: 'shrink',
- border: {
- type: 'line'
- },
- data: [
- [ 'Accel', 'Value' ],
- [ 'X', '-1' ],
- [ 'Y', '-1' ],
- [ 'Z', '-1' ]
- ]
- });
- screen.append(dataTable);
- screen.key(['escape', 'q', 'C-c'], function(ch, key) {
- process.exit(0);
- });
- screen.key(['z'], function(ch, key) {
- device.button$.onNext('');
- });
- // Focus our element.
- box.focus();
- // Render the screen.
- screen.render();
- device.weight$.subscribe(w => {
- box.setContent(w+'g');
- screen.render();
- })
- device.connStatus$.subscribe(s => {
- if(s.state == 'connected') {
- statusLine.setContent('Connected to Prep Pad '+s.serial);
- }
- else {
- statusLine.setContent('Connecting...');
- }
- screen.render();
- })
- device.accel$.subscribe(s => {
- let data = [
- [ 'Accel', 'Value' ],
- [ 'X', ''+s[0] ],
- [ 'Y', ''+s[1] ],
- [ 'Z', ''+s[2] ]
- ]
- dataTable.setData(data);
- screen.render();
- })
|