int main() { MS5611 barometer; if (check_apm()) { return 1; } barometer.initialize(); while (true) { barometer.refreshPressure(); usleep(10000); // Waiting for pressure data ready barometer.readPressure(); barometer.refreshTemperature(); usleep(10000); // Waiting for temperature data ready barometer.readTemperature(); barometer.calculatePressureAndTemperature(); printf("Temperature(C): %f Pressure(millibar): %f\n", barometer.getTemperature(), barometer.getPressure()); sleep(1); } return 0; }
int main(int argc, char *argv[]) { int parameter; char *sensor_name; if (check_apm()) { return 1; } if (argc < 2) { printf("Enter parameter\n"); print_help(); return EXIT_FAILURE; } // prevent the error message opterr=0; while ((parameter = getopt(argc, argv, "i:h")) != -1) { switch (parameter) { case 'i': sensor_name = optarg; break; case 'h': print_help(); return EXIT_FAILURE; case '?': printf("Wrong parameter.\n"); print_help(); return EXIT_FAILURE; } } imu = create_inertial_sensor(sensor_name); if (!imu) { printf("Wrong sensor name. Select: mpu or lsm\n"); return EXIT_FAILURE; } if (!imu->probe()) { printf("Sensor not enable\n"); return EXIT_FAILURE; } //--------------------------- Network setup ------------------------------- sockfd = socket(AF_INET,SOCK_DGRAM,0); servaddr.sin_family = AF_INET; if (argc == 5) { servaddr.sin_addr.s_addr = inet_addr(argv[3]); servaddr.sin_port = htons(atoi(argv[4])); } else { servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); servaddr.sin_port = htons(7000); } //-------------------- IMU setup and main loop ---------------------------- imuSetup(); while(1) imuLoop(); }
int main() { uint8_t dev_address = 0b1010000; uint16_t reg_address = 0; uint8_t data = 0xCC; bool flag = true; if (check_apm()) { return 1; } printf("Fram memory Write/Read test!\nWe will write value 0xCC to the address 0 of fram memory, and then read it:\n"); MB85RC256 fram; printf("Writing data...\n"); fram.writeByte(reg_address, data); data = 0x00; printf("Reading data...\n"); fram.readByte(reg_address, &data); printf("Data, read from address 0 is %x\n", data); if (data != 0xCC) flag = false; // multiple write and read functionality test printf("Multiple read/write functionality test!\nWe will write values 0xAA, 0xBB, 0xCC to the addresses 0, 1, 2 of the fram memory \nand then read it:\n"); uint8_t a[3] = {0xAA, 0xBB, 0xCC}; printf("Writing data...\n"); fram.writeBytes(reg_address, 3, a); for (int i=0; i<3; i++) a[i] = 0; printf("Reading data...\n"); fram.readBytes(reg_address, 3, a); printf("Data, read from the addresses 0, 1, 2:\n%x %x %x\n", a[0], a[1], a[2]); if ((a[0] != 0xAA) || (a[1] != 0xBB) || (a[2] != 0xCC)) flag = false; if (flag == true) { printf("Memory test passed succesfully\n"); } else { printf("Memory test not passed\n"); } return 0; }
int main(int argc, char *argv[]) { ADC adc; adc.init(); float *results; results = (float *) malloc(sizeof(float) * adc.get_channel_count()); if (check_apm()) { return 1; } while (true) { for (int i = 0; i < ARRAY_SIZE(results); i++){ results[i] = adc.read(i); printf("A%d: %.4fV ", i, results[i] / 1000); } printf("\n"); usleep(500000); } return 0; }
// Handles a command issued by the user. void cl_handler(char* buffer, fs_node_t *fs_root) { if (strcmp(buffer,"beep") == 0) { beep(); } else if (strcmp(buffer,"clear") == 0) { monitor_clear(); } else if (strcmp(buffer,"contents") == 0) { file_disp(fs_root); } else if (strcmp(buffer,"cpu") == 0) { detect_cpu(); } else if (strcmp(buffer,"fork") == 0) { fork_disp(); } else if (strcmp(buffer,"furelise") == 0) { felise(); } else if (strcmp(buffer,"help") == 0) { help_disp(); } else if (strcmp(buffer,"hibernate") == 0) { // Define variables byte temp; // Disable interrupts cli(); // Clear all keyboard buffers (output and command buffers) do { // Empty user data temp = inb(0x64); // Empty keyboard data if (check_flag(temp, 0) != 0) { inb(0x60); } } while (check_flag(temp, 1) != 0); // Check for Advanced Power Management check_apm(); // Initialize Advanced Power Management init_apm(); // Send hibernation command suspend(); // Halt the cpu if failed halt(); } else if (strcmp(buffer,"logo") == 0) { logo_disp(); } else if (strcmp(buffer,"ls") == 0) { dir_disp(fs_root); } else if (strcmp(buffer,"mary") == 0) { mary(); } else if (strcmp(buffer,"mouse") == 0) { // Initialize the mouse init_mouse(); // output current coordinates //monitor_write_dec(getcoords()); } else if (strcmp(buffer,"nosound") == 0) { nosound(); } else if (strcmp(buffer,"reboot") == 0) { reboot(); } else if (strcmp(buffer,"shutdown") == 0) { // Define variables byte temp; // Disable interrupts cli(); // Clear all keyboard buffers (output and command buffers) do { // Empty user data temp = inb(0x64); // Empty keyboard data if (check_flag(temp, 0) != 0) { inb(0x60); } } while (check_flag(temp, 1) != 0); // Check for Advanced Power Management check_apm(); // Initialize Advanced Power Management init_apm(); // Send shutdown command shutdown(); // Halt the cpu if failed halt(); } else if (strcmp(buffer,"sleep") == 0) { // Define variables byte temp; // Disable interrupts cli(); // Clear all keyboard buffers (output and command buffers) do { // Empty user data temp = inb(0x64); // Empty keyboard data if (check_flag(temp, 0) != 0) { inb(0x60); } } while (check_flag(temp, 1) != 0); // Check for Advanced Power Management check_apm(); // Initialize Advanced Power Management init_apm(); // Send standby command standby(); // Halt the cpu if failed halt(); } else if (strcmp(buffer,"time") == 0) { time_disp(); } else if (strcmp(buffer,"twinkle") == 0) { twinkle(); } else if (strcmp(buffer,"usermode") == 0) { umode_disp(fs_root); } else if (strcmp(buffer,"version") == 0) { version_disp(); } else if (strcmp(buffer,"vga") == 0) { VgaTest(); } else if (strcmp(buffer,"wait") == 0) { timer_wait(250000); } else { printf("Unknown command: "); printf(buffer); printf("\n"); } }