-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Linear Poti, Line, and Piezo Speaker 2.0 Bricklets
- Loading branch information
Showing
13 changed files
with
706 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/test.cr | ||
/dl/ | ||
/obj/ | ||
/docs/ | ||
/lib/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
@[Link( | ||
ldflags: "#{__DIR__}/../../../obj/bricklet_line.o" | ||
)] | ||
|
||
lib LibTF | ||
alias Line = Entity | ||
|
||
# Creates the device object \c line with the unique device ID \c uid and adds | ||
# it to the IPConnection \c ipcon. | ||
fun line_create( | ||
line : Line*, | ||
uid : LibC::Char*, | ||
ipcon : IPConnection* | ||
) : Void | ||
|
||
# Removes the device object \c line from its IPConnection and destroys it. | ||
# The device object cannot be used anymore afterwards. | ||
fun line_destroy( | ||
line : Line* | ||
) : Void | ||
|
||
# Returns the currently measured reflectivity. The reflectivity is a value between 0 (not reflective) and 4095 (very reflective). | ||
# | ||
# Usually black has a low reflectivity while white has a high reflectivity. | ||
# | ||
# If you want to get the reflectivity periodically, it is recommended to use the LINE_CALLBACK_REFLECTIVITY callback and set the period with line_set_reflectivity_callback_period(). | ||
fun line_get_reflectivity( | ||
line : Line*, | ||
ret_reflectivity : Int16* | ||
) : LibC::Int | ||
|
||
LINE_CALLBACK_REFLECTIVITY = 8 | ||
LINE_CALLBACK_REFLECTIVITY_REACHED = 9 | ||
|
||
fun line_register_callback( | ||
line : Line*, | ||
callback_id : Int16, | ||
function : Void*, | ||
user_data : Void* | ||
) : Void | ||
|
||
fun line_set_reflectivity_callback_period( | ||
line : Line*, | ||
period : UInt32 | ||
) : LibC::Int | ||
|
||
fun line_set_reflectivity_callback_threshold( | ||
line : Line*, | ||
option : LibC::Char, | ||
min : UInt16, | ||
max : UInt16 | ||
) : LibC::Int | ||
|
||
fun line_set_debounce_period( | ||
line : Line*, | ||
debounce : UInt32 | ||
) : LibC::Int | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@[Link( | ||
ldflags: "#{__DIR__}/../../../obj/bricklet_linear_poti.o" | ||
)] | ||
|
||
lib LibTF | ||
alias LinearPoti = Entity | ||
|
||
# Creates the device object \c linear_poti with the unique device ID \c uid and adds | ||
# it to the IPConnection \c ipcon. | ||
fun linear_poti_create( | ||
linear_poti : LinearPoti*, | ||
uid : LibC::Char*, | ||
ipcon : IPConnection* | ||
) : Void | ||
|
||
# Removes the device object \c linear_poti from its IPConnection and destroys it. | ||
# The device object cannot be used anymore afterwards. | ||
fun linear_poti_destroy( | ||
linear_poti : LinearPoti* | ||
) : Void | ||
|
||
# Returns the position of the linear potentiometer. The value is between 0 (slider down) and 100 (slider up). | ||
# | ||
# If you want to get the position periodically, it is recommended to use the {@link LINEAR_POTI_CALLBACK_POSITION} callback and set the period with {@link linear_poti_set_position_callback_period}. | ||
fun linear_poti_get_position( | ||
linear_poti : LinearPoti*, | ||
ret_position : Int16* | ||
) : LibC::Int | ||
|
||
fun linear_poti_set_position_callback_period( | ||
linear_poti : LinearPoti*, | ||
period : UInt32 | ||
) : LibC::Int | ||
|
||
LINEAR_POTI_CALLBACK_POSITION = 13 | ||
|
||
fun linear_poti_register_callback( | ||
linear_poti : LinearPoti*, | ||
callback_id : Int16, | ||
function : Void*, | ||
user_data : Void* | ||
) : Void | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
@[Link( | ||
ldflags: "#{__DIR__}/../../../obj/bricklet_piezo_speaker_v2.o" | ||
)] | ||
|
||
lib LibTF | ||
alias PiezoSpeakerV2 = Entity | ||
|
||
# Creates the device object \c piezo_speaker_v2 with the unique device ID \c uid and adds | ||
# it to the IPConnection \c ipcon. | ||
fun piezo_speaker_v2_create( | ||
piezo_speaker_v2 : PiezoSpeakerV2*, | ||
uid : LibC::Char*, | ||
ipcon : IPConnection* | ||
) : Void | ||
|
||
# Removes the device object \c piezo_speaker_v2 from its IPConnection and destroys it. | ||
# The device object cannot be used anymore afterwards. | ||
fun piezo_speaker_v2_destroy( | ||
piezo_speaker_v2 : PiezoSpeakerV2* | ||
) : Void | ||
|
||
PIEZO_SPEAKER_V2_BEEP_DURATION_OFF = 0 | ||
PIEZO_SPEAKER_V2_BEEP_DURATION_INFINITE = 4294967295 | ||
|
||
# Beeps with the given frequency and volume for the duration. | ||
# | ||
# A duration of 0 stops the current beep if any is ongoing. A duration of 4294967295 results in an infinite beep. | ||
# | ||
# The following constants are available for this function: | ||
# | ||
# For duration: | ||
# | ||
# PIEZO_SPEAKER_V2_BEEP_DURATION_OFF = 0 | ||
# PIEZO_SPEAKER_V2_BEEP_DURATION_INFINITE = 4294967295 | ||
fun piezo_speaker_v2_set_beep( | ||
piezo_speaker_v2 : PiezoSpeakerV2*, | ||
frequency : UInt16, | ||
volume : UInt8, | ||
duration : UInt32 | ||
) : LibC::Int | ||
|
||
# Returns the last beep settings as set by piezo_speaker_v2_set_beep(). If a beep is currently running it also returns the remaining duration of the beep. | ||
# | ||
# If the frequency or volume is updated during a beep (with piezo_speaker_v2_update_frequency() or piezo_speaker_v2_update_volume()) this function returns the updated value. | ||
# | ||
# The following constants are available for this function: | ||
# | ||
# For ret_duration: | ||
# | ||
# PIEZO_SPEAKER_V2_BEEP_DURATION_OFF = 0 | ||
# PIEZO_SPEAKER_V2_BEEP_DURATION_INFINITE = 4294967295 | ||
fun piezo_speaker_v2_get_beep( | ||
piezo_speaker_v2 : PiezoSpeakerV2*, | ||
ret_frequency : UInt16*, | ||
ret_volume : UInt8*, | ||
ret_duration : UInt32*, | ||
ret_duration_remaining : UInt32* | ||
) : LibC::Int | ||
|
||
PIEZO_SPEAKER_V2_ALARM_DURATION_OFF = 0 | ||
PIEZO_SPEAKER_V2_ALARM_DURATION_INFINITE = 4294967295 | ||
|
||
# Creates an alarm (a tone that goes back and force between two specified frequencies). | ||
# | ||
# The following parameters can be set: | ||
# | ||
# Start Frequency: Start frequency of the alarm. | ||
# End Frequency: End frequency of the alarm. | ||
# Step Size: Size of one step of the sweep between the start/end frequencies. | ||
# Step Delay: Delay between two steps (duration of time that one tone is used in a sweep). | ||
# Duration: Duration of the alarm. | ||
# | ||
# A duration of 0 stops the current alarm if any is ongoing. A duration of 4294967295 results in an infinite alarm. | ||
# | ||
# Below you can find two sets of example settings that you can try out. You can use these as a starting point to find an alarm signal that suits your application. | ||
# | ||
# Example 1: 10 seconds of loud annoying fast alarm | ||
# | ||
# Start Frequency = 800 | ||
# End Frequency = 2000 | ||
# Step Size = 10 | ||
# Step Delay = 1 | ||
# Volume = 10 | ||
# Duration = 10000 | ||
# | ||
# Example 2: 10 seconds of soft siren sound with slow build-up | ||
# | ||
# Start Frequency = 250 | ||
# End Frequency = 750 | ||
# Step Size = 1 | ||
# Step Delay = 5 | ||
# Volume = 0 | ||
# Duration = 10000 | ||
# | ||
# The following conditions must be met: | ||
# | ||
# Start Frequency: has to be smaller than end frequency | ||
# End Frequency: has to be bigger than start frequency | ||
# Step Size: has to be small enough to fit into the frequency range | ||
# Step Delay: has to be small enough to fit into the duration | ||
# | ||
# The following constants are available for this function: | ||
# | ||
# For duration: | ||
# | ||
# PIEZO_SPEAKER_V2_ALARM_DURATION_OFF = 0 | ||
# PIEZO_SPEAKER_V2_ALARM_DURATION_INFINITE = 4294967295 | ||
fun piezo_speaker_v2_set_alarm( | ||
piezo_speaker_v2 : PiezoSpeakerV2*, | ||
start_frequency : UInt16, | ||
end_frequency : UInt16, | ||
step_size : UInt16, | ||
step_delay : UInt16, | ||
volume : UInt8, | ||
duration : UInt32 | ||
) : LibC::Int | ||
|
||
# Returns the last alarm settings as set by piezo_speaker_v2_set_alarm(). If an alarm is currently running it also returns the remaining duration of the alarm as well as the current frequency of the alarm. | ||
# | ||
# If the volume is updated during an alarm (with piezo_speaker_v2_update_volume()) this function returns the updated value. | ||
# | ||
# The following constants are available for this function: | ||
# | ||
# For ret_duration: | ||
# | ||
# PIEZO_SPEAKER_V2_ALARM_DURATION_OFF = 0 | ||
# PIEZO_SPEAKER_V2_ALARM_DURATION_INFINITE = 4294967295 | ||
# | ||
# For ret_duration_remaining: | ||
# | ||
# PIEZO_SPEAKER_V2_ALARM_DURATION_OFF = 0 | ||
# PIEZO_SPEAKER_V2_ALARM_DURATION_INFINITE = 4294967295 | ||
fun piezo_speaker_v2_get_alarm( | ||
piezo_speaker_v2 : PiezoSpeakerV2*, | ||
ret_start_frequency : UInt16*, | ||
ret_end_frequency : UInt16*, | ||
ret_step_size : UInt16*, | ||
ret_step_delay : UInt16*, | ||
ret_volume : UInt8*, | ||
ret_duration : UInt32*, | ||
ret_duration_remaining : UInt32*, | ||
ret_current_frequency : UInt16* | ||
) : LibC::Int | ||
|
||
# Updates the volume of an ongoing beep or alarm. | ||
fun piezo_speaker_v2_update_volume( | ||
piezo_speaker_v2 : PiezoSpeakerV2*, | ||
volume : UInt8 | ||
) : LibC::Int | ||
|
||
# Updates the frequency of an ongoing beep. | ||
fun piezo_speaker_v2_update_frequency( | ||
piezo_speaker_v2 : PiezoSpeakerV2*, | ||
frequency : UInt16 | ||
) : LibC::Int | ||
|
||
|
||
PIEZO_SPEAKER_V2_STATUS_LED_CONFIG_OFF = 0u8 | ||
PIEZO_SPEAKER_V2_STATUS_LED_CONFIG_ON = 1u8 | ||
PIEZO_SPEAKER_V2_STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2u8 | ||
PIEZO_SPEAKER_V2_STATUS_LED_CONFIG_SHOW_STATUS = 3u8 | ||
|
||
fun piezo_speaker_v2_set_status_led_config( | ||
piezo_speaker_v2 : PiezoSpeakerV2*, | ||
config : UInt8 | ||
) : LibC::Int | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.