Synopsis

#include <nxtlibc.h>

int		nxt_bluetooth_initialize(char *)
void		nxt_bluetooth_done()
int		get_battery_level()
char *		get_firmware_version()
int		get_bluetooth_signal_strength()
int		start_program(char *)
int		stop_program()
int		play_sound_file(int, char *)
int		stop_sound_playback()
int		play_tone(short int, short int)
int		keep_alive()
int		set_brick_name(char *)
int		delete_user_flash()

int 		list_files(char *)
int		read_file(char *, char **, int *)
int		write_file(int, char *, char *, int)
int		delete_file(char *)
int		open_read_linear(char *)

int		clear_screen()
int		draw_pixel(unsigned char, unsigned char)
int		clear_pixel(unsigned char, unsigned char)
int		draw_line(unsigned char, unsigned char, unsigned char, unsigned char)

int		_set_output_state(unsigned char, signed char, unsigned char,
		unsigned char, signed char, unsigned char, unsigned long)
int		_get_output_state(unsigned char, signed char *, unsigned char *,
		unsigned char *, signed char *, unsigned char *,
		unsigned long *, int *, int *, int *)
int		reset_motor_position(unsigned char, unsigned char)

void		set_touch_sensor(unsigned char)
void		set_sound_sensor(unsigned char)
void		set_light_sensor(unsigned char)
void		set_ultrasonic_sensor(unsigned char)
int		reset_input_scaled_value(unsigned char)
int		get_touch_value()
int		get_sound_db_pct()
int		get_sound_db_scale()
int		get_sound_dba_pct()
int		get_sound_dba_scale()
int		get_light_active_pct()
int		get_light_active_scale()
int		get_light_ambient_pct()
int		get_light_ambient_scale()
int		get_light_reflection()

int		initialize_ultrasonic_sensor()
int		get_ultrasonic_measurement_units()
int		get_ultrasonic_measurement_byte(unsigned char byte)
int		get_ultrasonic_continuous_measurement_interval()
int		get_ultrasonic_read_command_state()
int		get_ultrasonic_actual_zero()
int		get_ultrasonic_actual_scale_factor()
int		get_ultrasonic_actual_scale_divisor()
int		set_ultrasonic_single_shot()
int		set_ultrasonic_continuous_measurement()
int		set_ultrasonic_event_capture_mode()
int		ultrasonic_request_warm_reset()
int		set_ultrasonic_continuous_measurement_interval(unsigned char)
int		set_ultrasonic_actual_zero(unsigned char)
int		set_ultrasonic_actual_scale_factor(unsigned char)
int		set_ultrasonic_actual_scale_divisor(unsigned char)
int		set_ultrasonic_off()

void		list_modules(char *)
int		get_module_id(int)
int		read_io_map(int, unsigned short int, unsigned short int, unsigned char **)
int		write_io_map(int, unsigned short int, unsigned short int, unsigned char *)

int		poll_command_length(unsigned char)
int		poll_command(unsigned char, unsigned char, char **, int *)

int		message_write(unsigned char, unsigned char, unsigned char *)
int		message_read(unsigned char, unsigned char, unsigned char,
		unsigned char *, unsigned char *, unsigned char **)


Private functions:
int		_get_device_info(char **, int *, int *)
int		_close_command(unsigned char)
unsigned char	_find_first(char *)
int		_find_next(unsigned char)
unsigned char 	_open_read(char *, int *)
int		_read_command(unsigned char, char *, short int)
unsigned char	_open_write(char *, int)
int		_write_command(unsigned char, char *, int)
unsigned char	_open_write_linear(char *, int)
unsigned char	_open_write_data(char *, int)
unsigned char	_open_append_data(char *, int)
int		_set_input_mode(unsigned char, unsigned char, unsigned char)
int		_get_input_values(unsigned char, unsigned char *, unsigned char *,
		unsigned char *, unsigned char *, unsigned short int *,
		unsigned short int *, signed short int *, signed short int *);
int		_ls_get_status(unsigned char);
int		_ls_write(unsigned char, unsigned char, unsigned char, char *);
int		_ls_read(unsigned char, int *, char **)
int		_ls_request_response(unsigned char, unsigned char, char *, int, char **, int *)
int		_close_module_handle(unsigned char)
unsigned char	_request_first_module(char *)
int		_request_next_module(unsigned char)

nxt_bluetooth_initialize(char *)

