bool LIS3LV02::getRaw( int16_t iaccel[3] ) { uint8_t *p = (uint8_t *)iaccel; for (int i=0; i < 3*2; i++) *(p++) = aread8( OUTX_L + i ); return true; /* areadX( OUTZ_L, (uint8_t*)iaccel, sizeof(iaccel) ); return true;*/ }
int main(int argc,char **argv) { char pfile[MAXLN],afile[MAXLN],wfile[MAXLN],shfile[MAXLN]; int err,useOutlets=0,usew=0,contcheck=1,i; if(argc < 2) { printf("Error: To run this program, use either the Simple Usage option or\n"); printf("the Usage with Specific file names option\n"); goto errexit; } if(argc > 2) { i = 1; // printf("You are running %s with the Specific File Names Usage option.\n", argv[0]); } else { i = 2; // printf("You are running %s with the Simple Usage option.\n", argv[0]); } while(argc > i) { if(strcmp(argv[i],"-p")==0) { i++; if(argc > i) { strcpy(pfile,argv[i]); i++; } else goto errexit; } else if(strcmp(argv[i],"-ad8")==0) { i++; if(argc > i) { strcpy(afile,argv[i]); i++; } else goto errexit; } else if(strcmp(argv[i],"-o")==0) { i++; if(argc > i) { strcpy(shfile,argv[i]); useOutlets = 1; i++; } else goto errexit; } else if(strcmp(argv[i],"-wg")==0) { i++; if(argc > i) { strcpy(wfile,argv[i]); usew=1; i++; } else goto errexit; } else if(strcmp(argv[i],"-nc")==0) { i++; contcheck=0; } else { goto errexit; } } if( argc == 2) { nameadd(afile,argv[1],"ad8"); nameadd(pfile,argv[1],"p"); } if( (err=aread8(pfile,afile,shfile,wfile,useOutlets,usew,contcheck)) != 0) printf("area error %d\n",err); return 0; errexit: printf("Simple Usage:\n %s <basefilename>\n",argv[0]); printf("Usage with specific file names:\n %s -p <pfile>\n",argv[0]); printf("-ad8 <afile> [-o <shfile>] [-wg <wfile>]\n"); printf("<basefilename> is the name of the raw digital elevation model\n"); printf("<pfile> is the D8 flow direction input file.\n"); printf("<afile> is the D8 area output file.\n"); printf("[-o <shfile>] is the optional outlet shape input file.\n"); printf("[-wg <wfile>] is the optional weight grid input file.\n"); printf("The flag -nc overrides edge contamination checking\n"); printf("The following are appended to the file names\n"); printf("before the files are opened:\n"); printf("ad8 D8 contributing area file (output)\n"); printf("p D8 flow direction output file\n"); exit(0); }
void main(int argc,char **argv) { char pfile[MAXLN],afile[MAXLN],wfile[MAXLN]; int err,nmain, doall=1,usew=0,contcheck=1,i; long x=0, y=0; if(argc < 2) { printf("Usage:\n %s <filename_prefix> [-xy outlet_x outlet_y] [-wg <weightfile>] [-nc]\n",argv[0]); printf("(The optional outlet_x and outlet_y are outlet coordinates\n"); printf("for the area to be computed. If they are not given \n"); printf("the whole file is computed.\n"); printf("The optional <weightfile> is the file name for a grid of weights for\n"); printf("weighted contributing area evaluation\n"); printf("The flag -nc overrides edge contamination checking\n"); printf("The following are appended to the file names\n"); printf("before the files are opened:\n"); printf("p D8 flow directions(Input)\n"); printf("ad8 D8 area's in pixels\n"); printf("wad8 Weighted D8 areas\n"); exit(0); } i=2; while(argc > i) { if(strcmp(argv[i],"-wg")==0) { i++; if(argc > i) { sscanf(argv[i],"%s",wfile); usew=1; i=i+1; } } else if(strcmp(argv[i],"-xy")==0) { i++; if(argc > i+1) { sscanf(argv[i],"%ld",&x); sscanf(argv[i+1],"%ld",&y); doall = 0; i=i+2; } } else if(strcmp(argv[i],"-nc")==0) { i++; contcheck=0; } else i++; } nmain=nameadd(pfile,argv[1],"p"); if(usew == 1) { nmain=nameadd(afile,argv[1],"wad8"); } else { nmain=nameadd(afile,argv[1],"ad8"); } if(err=aread8(pfile,afile,x,y,doall,wfile,usew,contcheck) != 0) printf("area error %d\n",err); }
bool LIS3LV02::init(unsigned int spiclk) { int ret; uint8_t mode = 0; uint8_t bits = 8; uint32_t speed = spiclk; //uint16_t delay = 0; fd = open(spidevname, O_RDWR); if (fd < 0) { cout << "can't open device" << endl; return false; } /* * spi mode */ ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); if (ret == -1) { cout << "can't set spi mode" << endl; return false; } ret = ioctl(fd, SPI_IOC_RD_MODE, &mode); if (ret == -1) { cout << "can't get spi mode" << endl; return false; } /* * bits per word */ ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); if (ret == -1) { cout << "can't set bits per word" << endl; return false; } ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits); if (ret == -1) { cout << "can't get bits per word"; return false; } /* * max speed hz */ ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); if (ret == -1) { cout << "can't set max speed hz" << endl; return false; } ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed); if (ret == -1) { cout << "can't get max speed hz" << endl; } /*** * Now try to find the device */ unsigned char sig = aread8(0x0F); if ( sig != 0x3A ) { cout << "Couldn't find LIS3LV02! " << (int)sig << endl; return false; } //start awrite8( CTRL_REG1, (1<<7) | (0<<3) | (1<<1) | (1<<2) | (1<<0) ); //all axes on //16 bit mode awrite8( CTRL_REG2, 1 //16 bit mode | (1<<5) //big endian | (1<<6) //block update on | (0<<7) //2g scale | (0<<4) //boot ); awrite8( CTRL_REG3, 0 ); return true; //ok! }