main.c File Reference

[M]ouse main file. More...

#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <stdlib.h>
#include "usrat.h"
#include "ioconfig.h"
#include "ps2.h"
#include "mouse.h"
#include "c1351.h"
#include "tdelay.h"

Include dependency graph for main.c:


Defines

#define VTPAINT
 Compile VT-toy.

Functions

void vtpaint ()
 VT-Paint test app for VT220 doodling.
int main ()
 Program main.

Variables

MouseMovt movt_packet
 Fresh movement packet, raw.
DecodedMovt movt
 Decoded movement packet.

Detailed Description

[M]ouse main file.

Author:
Viacheslav Slavinsky
This is the main source file. The main loop inits usart, then ps2 functions, then c1351. It then calls mouse_boot() which never exits until mouse is succesfully reset and initialized in streaming mode. Initial button status is reported and according to buttons pressed at start, options are set. The default is to boot into C1351 proportional mode, normal speed (2 counts per mm).

Right mouse button boots mouse in C1350 (Joystick) mode.

Left mouse button boots mouse in fast movement mode.

Middle mouse button boots mouse in slow mode.

A triple button chord at start enables VT-Paint doodle app that works in a VT220 terminal attached to USART, if any, but probably affects performance of the C1351 mouse. This is kept in for debugging and fun.

h/j/k/l/space keys in attached terminal can be used to simulate mouse movement.


Define Documentation

#define VTPAINT

Compile VT-toy.


Function Documentation

int main (  ) 

Program main.

00070            {
00071     uint8_t i;
00072     uint8_t byte;
00073     uint8_t vtpaint_on = 0;
00074     uint8_t joymode = 0;
00075     
00076     const uint16_t zero = 320;
00077     
00078     usart_init(F_CPU/16/19200-1);
00079     
00080     printf_P(PSTR("\033[2J\033[H[M]AUS B%d (C)SVO 2009\n"), BUILDNUM);
00081 
00082     io_init();
00083 
00084     ps2_init();
00085 
00086     potmouse_init();
00087     potmouse_zero(zero);
00088 
00089     // enable interruptski
00090     sei();
00091 
00092     byte = mouse_boot();
00093     
00094     joymode = POTMOUSE_C1351;
00095     
00096     switch (byte & 7) {
00097         case 001: // [__@]
00098             // right mouse button pressed, joystick mode
00099             printf_P(PSTR("Joystick mode\n"));
00100             joymode = POTMOUSE_JOYSTICK;
00101             break;
00102         case 007: // [@@@]
00103             printf_P(PSTR("VT-Paint enabled\n"));
00104             vtpaint_on = 1;
00105             break;
00106         case 004: // [@__]
00107             printf_P(PSTR("1351 Fast\n"));
00108             mouse_setres(2);
00109             break;
00110         case 002: // [_@_]
00111             printf_P(PSTR("1351 Slow\n"));
00112             mouse_setres(0);
00113             break;
00114         case 000: // [___]
00115         default:
00116             printf_P(PSTR("1351 Normal\n"));
00117             // normal boot
00118             break;
00119     }
00120     
00121     potmouse_start(joymode);    
00122     potmouse_movt(0,0,0); 
00123         
00124     printf_P(PSTR("hjkl to move, space = leftclick\n"));
00125     
00126     for(i = 0;;) {
00127         if (ps2_avail()) {
00128             byte = ps2_getbyte();
00129             movt_packet.byte[i] = byte;
00130             
00131             i = (i + 1) % 3;
00132         
00133             // parse full packet
00134             if (i == 0) {
00135                 movt.dx = ((movt_packet.fields.bits & _BV(XSIGN)) ? 0xff00 : 0) | movt_packet.fields.dx;
00136                 movt.dy = ((movt_packet.fields.bits & _BV(YSIGN)) ? 0xff00 : 0) | movt_packet.fields.dy;
00137                                 
00138                 movt.buttons = movt_packet.fields.bits & 7;
00139                 
00140                 // tell c1351 emulator that movement happened
00141                 potmouse_movt(movt.dx, movt.dy, movt.buttons);
00142 
00143                 // doodle on vt terminal
00144                 if (vtpaint_on) vtpaint();                
00145             }
00146         } 
00147         
00148         // handle keyboard commands
00149         if (uart_available()) {
00150             uart_putchar(byte = uart_getchar());
00151             switch (byte) {                    
00152                 case 'h':   potmouse_movt(-1, 0, 0);
00153                             break;
00154                 case 'l':   potmouse_movt(1, 0, 0);
00155                             break;
00156                 case 'j':   potmouse_movt(0, -1, 0);
00157                             break;
00158                 case 'k':   potmouse_movt(0, 1, 0);
00159                             break;
00160                 case ' ':   potmouse_movt(0, 0, 1);
00161                             break;
00162             }
00163         }
00164     }
00165 }

Here is the call graph for this function:

void vtpaint (  ) 

VT-Paint test app for VT220 doodling.

00167                {                    
00168 #ifdef VTPAINT
00169     static int16_t absoluteX = 0, absoluteY = 0;
00170     static int16_t termX, termY;
00171     static uint8_t last_buttons = 0;
00172 
00173     uint8_t moved = 0;
00174 
00175     ps2_enable_recv(0);
00176     absoluteX += movt.dx;
00177     absoluteY += movt.dy;
00178 
00179     moved = termX != absoluteX/33 || termY != absoluteY/66 || last_buttons != movt.buttons;
00180 
00181     if (moved) {
00182         printf_P(PSTR("\033[%d;%dH%c"), 12-termY, 40+termX, movt.buttons ? '#':' ');
00183 
00184         last_buttons = movt.buttons;
00185         termX = absoluteX/33;
00186         termY = absoluteY/66;
00187 
00188         printf_P(PSTR("\033[%d;%dH%c"), 12-termY, 40+termX, movt.buttons + '0');
00189     }
00190 
00191     printf_P(PSTR("\033[HX=%+6d Y=%+6d [%c %c %c]\r"), 
00192                 absoluteX, absoluteY,
00193                 (movt.buttons & _BV(BUTTON1)) ? '@':' ',
00194                 (movt.buttons & _BV(BUTTON3)) ? '@':' ',
00195                 (movt.buttons & _BV(BUTTON2)) ? '@':' ');
00196     
00197     ps2_enable_recv(1);
00198 #endif
00199 }

Here is the call graph for this function:


Variable Documentation

Decoded movement packet.

Fresh movement packet, raw.


Generated on Fri Nov 13 04:21:22 2009 for [M]ouse by  doxygen 1.5.9