int nxt_bluetooth_initialize(char *)

Provide the mac address of the NXT device in the form XX:XX:XX:XX:XX:XX
Returns 0 on success, -1 on failure and prints the error to stderr.

nxt_bluetooth_done()

int nxt_bluetooth_done()

Closes the bluetooth connection.

get_battery_level()

int get_battery_level()

Returns the current battery level in mV or -1 on failure and prints the error to stderr.

get_firmware_version()

char *get_firmware_version()

Returns the current firmware and protocol versions in the form: "Protocol: 1.124 Firmware: 1.1".
Returns NULL on failure and prints the error to stderr.

get_bluetooth_signal_strength()

int get_bluetooth_signal_strength

Returns the bluetooth signal strength. For some reason this is always 0.
Maybe this is different if acting in master/slave mode with 2 nxt bricks.
Returns -1 on failure and prints the error to stderr.

start_program(char *)

int start_program(char *)

Starts a program which is on the brick.
Returns 0 on success, -1 on failure and prints the error to stderr.

stop_program()

int stop_program()

Stops the currently running program.
Returns 0 on success, -1 on failure and prints the error to stderr.

play_sound_file(int, char *)

int play_sound_file(int, char *)

int is a boolean, 1 = loop sound file indefinitely, 0 play only once.
char * is the filename.
Returns 0 on success, -1 on failure and prints the error to stderr.

stop_sound_playback()

int stop_sound_playback()

This is pretty self explanatory.
Returns 0 on success, -1 on failure and prints the error to stderr.

play_tone(short int, short int)

int play_tone(short int, short int)

short int is Frequency in Hz (Range 200-14000Hz).
short int is Duration in ms.
Returns 0 on success, -1 on failure and prints the error to stderr.

keep_alive()

int keep_alive()

Returns current sleep time limit in milliseconds.
Returns -1 on failure and prints the error to stderr.

set_brick_name(char *)

int set_brick_name(char *)

Sets the name of your NXT brick, of which the default is "NXT".
Returns -1 on failure and prints the error to stderr.

delete_user_flash()

int delete_user_flash()

I have no idea what this does and it hasn't been tested.
Returns -1 on failure and prints the error to stderr.

list_files(char *)

void list_files(char *)

char * You can provide a search mask or NULL for all files.
You can then access the file list like such:

extern struct fstruct *filefirst;
struct fstruct *fs;
list_files(NULL);
fs = filefirst;
while (fs != NULL) {
        printf("%s %d\n", fs->filename, fs->size);
        fs = fs->next;
        }

Returns 0 on success, -1 on failure and prints the error to stderr.

read_file(char *, char **, int *)

int read_file(char *, char **, int *)

char * is the filename.
char ** is the return buffer of the file contents.
int * is the return length of the file.
Returns 0 on success, -1 on failure and prints the error to stderr.

write_file(int, char *, char *, int)

int write_file(int, char *, char *, int)

WARNING: I HAVE NOT TRIED THIS FUNCTION, SO USE AT YOUR OWN RISK. IF YOU TRY IT, PLEASE LET ME KNOW.

int is one of FILE_NORMAL, FILE_LINEAR, FILE_DATA, FILE_APPEND_DATA.
I am not sure exactly what the last 3 do, but I think they are for system and sepcial files.
char * is the filename to write.
char * is the file content buffer to write.
int is the length of the content buffer to write.
Returns 0 on success, -1 on failure and prints the error to stderr.

delete_file(char *)

int delete_file(char *)

char * is the filename.
Returns 0 on success, -1 on failure and prints the error to stderr.

open_read_linear(char *)

int open_read_linear(char *)

char * is the filename.
Returns a pointer to the linear memory segment. Not sure exactly what this does.
Returns -1 on failure and prints the error to stderr.

clear_screen()

int clear_screen()

This clears everything except the bar across the top, and you can write above the bar, but it
	disappears immediatly. Everything below the bar is writable however. 
Returns 0 on success, -1 on failure and prints the error to stderr.

draw_pixel(unsigned char, unsigned char)

int draw_pixel(unsigned char, unsigned char)

unsigned char is the x point.
unsigned char is the y point.
This will draw a pixel at the specified x,y point. The display size is 100x64.
Returns 0 on success, -1 on failure and prints the error to stderr.

clear_pixel(unsigned char, unsigned char)

int clear_pixel(unsigned char, unsigned char)

