Пример #1
0
void *I2CADCLoop(void *some_void_ptr)
{
	struct TGPS *GPS;
	int fd;

	GPS = (struct TGPS *)some_void_ptr;

	// Initialise MCP3426
	
	while (1)
	{
		if (fd = open_i2c(MCP3426_ADDRESS))
		{
			double BatteryVoltage, BoardCurrent;
			
			BatteryVoltage = ReadI2CADC(fd, 0, 33.024);
			GPS->BatteryVoltage = BatteryVoltage;
			// printf("Battery Voltage = %lf\n", BatteryVoltage);
			
			BoardCurrent = ReadI2CADC(fd, 1, 1.4);
			GPS->BoardCurrent = BoardCurrent;
			// printf("Board Current = %lf\n", BoardCurrent);

			close(fd);
		}

		sleep(10);
	}

    return 0;
}
Пример #2
0
// start i2c communication -- call this in main to start  
int motordriver::begin(void) {
  open_i2c(); // open device 
  ioctl(_i2cHandle, I2C_SLAVE,_i2cAddr); // set slave address
  reset();
  return 0;

}
Пример #3
0
Файл: bme280.c Проект: phl0/pits
void *BME280Loop(void *some_void_ptr)
{
	struct TBME bme;
	struct TGPS *GPS;

	GPS = (struct TGPS *)some_void_ptr;

	if (BMEPresent(&bme, BME280_ADDRESS))
	{
		BMEAddress = BME280_ADDRESS;
	}
	else if (BMEPresent(&bme, BME280_ADDRESS+1))
	{
		BMEAddress = BME280_ADDRESS+1;
	}
	else
	{
		BMEAddress = 0;
	}

	if (BMEAddress)
	{
		printf("BME280 Found At Address %02xh\n", BMEAddress);
	}
	else
	{
		printf("BME280 Not Found (nothing at addresses 76/77h)\n");
	}
	
	while (BMEAddress)
	{
		if ((bme.fd = open_i2c(BMEAddress)) >= 0)
		{
			bme280StartMeasurement(&bme);
		
			sleep(1);		// Wait (ample time) for measurement
		
			bme280ReadDataRegisters(&bme);
			
			bme280GetRawValues(&bme);
			
			GPS->BMP180Temperature = bme280Temperature(&bme);
			GPS->Pressure = bme280Pressure(&bme);
			GPS->Humidity = bme280Humidity(&bme);

			// printf("Temperature is %5.2lf\n", GPS->BMP180Temperature);
			// printf("Pressure is %5.2lf\n", GPS->Pressure);
			// printf("Humidity is %5.2lf\n", GPS->Humidity);

			close(bme.fd);
		}

		sleep(10);
	}
	
	return NULL;
}
Пример #4
0
void process_command_connections(int port, int bus, bool verbose)
{
	int i2c_handle, sock, result, con;
	socklen_t client_address_size;
	struct sockaddr_storage client_address;
	char client_ip[INET6_ADDRSTRLEN];

	if (verbose) printf("Opening command I2C handle\n");
	i2c_handle = open_i2c(bus, 1); 
	if (i2c_handle == -1) {
		perror("ERROR => Couldn't open i2c bus. The error was:");
		exit(1);
	}

	sock = create_and_bind_tcp_socket(port);
	if (sock == -1) {
		exit(1);
	}

	while (1) {
		
		if (verbose) printf("Listening for incoming command connections\n");

		result = listen(sock, 20);
		if (result != 0) {
			fprintf(stderr, "ERROR: Error attempting to listen on socket");
			continue;
		}

		client_address_size = sizeof(client_address);
		con = accept(sock, (struct sockaddr *) &client_address, &client_address_size);
		if (con < 0) {
			fprintf(stderr, "ERROR: Error attempting to accept connection");
			continue;
		}

		get_address_ip((struct sockaddr*)&client_address, client_ip, sizeof(client_ip));
		printf("Command connection accepted from %s\n", client_ip);

		process_command_connection(con, i2c_handle, verbose);

		printf("Closing command connection\n");
		close(con);

		printf("Removing all poll records\n");
		pr_lock("pcc");
		pr_clear_and_free_all();
		pr_unlock();
	}

	printf("Closing command socket\n");
	close(sock);

	printf("Closing command I2C handle\n");
	close(i2c_handle);
}
Пример #5
0
void *BMP085Loop(void *some_void_ptr)
{
	struct TBMP bmp;
	struct TGPS *GPS;

	GPS = (struct TGPS *)some_void_ptr;

	// Initialise BMP085
	if (bmp.fd = open_i2c(BMP085_ADDRESS))
	{
		int NoBMP;
		
		NoBMP = bmp085Calibration(&bmp);
		close(bmp.fd);
		
		if (NoBMP)
		{
			return 0;
		}
	}
	else
	{
		return 0;
	}
	
	while (1)
	{
		if (bmp.fd = open_i2c(BMP085_ADDRESS))
		{
			GPS->BMP180Temperature = bmp085GetTemperature(&bmp);
			GPS->Pressure = bmp085GetPressure(&bmp, GPS->BMP180Temperature);

			// printf("Temperature is %5.2lf\n", GPS->BMP180Temperature);
			// printf("Pressure is %5.2lf\n", GPS->Pressure);

			close(bmp.fd);
		}

		sleep(10);
	}

    return 0;
}
Пример #6
0
Файл: bme280.c Проект: phl0/pits
int BMEPresent(struct TBME *bme, int Address)
{
	int IsPresent;
	
	IsPresent = 0;
	
	if ((bme->fd = open_i2c(Address)) >= 0)
	{
		IsPresent = bme280Calibration(bme);
		
		close(bme->fd);
	}
	
	return IsPresent;
}
Пример #7
0
int main(){
    int i2c_dev;
    lcd lcd0;
    // 0x27 is the address of the i2c device
    i2c_dev = open_i2c(I2C_FILE_NAME, 0x27);
    if(i2c_dev <0){
       printf("Errore: %d\n", i2c_dev);
       return 1;
    }
    lcd_init(&lcd0, i2c_dev);
    lcd_clear(&lcd0);
    lcd_print(&lcd0, txt[0], strlen(txt[0]), 0);
    lcd_print(&lcd0, txt[1], strlen(txt[1]), 1);
    close_i2c(i2c_dev);
    return 0;
}
Пример #8
0
int I2CADCExists(void)
{
	int fd, result;
	
	result = 0;
	
	if (fd = open_i2c(MCP3426_ADDRESS))
	{
		if (wiringPiI2CRead(fd) != -1)
		{
			result = 1;
		}
		close(fd);
	}
	
	return result;
}
Пример #9
0
int main(){
    int i2c_dev;
    unsigned int i, j, dir;
    lcd lcd0;
    // 0x27 is the address of the i2c device
    i2c_dev = open_i2c(I2C_FILE_NAME, 0x27);
    if(i2c_dev <0){
       printf("Errore: %d\n", i2c_dev);
       return 1;
    }
    char tmp[16];
    dir = 0;
    i=0;
    lcd_init(&lcd0, i2c_dev);
    while(i < 0xffffffff){
       j = i%13;
       memset(tmp, ' ', 16);
       if(j == 0) dir = !dir;
       if(dir){
           tmp[j]='^';
           tmp[j+1]='_';
           tmp[j+2]='^';
       }else{
           tmp[15-j]='^';
           tmp[14-j]='_';
           tmp[13-j]='^';
       }
       lcd_clear(&lcd0);
       lcd_print(&lcd0, txt, 8, 0);
       lcd_print(&lcd0, tmp, 16, 1);
       usleep(100000);
       ++i;
    }
    close_i2c(i2c_dev);
    return 0;
}
Пример #10
0
int main(int argc, char **argv)
{
	int ser;
	struct stm32_def *chip;
	int ret = 1;
	int flags;

	/* Parse command line options */
	flags = parse_parameters(argc, argv);

	if (i2c_adapter == INVALID_I2C_ADAPTER) {
		/* Open the serial port tty */
		ser = open_serial(serial_port);
	} else {
		ser = open_i2c(i2c_adapter);
	}
	if (ser < 0)
		return 1;
	/* Trigger embedded monitor detection */
	if (init_monitor(ser) < 0)
		goto terminate;

	chip = command_get_id(ser);
	if (!chip)
		goto terminate;

	command_get_commands(ser, chip);

	if (flags & FLAG_READ_UNPROTECT)
		command_read_unprotect(ser);
	if (flags & FLAG_UNPROTECT)
		command_write_unprotect(ser);

	if (flags & FLAG_ERASE || output_filename) {
		if (!strcmp("STM32L15", chip->name)) {
			/* Mass erase is not supported on STM32L15xx */
			/* command_ext_erase(ser, ERASE_ALL, 0); */
			int i, page_count = chip->flash_size / chip->page_size;
			for (i = 0; i < page_count; i += 128) {
				int count = MIN(128, page_count - i);
				ret = erase(ser, count, i);
				if (ret)
					goto terminate;
			}
		} else {
			ret = erase(ser, 0xFFFF, 0);
			if (ret)
				goto terminate;
		}
	}

	if (input_filename) {
		ret = read_flash(ser, chip, input_filename,
				 0, chip->flash_size);
		if (ret)
			goto terminate;
	}

	if (output_filename) {
		ret = write_flash(ser, chip, output_filename, 0);
		if (ret)
			goto terminate;
	}

	/* Run the program from flash */
	if (flags & FLAG_GO)
		command_go(ser, chip->flash_start);

	/* Normal exit */
	ret = 0;
terminate:
	/* Close serial port */
	close(ser);
	return ret;
}