unsigned char is the x point.
unsigned char is the y point.
This will clear the pixel at the specified x,y point.
Returns 0 on success, -1 on failure and prints the error to stderr.

draw_line(unsigned char, unsigned char, unsigned char, unsigned char)

int delete_file(char *)

unsigned char is the x0 point.
unsigned char is the y0 point.
unsigned char is the x1 point.
unsigned char is the y1 point.
This will draw a line from x0,y0 to x1, y1.
Returns 0 on success, -1 on failure and prints the error to stderr.

_set_output_state(unsigned char, signed char, unsigned char, unsigned char, signed char, unsigned char, unsigned long)

int _set_output_state(unsigned char, signed char, unsigned char,
		unsigned char, signed char, unsigned char, unsigned long)

See SETOUTPUTSTATE in Bluetooth Appendix 2 for further information.
I will have macros for some of these eventually.

unsigned char is the output port (0-2)
signed char is the power set point (range -100 to 100)
unsigned char is the Mode byte (Bit field)
	MOTOR_ON, BRAKE, REGULATED
unsigned char is the regularion mode (enumerated)
	REGULATION_MODE_IDLE, REGULATION_MODE_MOTOR_SPEED, REGULATION_MODE_MOTOR_SYNC
signed char is the turn ratio (range -100 to 100)
unsigned char is the run state (enumerated)
	MOTOR_RUN_STATE_IDLE, MOTOR_RUN_STATE_RAMPUP, MOTOR_RUN_STATE_RUNNING, MOTOR_RUN_STATE_RAMPDOWN
unsigned long is Tacho limit (0 = run forever)
Returns 0 on success, -1 on failure and prints the error to stderr.

_get_input_state(unsigned char, signed char *, unsigned char *, unsigned char *, signed char *, unsigned char *, unsigned long *, int *, int *, int *)

int _get_input_state(unsigned char, signed char *, unsigned char *, unsigned char *, signed char *,
			unsigned char *, unsigned long *, int *, int *, int *)

See GETETOUTPUTSTATE in Bluetooth Appendix 2 for further information.
I will have macros for some of these eventually.

unsigned char is the output port (0-2)
signed char * returns the power set point (rangre -100 to 100)
unsigned char * returns the mode (bit field, see above)
unsigned char * returns the regulation mode (enumerated, see above)
signed char * returns the turn ration (range -100 to 100)
unsigned char * returns the run state (enumerated, see above)
unsigned long * returns the tacho limit (current limit on a movement in progress, if any)
int * returns the tacho count (internal count, number of counts since last reset of the motor counter)
int * returns the block tacho count (current position relative to the last programmed movement)
int * returns the rotation count (current position relative to the last reset of the rotation sensor
	for this motor)
Returns 0 on success, -1 on failure and prints the error to stderr.

reset_motor_position(unsigned char, unsigned char)

int reset_motor_position(unsigned char, unsigned char)

unsigned char is output port (range 0-2)
unsigned char is boolean (1 = position relative to last movement, 0 = absolute position)
Returns 0 on success, -1 on failure and prints the error to stderr.

set_touch_sensor(unsigned char)

void set_touch_sensor(unsigned char)

Set the touch sensor port. This must be done before the sensor port can be used.
NXT_SENSOR1, NXT_SENSOR2, NXT_SENSOR3, NXT_SENSOR4.

set_sound_sensor(unsigned char)

void set_sound_sensor(unsigned char)

Set the sound sensor port. This must be done before the sensor port can be used.
NXT_SENSOR1, NXT_SENSOR2, NXT_SENSOR3, NXT_SENSOR4.

set_light_sensor(unsigned char)

void set_light_sensor(unsigned char)

Set the light sensor port. This must be done before the sensor port can be used.
NXT_SENSOR1, NXT_SENSOR2, NXT_SENSOR3, NXT_SENSOR4.

set_ultrasonic_sensor(unsigned char)

void set_ultrasonic_sensor(unsigned char)

Set the ultrasonicsensor port. This must be done before the sensor port can be used.
NXT_SENSOR1, NXT_SENSOR2, NXT_SENSOR3, NXT_SENSOR4.

reset_input_scaled_value(unsigned char)

void reset_input_scaled_value(unsigned char)

unsigned char is the sensor port. I am not exactly sure what this does.
NXT_SENSOR1, NXT_SENSOR2, NXT_SENSOR3, NXT_SENSOR4.

get_touch_value()

void get_touch_value()

Returns the touch sensor value, 1 = pressed, 0 = unpressed.
Returns -1 on failure and prints the error to stderr.

get_sound_db_pct()

int get_sound_db_pct()

Returns audible range in a percentage, 0 - 100. Need to find more info on this.
Returns -1 on failure and prints the error to stderr.

get_sound_db_scale()

int get_sound_db_scale()

Returns audible range in a scale, 0 - 1023. Need to find more info on this.
Returns -1 on failure and prints the error to stderr.

get_sound_dba_pct()

int get_sound_dba_pct()

Returns audible + non-audible range in a percentage, 0 - 100. Need to find more info on this.
Returns -1 on failure and prints the error to stderr.

get_sound_dba_scale()

int get_sound_dba_scale()

Returns audible + non-audible range in a scale, 0 - 1023. Need to find more info on this.
Returns -1 on failure and prints the error to stderr.

get_light_active_pct()

int get_light_active_pct()

I think this returns reflected light, in a percentage, 0 - 100. Need more info on this.
Returns -1 on failure and prints the error to stderr.

get_light_active_scale()

int get_light_active_scale()

I think this returns reflected light, in a scale, 0 - 1023.
Returns -1 on failure and prints the error to stderr.

get_light_ambient_pct()

int get_light_ambient_pct()

Returns the amount of detected light (the light sensor is off) in a percentage, 0 - 100.
Returns -1 on failure and prints the error to stderr.

get_light_ambient_scale()

int get_light_ambient_scale()

Returns the amount of detected light (the light sensor is off) in a scale, 0 - 1023.
Returns -1 on failure and prints the error to stderr.

get_light_reflection()

int get_light_reflection()

This doesn't work. I think this has to do with attaching the old RCX light sensor to the NXT.
Returns -1 on failure and prints the error to stderr.

initialize_ultrasonic_sensor()

int initialize_ultrasonic_sensor()

You must call this after set_ultrasonic_sensor before using any of the other ultrasonic calls.
Returns 0 on success, -1 on failure and prints the error to stderr.

get_ultrasonic_measurement_units()

int get_ultrasonic_measurement_units()

This returns different data every time, it's supposed to return whether your sensor is set to inches
	or centimeters. At this point it just does below till I can fix it.
Returns 0 on success, -1 on failure and prints the error to stderr.

get_ultrasonic_measurement_byte(unsigned char byte)

int get_ultrasonic_measurement_byte(unsigned char byte)

Returns the distance reading from the NXT from register $byte.
$byte should be a value 0-7 indicating the measurement register
in the ultrasound sensor. In continuous measurement mode,
measurements are stored in register 0 only, however in one-shot mode,
each time one-shot is called a value will be stored in a new register.
Returns -1 on failure and prints the error to stderr.

get_ultrasonic_continuous_measurement_interval()

int get_ultrasonic_continuous_measurement_interval()

Returns the period between ultrasonic measurements, I think this is in milliseconds?
Returns -1 on failure and prints the error to stderr.

get_ultrasonic_read_command_state()

int get_ultrasonic_read_command_state()

Returns whether the sensor is in one-off mode or continuous measurement mode (the default).
Returns -1 on failure and prints the error to stderr.

get_ultrasonic_actual_zero()

int get_ultrasonic_actual_zero()

Returns the calibrated zero-distance value for the sensor.
Returns -1 on failure and prints the error to stderr.

get_ultrasonic_actual_scale_factor()

int get_ultrasonic_actual_scale_factor()

Returns the scale factor used to compute distances.
Returns -1 on failure and prints the error to stderr.

get_ultrasonic_actual_scale_divisor()

int get_ultrasonic_actual_scale_divisor()

Returns the scale divisor used to compute distances.
Returns -1 on failure and prints the error to stderr.

set_ultrasonic_continuous_measurement()

int set_ultrasonic_continuous_measurement()

Puts the sensor in continuous measurement mode (the default).
Returns -1 on failure and prints the error to stderr.

set_ultrasonic_single_shot()

int set_ultrasonic_single_shot()

Puts the sensor in single shot mode, it will only store a value in a register once each time this
	function is called.
Returns -1 on failure and prints the error to stderr.

set_ultrasonic_event_capture_mode()

int set_ultrasonic_event_capture_mode()

In this mode the US sensor will detect only other ultrasound sensors in the vicinity.
Returns -1 on failure and prints the error to stderr.

ultrasonic_request_warm_reset()

int ultrasonic_request_warm_reset()

Maybe this does a warm reset? Hmmmmmm...
Returns 0 on success, -1 on failure and prints the error to stderr.

set_ultrasonic_continuous_measurement_interval(unsigned char)

int set_ultrasonic_continuous_measurement_interval(unsigned char)

Sets the sampling interval for the range sensor. Not sure of timing.
Returns 0 on success, -1 on failure and prints the error to stderr.

set_ultrasonic_actual_zero(unsigned char)

int set_ultrasonic_actual_zero(unsigned char)

Sets the calibrated zero value for the sensor.
Returns 0 on success, -1 on failure and prints the error to stderr.

set_ultrasonic_actual_scale_factor(unsigned char)

int set_ultrasonic_actual_scale_factor(unsigned char)

Sets the scale factor used in computing range.
Returns 0 on success, -1 on failure and prints the error to stderr.

set_ultrasonic_actual_scale_divisor(unsigned char)

int set_ultrasonic_actual_scale_divisor(unsigned char)

Sets the scale divisor used in computing range.
Returns 0 on success, -1 on failure and prints the error to stderr.

set_ultrasonic_off()

int set_ultrasonic_off()

Turn the ultrasonic sensor off.
Returns 0 on success, -1 on failure and prints the error to stderr.

list_modules(char *)

void int list_modules(char *)

char * is the mask or NULL for all modules.
You can access the mdoules list like such:

extern struct fstruct *modulefirst;
struct fstruct *fs;
list_modules(NULL);
fs = modulefirst;
while (fs != NULL) {
        printf("%s %d %d\n", fs->filename, fs->moduleid, fs->module);
        fs = fs->next;
        }

get_module_id(int)

int get_module_id(int)

int is the module request, they are prefaced with MODULE_ in nxtlibc.h
Returns the module id for use with read_io_map, and write_io_map.
Returns -1 on failure and prints the error to stderr.

read_io_map(int, unsigned short int, unsigned short int, unsigned char **)

int read_io_map(int, unsigned short int, unsigned short int, unsigned char **)

int is the moduleid (from get_module_id).
unsigned short int is the index position.
unsigned short int is the length (I think this is 110 max).
unsigned char **data is the return buffer of the data read.
Returns length read on success, -1 on failure and prints the error to stderr.

write_io_map(int, unsigned short int, unsigned short int, unsigned char *)

int write_io_map(int, unsigned short int, unsigned short int, unsigned char *)

int is the moduleid (from get_module_id).
unsigned short int is the index position.
unsigned short int is the length (I think this is 110 max).
unsigned char *data is the data to write.
Returns 0 on success, -1 on failure and prints the error to stderr.

poll_command_length(unsigned char)

int poll_command_length(unsigned char)

unsigned char is one of POLL_BUFFER or HS_BUFFER (highspeed buffer?).
Not exactly sure what this does.
Returns number of bytes for the command ready in the buffer. (0 = no command ready)
Returns -1 on failure and prints the error to stderr.

poll_command(unsigned char, unsigned char ,char **, int *)

int poll_command_length(unsigned char, unsigned char, char **, int *)

unsigned char is one of POLL_BUFFER or HS_BUFFER (highspeed buffer?).
unsigned char is the command length
char ** is the return data buffer.
int * is the return data length.
Not exactly sure what this does.
Returns the data length read.
Returns -1 on failure and prints the error to stderr.

message_write(unsigned char, unsigned char, unsigned char *)

int message_write(unsigned char, unsigned char, unsigned char *)

unsigned char is the inbox.
unsigned char is the data size to write.
unsigned char * is the data to write.
From what I understand this is to communicate with running programs on the NXT.
Returns 0 on success, -1 on failure and prints the error to stderr.

message_read(unsigned char, unsigned char, unsigned char, unsigned char *, unsigned char *, unsigned char **)

int message_read(unsigned char, unsigned char, unsigned char,
		unsigned char *, unsigned char *, unsigned char **)

unsigned char is the remote inbox (0-9).
unsigned char is the local inbox (0-9).
unsigned char is remove boolean. (1 = clear message, 0 = keep message in inbox)
unsigned char * is the return inbox number. (one byte)
unsigned char * is the return message size. (one byte)
unsigned char ** is the return data.
From what I understand this is to communicate with running programs on the NXT.
Returns 0 on success, -1 on failure and prints the error to stderr.