mirror of
https://github.com/Maschell/HIDtoVPADNetworkClient.git
synced 2024-11-22 14:09:17 +01:00
Merge branch 'master' of https://github.com/QuarkTheAwesome/HIDToVPADNetworkClient
This commit is contained in:
commit
6fd6c9aeaf
@ -6,7 +6,11 @@
|
|||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" path="resources"/>
|
<classpathentry excluding="**" kind="src" output="target/classes" path="resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@ hs_err_pid*
|
|||||||
bin/
|
bin/
|
||||||
target/
|
target/
|
||||||
.settings/
|
.settings/
|
||||||
|
config/hidtovpad.properties
|
||||||
|
295
eclipse_code_convention.xml
Normal file
295
eclipse_code_convention.xml
Normal file
@ -0,0 +1,295 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<profiles version="12">
|
||||||
|
<profile kind="CodeFormatterProfile" name="HIDtoVPADNetworkClient Code Convention" version="12">
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="160"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_lambda_body" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.source" value="1.8"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.8"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.8"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="160"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
@ -32,32 +32,30 @@ import net.ash.HIDToVPADNetworkClient.util.Settings;
|
|||||||
* TODO finish HidController
|
* TODO finish HidController
|
||||||
* TODO locale
|
* TODO locale
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Hello World!");
|
Settings.loadSettings();
|
||||||
Settings.loadSettings();
|
try {
|
||||||
try {
|
new Thread(ActiveControllerManager.getInstance()).start();
|
||||||
new Thread(ActiveControllerManager.getInstance()).start();
|
new Thread(NetworkManager.getInstance()).start();
|
||||||
new Thread(NetworkManager.getInstance()).start();
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
fatal();
|
||||||
fatal();
|
}
|
||||||
}
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
public void run() {
|
||||||
public void run() {
|
GuiMain.createGUI();
|
||||||
GuiMain.createGUI();
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static void fatal() {
|
public static void fatal() {
|
||||||
System.err.println("HID To VPAD Network Client encountered an irrecoverable error.");
|
System.err.println("HID To VPAD Network Client encountered an irrecoverable error.");
|
||||||
System.err.println("Exiting...");
|
System.err.println("Exiting...");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initiateShutdown() {
|
public static void initiateShutdown() {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,41 +29,42 @@ import net.ash.HIDToVPADNetworkClient.util.Settings;
|
|||||||
import net.ash.HIDToVPADNetworkClient.util.Utilities;
|
import net.ash.HIDToVPADNetworkClient.util.Utilities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main controller interface, extended by controller drivers.
|
* Main controller interface, extended by controller drivers. <br>
|
||||||
* <br><br>
|
* <br>
|
||||||
* See {@link LinuxDevInputController} for a full implementation.
|
* See {@link LinuxDevInputController} for a full implementation.
|
||||||
|
*
|
||||||
* @author ash
|
* @author ash
|
||||||
*/
|
*/
|
||||||
public abstract class Controller implements Runnable{
|
public abstract class Controller implements Runnable {
|
||||||
private boolean active;
|
private boolean active;
|
||||||
@Getter private final ControllerType type;
|
@Getter private final ControllerType type;
|
||||||
@Getter private final String identifier;
|
@Getter private final String identifier;
|
||||||
private byte[] latestData = null;
|
private byte[] latestData = null;
|
||||||
|
|
||||||
boolean shutdown = false;
|
boolean shutdown = false;
|
||||||
boolean shutdownDone = false;
|
boolean shutdownDone = false;
|
||||||
private Object dataLock = new Object();
|
private Object dataLock = new Object();
|
||||||
private Object shutdownLock = new Object();
|
private Object shutdownLock = new Object();
|
||||||
|
|
||||||
private Object rumbleLock = new Object();
|
private Object rumbleLock = new Object();
|
||||||
private boolean rumble = false;
|
private boolean rumble = false;
|
||||||
|
|
||||||
public Controller(ControllerType type, String identifier) throws ControllerInitializationFailedException{
|
public Controller(ControllerType type, String identifier) throws ControllerInitializationFailedException {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
if(!initController(identifier)){
|
if (!initController(identifier)) {
|
||||||
throw new ControllerInitializationFailedException();
|
throw new ControllerInitializationFailedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean shutdownState = shutdown;
|
boolean shutdownState = shutdown;
|
||||||
while(!shutdownState){
|
while (!shutdownState) {
|
||||||
Utilities.sleep(Settings.getDetectControllerInterval());
|
Utilities.sleep(Settings.DETECT_CONTROLLER_INTERVAL);
|
||||||
while(isActive()) {
|
while (isActive()) {
|
||||||
byte[] newData = pollLatestData();
|
byte[] newData = pollLatestData();
|
||||||
if(newData != null){
|
if (newData != null) {
|
||||||
setLatestData(newData);
|
setLatestData(newData);
|
||||||
}
|
}
|
||||||
doSleepAfterPollingData();
|
doSleepAfterPollingData();
|
||||||
@ -76,82 +77,80 @@ public abstract class Controller implements Runnable{
|
|||||||
shutdownDone = true;
|
shutdownDone = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doSleepAfterPollingData() {
|
protected void doSleepAfterPollingData() {
|
||||||
Utilities.sleep(Settings.getSleepAfterPolling());
|
Utilities.sleep(Settings.SLEEP_AFER_POLLING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized("dataLock")
|
@Synchronized("dataLock")
|
||||||
private void setLatestData(byte[] newData) {
|
private void setLatestData(byte[] newData) {
|
||||||
this.latestData = newData;
|
this.latestData = newData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized("dataLock")
|
@Synchronized("dataLock")
|
||||||
public byte[] getLatestData() {
|
public byte[] getLatestData() {
|
||||||
if(latestData != null){
|
if (latestData != null) {
|
||||||
byte[] data = this.latestData.clone();
|
byte[] data = this.latestData.clone();
|
||||||
this.latestData = null;
|
this.latestData = null;
|
||||||
return data;
|
return data;
|
||||||
}else{
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract byte[] pollLatestData();
|
public abstract byte[] pollLatestData();
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets up the driver.
|
|
||||||
* <br>
|
|
||||||
* During this method call, a connection will be made with the controller hardware (if required).
|
|
||||||
*
|
|
||||||
* @param arg Driver-specific init argument, see {@link ControllerManager} and {@link ControllerDetector}.
|
|
||||||
* @return Whether initialization was successful.
|
|
||||||
*/
|
|
||||||
public abstract boolean initController(String identifier);
|
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
* Sets up the driver. <br>
|
||||||
* Destroys the controller driver and ends the polling thread.
|
* During this method call, a connection will be made with the controller hardware (if required).
|
||||||
*/
|
*
|
||||||
public void destroyAll(){
|
* @param arg
|
||||||
destroyDriver();
|
* Driver-specific init argument, see {@link ControllerManager} and {@link ControllerDetector}.
|
||||||
endThread();
|
* @return Whether initialization was successful.
|
||||||
}
|
*/
|
||||||
|
public abstract boolean initController(String identifier);
|
||||||
/**
|
|
||||||
|
/**
|
||||||
|
* Destroys the controller driver and ends the polling thread.
|
||||||
|
*/
|
||||||
|
public void destroyAll() {
|
||||||
|
destroyDriver();
|
||||||
|
endThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Destroys the controller driver.
|
* Destroys the controller driver.
|
||||||
*/
|
*/
|
||||||
public abstract void destroyDriver();
|
public abstract void destroyDriver();
|
||||||
|
|
||||||
|
private void endThread() {
|
||||||
private void endThread() {
|
new Thread(new Runnable() {
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
setActive(false);
|
setActive(false);
|
||||||
|
|
||||||
synchronized (shutdownLock) {
|
synchronized (shutdownLock) {
|
||||||
shutdown = true;
|
shutdown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(!done){
|
while (!done) {
|
||||||
synchronized (shutdownLock) {
|
synchronized (shutdownLock) {
|
||||||
done = shutdownDone;
|
done = shutdownDone;
|
||||||
}
|
}
|
||||||
Utilities.sleep(50);
|
Utilities.sleep(50);
|
||||||
if(i++ > 50) System.out.println("Thread doesn't stop!!");
|
if (i++ > 50) System.out.println("Thread doesn't stop!!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract short getVID();
|
public abstract short getVID();
|
||||||
|
|
||||||
public abstract short getPID();
|
public abstract short getPID();
|
||||||
|
|
||||||
@Synchronized("shutdownLock")
|
@Synchronized("shutdownLock")
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
@ -159,9 +158,9 @@ public abstract class Controller implements Runnable{
|
|||||||
public void setActive(boolean active) {
|
public void setActive(boolean active) {
|
||||||
this.active = active;
|
this.active = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString() {
|
||||||
return getType() + " " + getIdentifier();
|
return getType() + " " + getIdentifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,23 +175,17 @@ public abstract class Controller implements Runnable{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null) return false;
|
||||||
if (obj == null)
|
if (getClass() != obj.getClass()) return false;
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
Controller other = (Controller) obj;
|
Controller other = (Controller) obj;
|
||||||
if (identifier == null) {
|
if (identifier == null) {
|
||||||
if (other.identifier != null)
|
if (other.identifier != null) return false;
|
||||||
return false;
|
} else if (!identifier.equals(other.identifier)) return false;
|
||||||
} else if (!identifier.equals(other.identifier))
|
if (type != other.type) return false;
|
||||||
return false;
|
|
||||||
if (type != other.type)
|
|
||||||
return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized("rumbleLock")
|
@Synchronized("rumbleLock")
|
||||||
public boolean isRumble() {
|
public boolean isRumble() {
|
||||||
return rumble;
|
return rumble;
|
||||||
@ -202,15 +195,15 @@ public abstract class Controller implements Runnable{
|
|||||||
public void startRumble() {
|
public void startRumble() {
|
||||||
this.rumble = true;
|
this.rumble = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized("rumbleLock")
|
@Synchronized("rumbleLock")
|
||||||
public void stopRumble() {
|
public void stopRumble() {
|
||||||
this.rumble = false;
|
this.rumble = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ControllerType {
|
public enum ControllerType {
|
||||||
PureJAVAHid, LINUX, XINPUT13,XINPUT14
|
PureJAVAHid, LINUX, XINPUT13, XINPUT14
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getInfoText();
|
public abstract String getInfoText();
|
||||||
}
|
}
|
@ -3,22 +3,22 @@ package net.ash.HIDToVPADNetworkClient.controller;
|
|||||||
import net.ash.HIDToVPADNetworkClient.exeption.ControllerInitializationFailedException;
|
import net.ash.HIDToVPADNetworkClient.exeption.ControllerInitializationFailedException;
|
||||||
|
|
||||||
public class DS4NewController extends PureJavaHidController {
|
public class DS4NewController extends PureJavaHidController {
|
||||||
public static final short DS4_NEW_CONTROLLER_VID = 0x54C;
|
public static final short DS4_NEW_CONTROLLER_VID = 0x54C;
|
||||||
public static final short DS4_NEW_CONTROLLER_PID = 0x09CC;
|
public static final short DS4_NEW_CONTROLLER_PID = 0x09CC;
|
||||||
|
|
||||||
public DS4NewController(String identifier) throws ControllerInitializationFailedException {
|
public DS4NewController(String identifier) throws ControllerInitializationFailedException {
|
||||||
super(identifier);
|
super(identifier);
|
||||||
//truncate package to 6;
|
// truncate package to 6;
|
||||||
this.PACKET_LENGTH = 6;
|
this.PACKET_LENGTH = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] pollLatestData() {
|
public byte[] pollLatestData() {
|
||||||
return currentData.clone();
|
return currentData.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInfoText(){
|
public String getInfoText() {
|
||||||
return "DS4 on " + getIdentifier();
|
return "DS4 on " + getIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,24 +30,24 @@ import lombok.Getter;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.ash.HIDToVPADNetworkClient.exeption.ControllerInitializationFailedException;
|
import net.ash.HIDToVPADNetworkClient.exeption.ControllerInitializationFailedException;
|
||||||
|
|
||||||
public class LinuxDevInputController extends Controller implements Runnable{
|
public class LinuxDevInputController extends Controller implements Runnable {
|
||||||
public LinuxDevInputController(String identifier) throws ControllerInitializationFailedException {
|
public LinuxDevInputController(String identifier) throws ControllerInitializationFailedException {
|
||||||
super(ControllerType.LINUX, identifier);
|
super(ControllerType.LINUX, identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int NUM_SUPPORTED_AXIS = 10; //possibly off-by-one
|
public static final int NUM_SUPPORTED_AXIS = 10; // possibly off-by-one
|
||||||
public static final int CONTROLLER_DATA_SIZE = Long.BYTES + (Byte.BYTES * NUM_SUPPORTED_AXIS);
|
public static final int CONTROLLER_DATA_SIZE = Long.BYTES + (Byte.BYTES * NUM_SUPPORTED_AXIS);
|
||||||
|
|
||||||
private static final byte JS_EVENT_BUTTON = 0x01;
|
private static final byte JS_EVENT_BUTTON = 0x01;
|
||||||
private static final byte JS_EVENT_INIT = (byte)0x80;
|
private static final byte JS_EVENT_INIT = (byte) 0x80;
|
||||||
private static final byte JS_EVENT_AXIS = 0x02;
|
private static final byte JS_EVENT_AXIS = 0x02;
|
||||||
|
|
||||||
@Getter @Setter private DataInputStream controller;
|
@Getter @Setter private DataInputStream controller;
|
||||||
|
|
||||||
@Getter @Setter private short VID;
|
@Getter @Setter private short VID;
|
||||||
@Getter @Setter private short PID;
|
@Getter @Setter private short PID;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean initController(String identifier) {
|
public boolean initController(String identifier) {
|
||||||
try {
|
try {
|
||||||
controller = new DataInputStream(new BufferedInputStream(new FileInputStream(identifier)));
|
controller = new DataInputStream(new BufferedInputStream(new FileInputStream(identifier)));
|
||||||
@ -56,93 +56,96 @@ public class LinuxDevInputController extends Controller implements Runnable{
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
setVID((short)(identifier.hashCode() & 0xFFFF));
|
setVID((short) (identifier.hashCode() & 0xFFFF));
|
||||||
setPID((short)((identifier.hashCode() >> Short.BYTES) & 0xFFFF));
|
setPID((short) ((identifier.hashCode() >> Short.BYTES) & 0xFFFF));
|
||||||
System.out.println("[LinuxDevInputController] " + identifier.toString() + " fakevid: " + Integer.toHexString((int)getVID() & 0xFFFF) + " fakepid: " + Integer.toHexString((int)getPID() & 0xFFFF));
|
System.out.println("[LinuxDevInputController] " + identifier.toString() + " fakevid: " + Integer.toHexString((int) getVID() & 0xFFFF) + " fakepid: "
|
||||||
|
+ Integer.toHexString((int) getPID() & 0xFFFF));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long buttonState = 0;
|
private long buttonState = 0;
|
||||||
private byte[] axisState = new byte[NUM_SUPPORTED_AXIS];
|
private byte[] axisState = new byte[NUM_SUPPORTED_AXIS];
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] pollLatestData() {
|
public byte[] pollLatestData() {
|
||||||
DataInputStream inputStream = getController();
|
DataInputStream inputStream = getController();
|
||||||
//Read out next event from controller
|
// Read out next event from controller
|
||||||
/*int time;*/
|
/* int time; */
|
||||||
short value;
|
short value;
|
||||||
byte type, number;
|
byte type, number;
|
||||||
try {
|
try {
|
||||||
/*time = */inputStream.readInt();
|
/* time = */inputStream.readInt();
|
||||||
value = inputStream.readShort();
|
value = inputStream.readShort();
|
||||||
type = inputStream.readByte();
|
type = inputStream.readByte();
|
||||||
number = inputStream.readByte();
|
number = inputStream.readByte();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("[LinuxDevInputController] Couldn't read from controller!");
|
System.err.println("[LinuxDevInputController] Couldn't read from controller!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.out.println("[LinuxDevInputController] Detaching...");
|
System.out.println("[LinuxDevInputController] Detaching...");
|
||||||
setActive(false);
|
setActive(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Treat init events as normal (clear init bit)
|
// Treat init events as normal (clear init bit)
|
||||||
type &= ~JS_EVENT_INIT;
|
type &= ~JS_EVENT_INIT;
|
||||||
|
|
||||||
if (type == JS_EVENT_BUTTON) {
|
if (type == JS_EVENT_BUTTON) {
|
||||||
if (number >= Long.SIZE) {
|
if (number >= Long.SIZE) {
|
||||||
System.out.println("[LinuxDevInputController] Button number " + number + " out of range; ignoring");
|
System.out.println("[LinuxDevInputController] Button number " + number + " out of range; ignoring");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value != 0) {
|
if (value != 0) {
|
||||||
//Set bit with button number
|
// Set bit with button number
|
||||||
buttonState |= (1 << number);
|
buttonState |= (1 << number);
|
||||||
} else {
|
} else {
|
||||||
//Clear bit with button number
|
// Clear bit with button number
|
||||||
buttonState &= ~(1 << number);
|
buttonState &= ~(1 << number);
|
||||||
}
|
}
|
||||||
} else if (type == JS_EVENT_AXIS) {
|
} else if (type == JS_EVENT_AXIS) {
|
||||||
if (number >= NUM_SUPPORTED_AXIS) {
|
if (number >= NUM_SUPPORTED_AXIS) {
|
||||||
System.out.println("[LinuxDevInputController] Axis number " + number + " out of range; ignoring");
|
System.out.println("[LinuxDevInputController] Axis number " + number + " out of range; ignoring");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//Do byteswap
|
// Do byteswap
|
||||||
value = (short)(((value & 0xFF) << Byte.SIZE) | ((value & 0xFF00) >> Byte.SIZE));
|
value = (short) (((value & 0xFF) << Byte.SIZE) | ((value & 0xFF00) >> Byte.SIZE));
|
||||||
//Convert to unsigned byte and store
|
// Convert to unsigned byte and store
|
||||||
axisState[number] = (byte)(((value + Short.MAX_VALUE + 1) >> 8) & 0xFF);
|
axisState[number] = (byte) (((value + Short.MAX_VALUE + 1) >> 8) & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] newData = new byte[CONTROLLER_DATA_SIZE];
|
byte[] newData = new byte[CONTROLLER_DATA_SIZE];
|
||||||
//Copy in button states
|
// Copy in button states
|
||||||
for (int i = 0; i < Long.BYTES; i++) {
|
for (int i = 0; i < Long.BYTES; i++) {
|
||||||
newData[i] = (byte)((buttonState >> (i * Byte.SIZE)) & 0xFF);
|
newData[i] = (byte) ((buttonState >> (i * Byte.SIZE)) & 0xFF);
|
||||||
}
|
}
|
||||||
//Copy in axis data
|
// Copy in axis data
|
||||||
for (int i = Long.BYTES; i < CONTROLLER_DATA_SIZE; i++) {
|
for (int i = Long.BYTES; i < CONTROLLER_DATA_SIZE; i++) {
|
||||||
newData[i] = axisState[i - Long.BYTES];
|
newData[i] = axisState[i - Long.BYTES];
|
||||||
}
|
}
|
||||||
return newData;
|
return newData;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doSleepAfterPollingData() {
|
|
||||||
//This is event driven (aka pollLatestData() is blocking anyway until we have data), we don't need to sleep it all.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyDriver() {
|
protected void doSleepAfterPollingData() {
|
||||||
try {
|
// This is event driven (aka pollLatestData() is blocking anyway until
|
||||||
|
// we have data), we don't need to sleep it all.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroyDriver() {
|
||||||
|
try {
|
||||||
controller.close();
|
controller.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[" + super.toString() + ";VID," + Integer.toHexString((int)getVID() & 0xFFFF) + ";PID," + Integer.toHexString((int)getPID() & 0xFFFF) + ";run," + isActive() + ((controller == null) ? ";uninitialised]" : ";initialised]");
|
return "[" + super.toString() + ";VID," + Integer.toHexString((int) getVID() & 0xFFFF) + ";PID," + Integer.toHexString((int) getPID() & 0xFFFF)
|
||||||
}
|
+ ";run," + isActive() + ((controller == null) ? ";uninitialised]" : ";initialised]");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInfoText() {
|
public String getInfoText() {
|
||||||
|
@ -36,73 +36,73 @@ import purejavahidapi.InputReportListener;
|
|||||||
public class PureJavaHidController extends Controller implements InputReportListener {
|
public class PureJavaHidController extends Controller implements InputReportListener {
|
||||||
public static Controller getInstance(String deviceIdentifier) throws IOException, ControllerInitializationFailedException {
|
public static Controller getInstance(String deviceIdentifier) throws IOException, ControllerInitializationFailedException {
|
||||||
HidDevice device = PureJavaHidApiManager.getDeviceByPath(deviceIdentifier);
|
HidDevice device = PureJavaHidApiManager.getDeviceByPath(deviceIdentifier);
|
||||||
//We use a special version to optimize the data for the switch pro controller
|
// We use a special version to optimize the data for the switch pro
|
||||||
if(device.getHidDeviceInfo().getVendorId() == SwitchProController.SWITCH_PRO_CONTROLLER_VID &&
|
// controller
|
||||||
device.getHidDeviceInfo().getProductId() == SwitchProController.SWITCH_PRO_CONTROLLER_PID){
|
if (device.getHidDeviceInfo().getVendorId() == SwitchProController.SWITCH_PRO_CONTROLLER_VID
|
||||||
|
&& device.getHidDeviceInfo().getProductId() == SwitchProController.SWITCH_PRO_CONTROLLER_PID) {
|
||||||
return new SwitchProController(deviceIdentifier);
|
return new SwitchProController(deviceIdentifier);
|
||||||
}else if(device.getHidDeviceInfo().getVendorId() == DS4NewController.DS4_NEW_CONTROLLER_VID &&
|
} else if (device.getHidDeviceInfo().getVendorId() == DS4NewController.DS4_NEW_CONTROLLER_VID
|
||||||
device.getHidDeviceInfo().getProductId() == DS4NewController.DS4_NEW_CONTROLLER_PID){
|
&& device.getHidDeviceInfo().getProductId() == DS4NewController.DS4_NEW_CONTROLLER_PID) {
|
||||||
return new DS4NewController(deviceIdentifier);
|
return new DS4NewController(deviceIdentifier);
|
||||||
}else {
|
} else {
|
||||||
return new PureJavaHidController(deviceIdentifier);
|
return new PureJavaHidController(deviceIdentifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PureJavaHidController(String identifier) throws ControllerInitializationFailedException {
|
public PureJavaHidController(String identifier) throws ControllerInitializationFailedException {
|
||||||
super(ControllerType.PureJAVAHid, identifier);
|
super(ControllerType.PureJAVAHid, identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object dataLock = new Object();
|
private Object dataLock = new Object();
|
||||||
protected byte[] currentData = new byte[1];
|
protected byte[] currentData = new byte[1];
|
||||||
|
|
||||||
protected int PACKET_LENGTH = 64;
|
protected int PACKET_LENGTH = 64;
|
||||||
|
|
||||||
@Getter @Setter(AccessLevel.PRIVATE)
|
@Getter @Setter(AccessLevel.PRIVATE) private HidDevice hidDevice;
|
||||||
private HidDevice hidDevice;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean initController(String identifier) {
|
public boolean initController(String identifier) {
|
||||||
HidDevice device;
|
HidDevice device;
|
||||||
try {
|
try {
|
||||||
device = PureJavaHidApiManager.getDeviceByPath(identifier);
|
device = PureJavaHidApiManager.getDeviceByPath(identifier);
|
||||||
|
|
||||||
device.setInputReportListener(this);
|
device.setInputReportListener(this);
|
||||||
setHidDevice(device);
|
setHidDevice(device);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Synchronized("dataLock")
|
@Synchronized("dataLock")
|
||||||
public byte[] pollLatestData() {
|
public byte[] pollLatestData() {
|
||||||
return currentData.clone();
|
return currentData.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyDriver() {
|
public void destroyDriver() {
|
||||||
getHidDevice().close();
|
getHidDevice().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public short getVID() {
|
public short getVID() {
|
||||||
return getHidDevice().getHidDeviceInfo().getVendorId();
|
return getHidDevice().getHidDeviceInfo().getVendorId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public short getPID() {
|
public short getPID() {
|
||||||
return getHidDevice().getHidDeviceInfo().getProductId();
|
return getHidDevice().getHidDeviceInfo().getProductId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Synchronized("dataLock")
|
@Synchronized("dataLock")
|
||||||
public void onInputReport(HidDevice source, byte reportID, byte[] reportData, int reportLength) {
|
public void onInputReport(HidDevice source, byte reportID, byte[] reportData, int reportLength) {
|
||||||
if(isActive()){
|
if (isActive()) {
|
||||||
int length = PACKET_LENGTH;
|
int length = PACKET_LENGTH;
|
||||||
if(reportLength < length){
|
if (reportLength < length) {
|
||||||
length = reportLength;
|
length = reportLength;
|
||||||
}
|
}
|
||||||
currentData = Arrays.copyOfRange(reportData, 0, length);
|
currentData = Arrays.copyOfRange(reportData, 0, length);
|
||||||
@ -111,15 +111,15 @@ public class PureJavaHidController extends Controller implements InputReportList
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInfoText() {
|
public String getInfoText() {
|
||||||
//TODO:
|
// TODO:
|
||||||
if(getVID() == 0x57e){
|
if (getVID() == 0x57e) {
|
||||||
if(getPID() == 0x2006){
|
if (getPID() == 0x2006) {
|
||||||
return "Joy-Con (L) on " + getIdentifier();
|
return "Joy-Con (L) on " + getIdentifier();
|
||||||
}else if(getPID() == 0x2007){
|
} else if (getPID() == 0x2007) {
|
||||||
return "Joy-Con (R) on " + getIdentifier();
|
return "Joy-Con (R) on " + getIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "USB HID on " + getIdentifier();
|
return "USB HID on " + getIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,27 +24,27 @@ package net.ash.HIDToVPADNetworkClient.controller;
|
|||||||
import net.ash.HIDToVPADNetworkClient.exeption.ControllerInitializationFailedException;
|
import net.ash.HIDToVPADNetworkClient.exeption.ControllerInitializationFailedException;
|
||||||
|
|
||||||
public class SwitchProController extends PureJavaHidController {
|
public class SwitchProController extends PureJavaHidController {
|
||||||
public static final short SWITCH_PRO_CONTROLLER_VID = 0x57e;
|
public static final short SWITCH_PRO_CONTROLLER_VID = 0x57e;
|
||||||
public static final short SWITCH_PRO_CONTROLLER_PID = 0x2009;
|
public static final short SWITCH_PRO_CONTROLLER_PID = 0x2009;
|
||||||
|
|
||||||
public SwitchProController(String identifier) throws ControllerInitializationFailedException {
|
public SwitchProController(String identifier) throws ControllerInitializationFailedException {
|
||||||
super(identifier);
|
super(identifier);
|
||||||
//truncate package to 11;
|
// truncate package to 11;
|
||||||
this.PACKET_LENGTH = 11;
|
this.PACKET_LENGTH = 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] pollLatestData() {
|
public byte[] pollLatestData() {
|
||||||
//remove unused data (because only changed data will be sent)
|
// remove unused data (because only changed data will be sent)
|
||||||
currentData[3] = 0;
|
currentData[3] = 0;
|
||||||
currentData[5] = 0;
|
currentData[5] = 0;
|
||||||
currentData[7] = 0;
|
currentData[7] = 0;
|
||||||
currentData[9] = 0;
|
currentData[9] = 0;
|
||||||
return currentData.clone();
|
return currentData.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInfoText(){
|
public String getInfoText() {
|
||||||
return "Switch Pro Controller on " + getIdentifier();
|
return "Switch Pro Controller on " + getIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,9 @@ public class XInput13Controller extends XInputController {
|
|||||||
public XInput13Controller(String identifier) throws ControllerInitializationFailedException {
|
public XInput13Controller(String identifier) throws ControllerInitializationFailedException {
|
||||||
super(ControllerType.XINPUT13, identifier);
|
super(ControllerType.XINPUT13, identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInfoText(){
|
public String getInfoText() {
|
||||||
return "XInput 1.3 on " + getIdentifier();
|
return "XInput 1.3 on " + getIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,9 @@ public class XInput14Controller extends XInputController {
|
|||||||
public XInput14Controller(String identifier) throws ControllerInitializationFailedException {
|
public XInput14Controller(String identifier) throws ControllerInitializationFailedException {
|
||||||
super(ControllerType.XINPUT14, identifier);
|
super(ControllerType.XINPUT14, identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInfoText(){
|
public String getInfoText() {
|
||||||
return "XInput 1.4 on " + getIdentifier();
|
return "XInput 1.4 on " + getIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,15 +36,15 @@ import net.ash.HIDToVPADNetworkClient.exeption.ControllerInitializationFailedExc
|
|||||||
import net.ash.HIDToVPADNetworkClient.util.Utilities;
|
import net.ash.HIDToVPADNetworkClient.util.Utilities;
|
||||||
|
|
||||||
public class XInputController extends Controller {
|
public class XInputController extends Controller {
|
||||||
//the pad number will be appended to this String.
|
// the pad number will be appended to this String.
|
||||||
public static final String XINPUT_INDENTIFER = "\\\\?\\XINPUT\\";
|
public static final String XINPUT_INDENTIFER = "\\\\?\\XINPUT\\";
|
||||||
|
|
||||||
@Getter @Setter(AccessLevel.PRIVATE) private XInputDevice device;
|
@Getter @Setter(AccessLevel.PRIVATE) private XInputDevice device;
|
||||||
|
|
||||||
public XInputController(ControllerType type, String identifier) throws ControllerInitializationFailedException {
|
public XInputController(ControllerType type, String identifier) throws ControllerInitializationFailedException {
|
||||||
super(type, identifier);
|
super(type, identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean initController(String identifier) {
|
public boolean initController(String identifier) {
|
||||||
int pad = Integer.parseInt(identifier.substring(XINPUT_INDENTIFER.length()));
|
int pad = Integer.parseInt(identifier.substring(XINPUT_INDENTIFER.length()));
|
||||||
@ -52,82 +52,82 @@ public class XInputController extends Controller {
|
|||||||
try {
|
try {
|
||||||
device = XInputDevice.getDeviceFor(pad);
|
device = XInputDevice.getDeviceFor(pad);
|
||||||
} catch (XInputNotLoadedException e) {
|
} catch (XInputNotLoadedException e) {
|
||||||
//TODO: Log?
|
// TODO: Log?
|
||||||
}
|
}
|
||||||
if(device == null) return false;
|
if (device == null) return false;
|
||||||
setDevice(device);
|
setDevice(device);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] pollLatestData() {
|
public byte[] pollLatestData() {
|
||||||
if(device.poll()){
|
if (device.poll()) {
|
||||||
ByteBuffer data = ByteBuffer.allocate(8);
|
ByteBuffer data = ByteBuffer.allocate(8);
|
||||||
XInputComponents components = device.getComponents();
|
XInputComponents components = device.getComponents();
|
||||||
|
|
||||||
XInputButtons buttons = components.getButtons();
|
|
||||||
|
|
||||||
int buttonState = 0;
|
|
||||||
if(buttons.a) buttonState |= (1 << 0);
|
|
||||||
if(buttons.b) buttonState |= (1 << 1);
|
|
||||||
if(buttons.x) buttonState |= (1 << 2);
|
|
||||||
if(buttons.y) buttonState |= (1 << 3);
|
|
||||||
|
|
||||||
if(buttons.left) buttonState |= (1 << 4);
|
|
||||||
if(buttons.up) buttonState |= (1 << 5);
|
|
||||||
if(buttons.right) buttonState |= (1 << 6);
|
|
||||||
if(buttons.down) buttonState |= (1 << 7);
|
|
||||||
|
|
||||||
if(buttons.back) buttonState |= (1 << 8);
|
|
||||||
if(buttons.start) buttonState |= (1 << 9);
|
|
||||||
if(buttons.lShoulder) buttonState |= (1 << 10);
|
|
||||||
if(buttons.rShoulder) buttonState |= (1 << 11);
|
|
||||||
if(buttons.lThumb) buttonState |= (1 << 12);
|
|
||||||
if(buttons.rThumb) buttonState |= (1 << 13);
|
|
||||||
if(buttons.unknown) buttonState |= (1 << 14);
|
|
||||||
if (XInputDevice.isGuideButtonSupported()) {
|
|
||||||
if (buttons.guide) buttonState |= (1 << 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
XInputAxes axes = components.getAxes();
|
XInputButtons buttons = components.getButtons();
|
||||||
int axesData = 0;
|
|
||||||
|
int buttonState = 0;
|
||||||
axesData |= Utilities.signedShortToByte(axes.lxRaw) << 24;
|
if (buttons.a) buttonState |= (1 << 0);
|
||||||
axesData |= Utilities.signedShortToByte(axes.lyRaw) << 16;
|
if (buttons.b) buttonState |= (1 << 1);
|
||||||
axesData |= Utilities.signedShortToByte(axes.rxRaw) << 8;
|
if (buttons.x) buttonState |= (1 << 2);
|
||||||
axesData |= Utilities.signedShortToByte(axes.ryRaw) << 0;
|
if (buttons.y) buttonState |= (1 << 3);
|
||||||
|
|
||||||
short axesDataShoulderButtons = 0;
|
if (buttons.left) buttonState |= (1 << 4);
|
||||||
|
if (buttons.up) buttonState |= (1 << 5);
|
||||||
axesDataShoulderButtons |= axes.ltRaw << 8;
|
if (buttons.right) buttonState |= (1 << 6);
|
||||||
axesDataShoulderButtons |= axes.rtRaw << 0;
|
if (buttons.down) buttonState |= (1 << 7);
|
||||||
|
|
||||||
buttonState |= axesDataShoulderButtons << 16;
|
if (buttons.back) buttonState |= (1 << 8);
|
||||||
data.putInt(axesData).putInt(buttonState);
|
if (buttons.start) buttonState |= (1 << 9);
|
||||||
|
if (buttons.lShoulder) buttonState |= (1 << 10);
|
||||||
return(data.array());
|
if (buttons.rShoulder) buttonState |= (1 << 11);
|
||||||
}
|
if (buttons.lThumb) buttonState |= (1 << 12);
|
||||||
return null;
|
if (buttons.rThumb) buttonState |= (1 << 13);
|
||||||
|
if (buttons.unknown) buttonState |= (1 << 14);
|
||||||
|
if (XInputDevice.isGuideButtonSupported()) {
|
||||||
|
if (buttons.guide) buttonState |= (1 << 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
XInputAxes axes = components.getAxes();
|
||||||
|
int axesData = 0;
|
||||||
|
|
||||||
|
axesData |= Utilities.signedShortToByte(axes.lxRaw) << 24;
|
||||||
|
axesData |= Utilities.signedShortToByte(axes.lyRaw) << 16;
|
||||||
|
axesData |= Utilities.signedShortToByte(axes.rxRaw) << 8;
|
||||||
|
axesData |= Utilities.signedShortToByte(axes.ryRaw) << 0;
|
||||||
|
|
||||||
|
short axesDataShoulderButtons = 0;
|
||||||
|
|
||||||
|
axesDataShoulderButtons |= axes.ltRaw << 8;
|
||||||
|
axesDataShoulderButtons |= axes.rtRaw << 0;
|
||||||
|
|
||||||
|
buttonState |= axesDataShoulderButtons << 16;
|
||||||
|
data.putInt(axesData).putInt(buttonState);
|
||||||
|
|
||||||
|
return (data.array());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyDriver() {
|
public void destroyDriver() {
|
||||||
//not needed
|
// not needed
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Other values for VID/PID? I guess other people had this idea too...
|
// TODO: Other values for VID/PID? I guess other people had this idea too...
|
||||||
@Override
|
@Override
|
||||||
public short getVID() {
|
public short getVID() {
|
||||||
return 0x7331;
|
return 0x7331;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public short getPID() {
|
public short getPID() {
|
||||||
return 0x1337;
|
return 0x1337;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInfoText(){
|
public String getInfoText() {
|
||||||
return "XInput on " + getIdentifier();
|
return "XInput on " + getIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,29 +25,37 @@ import java.awt.event.WindowEvent;
|
|||||||
import java.awt.event.WindowListener;
|
import java.awt.event.WindowListener;
|
||||||
|
|
||||||
import net.ash.HIDToVPADNetworkClient.Main;
|
import net.ash.HIDToVPADNetworkClient.Main;
|
||||||
|
import net.ash.HIDToVPADNetworkClient.util.Settings;
|
||||||
|
|
||||||
public class GuiCloseListener implements WindowListener {
|
public class GuiCloseListener implements WindowListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(WindowEvent arg0) {
|
public void windowClosing(WindowEvent arg0) {
|
||||||
|
Settings.saveSettings();
|
||||||
Main.initiateShutdown();
|
Main.initiateShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void windowActivated(WindowEvent arg0) {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowClosed(WindowEvent arg0) {}
|
public void windowActivated(WindowEvent arg0) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowDeactivated(WindowEvent arg0) {}
|
public void windowClosed(WindowEvent arg0) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowDeiconified(WindowEvent arg0) {}
|
public void windowDeactivated(WindowEvent arg0) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowIconified(WindowEvent arg0) {}
|
public void windowDeiconified(WindowEvent arg0) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowOpened(WindowEvent arg0) {}
|
public void windowIconified(WindowEvent arg0) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowOpened(WindowEvent arg0) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,70 +39,71 @@ import net.ash.HIDToVPADNetworkClient.controller.Controller;
|
|||||||
import net.ash.HIDToVPADNetworkClient.manager.ControllerManager;
|
import net.ash.HIDToVPADNetworkClient.manager.ControllerManager;
|
||||||
|
|
||||||
public class GuiControllerList extends JPanel {
|
public class GuiControllerList extends JPanel {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private JPanel innerScrollPanel;
|
private JPanel innerScrollPanel;
|
||||||
|
|
||||||
public GuiControllerList() {
|
public GuiControllerList() {
|
||||||
super(new BorderLayout());
|
super(new BorderLayout());
|
||||||
|
|
||||||
innerScrollPanel = new JPanel();
|
innerScrollPanel = new JPanel();
|
||||||
innerScrollPanel.setLayout(new BoxLayout(innerScrollPanel, BoxLayout.PAGE_AXIS));
|
innerScrollPanel.setLayout(new BoxLayout(innerScrollPanel, BoxLayout.PAGE_AXIS));
|
||||||
add(new JScrollPane(innerScrollPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
|
add(new JScrollPane(innerScrollPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
|
||||||
|
|
||||||
int delay = 1000; //milliseconds
|
int delay = 1000; // milliseconds
|
||||||
ActionListener taskPerformer = new ActionListener() {
|
ActionListener taskPerformer = new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
updateControllerList();
|
updateControllerList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
new Timer(delay, taskPerformer).start();
|
new Timer(delay, taskPerformer).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void updateControllerList() {
|
public synchronized void updateControllerList() {
|
||||||
//System.out.println("[GuiControllerList] Updating controller list..."); //XXX debug text
|
// System.out.println("[GuiControllerList] Updating controller
|
||||||
|
// list..."); //XXX debug text
|
||||||
boolean repaintNeeded = false;
|
|
||||||
|
boolean repaintNeeded = false;
|
||||||
List<Controller> attachedControllers = ControllerManager.getAttachedControllers();
|
|
||||||
|
List<Controller> attachedControllers = ControllerManager.getAttachedControllers();
|
||||||
List<GuiControllerListItem> newComponents = new ArrayList<GuiControllerListItem>();
|
|
||||||
|
List<GuiControllerListItem> newComponents = new ArrayList<GuiControllerListItem>();
|
||||||
Map<Controller,GuiControllerListItem> components = new HashMap<Controller,GuiControllerListItem>();
|
|
||||||
|
Map<Controller, GuiControllerListItem> components = new HashMap<Controller, GuiControllerListItem>();
|
||||||
for (Component component : innerScrollPanel.getComponents()) {
|
for (Component component : innerScrollPanel.getComponents()) {
|
||||||
if (component instanceof GuiControllerListItem) {
|
if (component instanceof GuiControllerListItem) {
|
||||||
GuiControllerListItem comp = (GuiControllerListItem) component;
|
GuiControllerListItem comp = (GuiControllerListItem) component;
|
||||||
Controller cont = comp.getController();
|
Controller cont = comp.getController();
|
||||||
if(attachedControllers.contains(cont)){
|
if (attachedControllers.contains(cont)) {
|
||||||
components.put(cont,comp);
|
components.put(cont, comp);
|
||||||
}else{//Controller removed
|
} else {// Controller removed
|
||||||
repaintNeeded = true;
|
repaintNeeded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Build new list of components.
|
// Build new list of components.
|
||||||
for (Controller controller : attachedControllers) {
|
for (Controller controller : attachedControllers) {
|
||||||
GuiControllerListItem i = null;
|
GuiControllerListItem i = null;
|
||||||
if (components.containsKey(controller)) {
|
if (components.containsKey(controller)) {
|
||||||
newComponents.add(components.get(controller));
|
newComponents.add(components.get(controller));
|
||||||
}else{ //New controller was added
|
} else { // New controller was added
|
||||||
repaintNeeded = true;
|
repaintNeeded = true;
|
||||||
i = new GuiControllerListItem(controller);
|
i = new GuiControllerListItem(controller);
|
||||||
newComponents.add(i);
|
newComponents.add(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(repaintNeeded){
|
if (repaintNeeded) {
|
||||||
innerScrollPanel.removeAll();
|
innerScrollPanel.removeAll();
|
||||||
for (GuiControllerListItem component : newComponents) {
|
for (GuiControllerListItem component : newComponents) {
|
||||||
innerScrollPanel.add(component);
|
innerScrollPanel.add(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
innerScrollPanel.revalidate();
|
innerScrollPanel.revalidate();
|
||||||
revalidate();
|
revalidate();
|
||||||
innerScrollPanel.repaint();
|
innerScrollPanel.repaint();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,26 +35,26 @@ import net.ash.HIDToVPADNetworkClient.controller.Controller;
|
|||||||
import net.ash.HIDToVPADNetworkClient.network.NetworkManager;
|
import net.ash.HIDToVPADNetworkClient.network.NetworkManager;
|
||||||
|
|
||||||
public class GuiControllerListItem extends JPanel implements ActionListener {
|
public class GuiControllerListItem extends JPanel implements ActionListener {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Getter private final Controller controller;
|
|
||||||
private JCheckBox checkbox;
|
|
||||||
|
|
||||||
public GuiControllerListItem(Controller data) {
|
@Getter private final Controller controller;
|
||||||
super(new BorderLayout());
|
private JCheckBox checkbox;
|
||||||
|
|
||||||
setMinimumSize(new Dimension (300, 30));
|
public GuiControllerListItem(Controller data) {
|
||||||
setPreferredSize(new Dimension(300, 30));
|
super(new BorderLayout());
|
||||||
setMaximumSize(new Dimension(2000, 30));
|
|
||||||
|
setMinimumSize(new Dimension(300, 30));
|
||||||
this.controller = data;
|
setPreferredSize(new Dimension(300, 30));
|
||||||
|
setMaximumSize(new Dimension(2000, 30));
|
||||||
checkbox = new JCheckBox(getFlavorText());
|
|
||||||
checkbox.setSelected(data.isActive());
|
this.controller = data;
|
||||||
checkbox.addActionListener(this);
|
|
||||||
add(checkbox);
|
checkbox = new JCheckBox(getFlavorText());
|
||||||
|
checkbox.setSelected(data.isActive());
|
||||||
int delay = 100; //milliseconds
|
checkbox.addActionListener(this);
|
||||||
|
add(checkbox);
|
||||||
|
|
||||||
|
int delay = 100; // milliseconds
|
||||||
ActionListener taskPerformer = new ActionListener() {
|
ActionListener taskPerformer = new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
checkbox.setEnabled(NetworkManager.getInstance().isConnected());
|
checkbox.setEnabled(NetworkManager.getInstance().isConnected());
|
||||||
@ -62,17 +62,17 @@ public class GuiControllerListItem extends JPanel implements ActionListener {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
new Timer(delay, taskPerformer).start();
|
new Timer(delay, taskPerformer).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFlavorText() {
|
private String getFlavorText() {
|
||||||
return controller.getInfoText();
|
return controller.getInfoText();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
boolean selected = ((JCheckBox) e.getSource()).isSelected();
|
boolean selected = ((JCheckBox) e.getSource()).isSelected();
|
||||||
controller.setActive(selected);
|
controller.setActive(selected);
|
||||||
checkbox.setSelected(controller.isActive());
|
checkbox.setSelected(controller.isActive());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -85,18 +85,13 @@ public class GuiControllerListItem extends JPanel implements ActionListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null) return false;
|
||||||
if (obj == null)
|
if (getClass() != obj.getClass()) return false;
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
GuiControllerListItem other = (GuiControllerListItem) obj;
|
GuiControllerListItem other = (GuiControllerListItem) obj;
|
||||||
if (controller == null) {
|
if (controller == null) {
|
||||||
if (other.controller != null)
|
if (other.controller != null) return false;
|
||||||
return false;
|
} else if (!controller.equals(other.controller)) return false;
|
||||||
} else if (!controller.equals(other.controller))
|
|
||||||
return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,112 +39,112 @@ import javax.swing.Timer;
|
|||||||
import net.ash.HIDToVPADNetworkClient.network.NetworkManager;
|
import net.ash.HIDToVPADNetworkClient.network.NetworkManager;
|
||||||
import net.ash.HIDToVPADNetworkClient.util.Settings;
|
import net.ash.HIDToVPADNetworkClient.util.Settings;
|
||||||
|
|
||||||
public class GuiInputControls extends JPanel implements ActionListener {
|
public class GuiInputControls extends JPanel implements ActionListener {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static GuiInputControls instance = null;
|
private static GuiInputControls instance = null;
|
||||||
|
|
||||||
private static final String CONNECT = "Connect";
|
private static final String CONNECT = "Connect";
|
||||||
private static final String DISCONNECT = "Disconnect";
|
private static final String DISCONNECT = "Disconnect";
|
||||||
private static final String RECONNECTING = "Reconnecting";
|
private static final String RECONNECTING = "Reconnecting";
|
||||||
|
|
||||||
private JButton connectButton;
|
|
||||||
private JTextField ipTextBox;
|
|
||||||
private JPanel ipTextBoxWrap;
|
|
||||||
private JTextField packetIntervalTextBox;
|
|
||||||
private JLabel statusLabel;
|
|
||||||
|
|
||||||
public GuiInputControls() throws Exception {
|
|
||||||
super();
|
|
||||||
if (instance != null) {
|
|
||||||
throw new Exception("GuiInputControls already has an instance!");
|
|
||||||
}
|
|
||||||
instance = this;
|
|
||||||
|
|
||||||
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
|
||||||
setPreferredSize(new Dimension(220, 150));
|
|
||||||
|
|
||||||
connectButton = new JButton(CONNECT);
|
|
||||||
connectButton.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
||||||
|
|
||||||
|
|
||||||
ipTextBox = new JTextField();
|
|
||||||
ipTextBox.setColumns(15);
|
|
||||||
ipTextBox.setText(Settings.getIpAddr());
|
|
||||||
ipTextBoxWrap = new JPanel(new FlowLayout());
|
|
||||||
ipTextBoxWrap.add(new JLabel("IP: "));
|
|
||||||
ipTextBoxWrap.add(ipTextBox);
|
|
||||||
ipTextBoxWrap.setMaximumSize(new Dimension(1000, 20));
|
|
||||||
|
|
||||||
statusLabel = new JLabel("Ready.");
|
|
||||||
statusLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
||||||
|
|
||||||
add(Box.createVerticalGlue());
|
|
||||||
|
|
||||||
add(ipTextBoxWrap);
|
private JButton connectButton;
|
||||||
|
private JTextField ipTextBox;
|
||||||
add(Box.createRigidArea(new Dimension(1, 4)));
|
private JPanel ipTextBoxWrap;
|
||||||
add(connectButton);
|
private JTextField packetIntervalTextBox;
|
||||||
add(Box.createRigidArea(new Dimension(1, 8)));
|
private JLabel statusLabel;
|
||||||
|
|
||||||
add(statusLabel);
|
public GuiInputControls() throws Exception {
|
||||||
|
super();
|
||||||
add(Box.createVerticalGlue());
|
if (instance != null) {
|
||||||
|
throw new Exception("GuiInputControls already has an instance!");
|
||||||
connectButton.addActionListener(this);
|
}
|
||||||
|
instance = this;
|
||||||
int delay = 100; //milliseconds
|
|
||||||
|
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
||||||
|
setPreferredSize(new Dimension(220, 150));
|
||||||
|
|
||||||
|
connectButton = new JButton(CONNECT);
|
||||||
|
connectButton.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
|
ipTextBox = new JTextField();
|
||||||
|
ipTextBox.setColumns(15);
|
||||||
|
ipTextBox.setText(Settings.getIpAddr());
|
||||||
|
ipTextBoxWrap = new JPanel(new FlowLayout());
|
||||||
|
ipTextBoxWrap.add(new JLabel("IP: "));
|
||||||
|
ipTextBoxWrap.add(ipTextBox);
|
||||||
|
ipTextBoxWrap.setMaximumSize(new Dimension(1000, 20));
|
||||||
|
|
||||||
|
statusLabel = new JLabel("Ready.");
|
||||||
|
statusLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
|
add(Box.createVerticalGlue());
|
||||||
|
|
||||||
|
add(ipTextBoxWrap);
|
||||||
|
|
||||||
|
add(Box.createRigidArea(new Dimension(1, 4)));
|
||||||
|
add(connectButton);
|
||||||
|
add(Box.createRigidArea(new Dimension(1, 8)));
|
||||||
|
|
||||||
|
add(statusLabel);
|
||||||
|
|
||||||
|
add(Box.createVerticalGlue());
|
||||||
|
|
||||||
|
connectButton.addActionListener(this);
|
||||||
|
|
||||||
|
int delay = 100; // milliseconds
|
||||||
ActionListener taskPerformer = new ActionListener() {
|
ActionListener taskPerformer = new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
if(NetworkManager.getInstance().isReconnecting()){
|
if (NetworkManager.getInstance().isReconnecting()) {
|
||||||
connectButton.setText(RECONNECTING);
|
connectButton.setText(RECONNECTING);
|
||||||
connectButton.setEnabled(false);
|
connectButton.setEnabled(false);
|
||||||
}else if(NetworkManager.getInstance().isConnected()){
|
} else if (NetworkManager.getInstance().isConnected()) {
|
||||||
connectButton.setText(DISCONNECT);
|
connectButton.setText(DISCONNECT);
|
||||||
connectButton.setEnabled(true);
|
connectButton.setEnabled(true);
|
||||||
}else{
|
} else {
|
||||||
connectButton.setText(CONNECT);
|
connectButton.setText(CONNECT);
|
||||||
connectButton.setEnabled(true);
|
connectButton.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
new Timer(delay, taskPerformer).start();
|
new Timer(delay, taskPerformer).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GuiInputControls instance() {
|
public static GuiInputControls instance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JTextField getPacketIntervalTextBox() {
|
public JTextField getPacketIntervalTextBox() {
|
||||||
return packetIntervalTextBox;
|
return packetIntervalTextBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JTextField getIpTextBox() {
|
public JTextField getIpTextBox() {
|
||||||
return ipTextBox;
|
return ipTextBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JButton getConnectButton() {
|
public JButton getConnectButton() {
|
||||||
return connectButton;
|
return connectButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JLabel getStatusLabel() {
|
public JLabel getStatusLabel() {
|
||||||
return statusLabel;
|
return statusLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if(NetworkManager.getInstance().isReconnecting()){
|
Settings.setIpAddr(ipTextBox.getText());
|
||||||
|
if (NetworkManager.getInstance().isReconnecting()) {
|
||||||
}else{
|
|
||||||
if(NetworkManager.getInstance().isConnected()){
|
} else {
|
||||||
|
if (NetworkManager.getInstance().isConnected()) {
|
||||||
NetworkManager.getInstance().disconnect();
|
NetworkManager.getInstance().disconnect();
|
||||||
}else{
|
} else {
|
||||||
NetworkManager.getInstance().connect(ipTextBox.getText());
|
NetworkManager.getInstance().connect(ipTextBox.getText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,42 +31,43 @@ import javax.swing.JPanel;
|
|||||||
import net.ash.HIDToVPADNetworkClient.Main;
|
import net.ash.HIDToVPADNetworkClient.Main;
|
||||||
|
|
||||||
public class GuiMain extends JPanel {
|
public class GuiMain extends JPanel {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static GuiMain instance;
|
private static GuiMain instance;
|
||||||
|
|
||||||
public static void createGUI() {
|
public static void createGUI() {
|
||||||
JFrame frame = new JFrame("HID To VPAD Network Client");
|
JFrame frame = new JFrame("HID To VPAD Network Client");
|
||||||
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||||
frame.addWindowListener(new GuiCloseListener());
|
frame.addWindowListener(new GuiCloseListener());
|
||||||
|
|
||||||
instance = new GuiMain();
|
|
||||||
JComponent newContentPane = instance;
|
|
||||||
newContentPane.setOpaque(true);
|
|
||||||
frame.setContentPane(newContentPane);
|
|
||||||
|
|
||||||
frame.pack();
|
|
||||||
frame.setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private GuiControllerList leftControllerList;
|
instance = new GuiMain();
|
||||||
private GuiInputControls rightSideControls;
|
JComponent newContentPane = instance;
|
||||||
public GuiMain() {
|
newContentPane.setOpaque(true);
|
||||||
super(new BorderLayout());
|
frame.setContentPane(newContentPane);
|
||||||
|
|
||||||
leftControllerList = new GuiControllerList();
|
frame.pack();
|
||||||
leftControllerList.setPreferredSize(new Dimension(300, 100));
|
frame.setVisible(true);
|
||||||
add(leftControllerList, BorderLayout.CENTER);
|
}
|
||||||
|
|
||||||
try {
|
private GuiControllerList leftControllerList;
|
||||||
rightSideControls = new GuiInputControls();
|
private GuiInputControls rightSideControls;
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
public GuiMain() {
|
||||||
Main.fatal();
|
super(new BorderLayout());
|
||||||
}
|
|
||||||
add(rightSideControls, BorderLayout.LINE_END);
|
leftControllerList = new GuiControllerList();
|
||||||
}
|
leftControllerList.setPreferredSize(new Dimension(300, 100));
|
||||||
|
add(leftControllerList, BorderLayout.CENTER);
|
||||||
public static GuiMain instance() {
|
|
||||||
return instance;
|
try {
|
||||||
}
|
rightSideControls = new GuiInputControls();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Main.fatal();
|
||||||
|
}
|
||||||
|
add(rightSideControls, BorderLayout.LINE_END);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GuiMain instance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,72 +35,73 @@ import net.ash.HIDToVPADNetworkClient.util.Settings;
|
|||||||
import net.ash.HIDToVPADNetworkClient.util.Utilities;
|
import net.ash.HIDToVPADNetworkClient.util.Utilities;
|
||||||
|
|
||||||
@Log
|
@Log
|
||||||
public class ActiveControllerManager implements Runnable{
|
public class ActiveControllerManager implements Runnable {
|
||||||
private static ActiveControllerManager instance = new ActiveControllerManager();
|
private static ActiveControllerManager instance = new ActiveControllerManager();
|
||||||
|
|
||||||
private ActiveControllerManager(){
|
private ActiveControllerManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ActiveControllerManager getInstance(){
|
public static ActiveControllerManager getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() { //TODO: Add mechanism to stop these threads?
|
public void run() { // TODO: Add mechanism to stop these threads?
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while(true){
|
while (true) {
|
||||||
updateControllerStates();
|
updateControllerStates();
|
||||||
ControllerManager.detectControllers();
|
ControllerManager.detectControllers();
|
||||||
Utilities.sleep(Settings.getDetectControllerInterval());
|
Utilities.sleep(Settings.DETECT_CONTROLLER_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while(true){
|
while (true) {
|
||||||
handleControllerInputs();
|
handleControllerInputs();
|
||||||
Utilities.sleep(Settings.getHandleInputsInterval());
|
Utilities.sleep(Settings.HANDLE_INPUTS_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Controller,NetworkHIDDevice> activeControllers = new HashMap<Controller,NetworkHIDDevice>();
|
private Map<Controller, NetworkHIDDevice> activeControllers = new HashMap<Controller, NetworkHIDDevice>();
|
||||||
|
|
||||||
public void updateControllerStates() {
|
public void updateControllerStates() {
|
||||||
List<Controller> currentControllers = ControllerManager.getActiveControllers();
|
List<Controller> currentControllers = ControllerManager.getActiveControllers();
|
||||||
|
|
||||||
List<Controller> toAdd = new ArrayList<Controller>();
|
List<Controller> toAdd = new ArrayList<Controller>();
|
||||||
List<Controller> toRemove = new ArrayList<Controller>();
|
List<Controller> toRemove = new ArrayList<Controller>();
|
||||||
synchronized (activeControllers) {
|
synchronized (activeControllers) {
|
||||||
//Adding all missing.
|
// Adding all missing.
|
||||||
|
|
||||||
for(Controller c: currentControllers){
|
for (Controller c : currentControllers) {
|
||||||
if(!activeControllers.containsKey(c)){
|
if (!activeControllers.containsKey(c)) {
|
||||||
log.info("Added " + c);
|
log.info("Added " + c);
|
||||||
toAdd.add(c);
|
toAdd.add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//removing all old
|
// removing all old
|
||||||
for(Controller c : activeControllers.keySet()){
|
for (Controller c : activeControllers.keySet()) {
|
||||||
if(!currentControllers.contains(c)){
|
if (!currentControllers.contains(c)) {
|
||||||
log.info("Removed " + c);
|
log.info("Removed " + c);
|
||||||
toRemove.add(c);
|
toRemove.add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addController(toAdd);
|
addController(toAdd);
|
||||||
removeController(toRemove);
|
removeController(toRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeController(List<Controller> toRemove) {
|
private void removeController(List<Controller> toRemove) {
|
||||||
synchronized (activeControllers) {
|
synchronized (activeControllers) {
|
||||||
for(Controller c : toRemove){
|
for (Controller c : toRemove) {
|
||||||
NetworkManager.getInstance().removeHIDDevice(activeControllers.get(c));
|
NetworkManager.getInstance().removeHIDDevice(activeControllers.get(c));
|
||||||
c.destroyDriver();
|
c.destroyDriver();
|
||||||
activeControllers.remove(c);
|
activeControllers.remove(c);
|
||||||
@ -110,44 +111,44 @@ public class ActiveControllerManager implements Runnable{
|
|||||||
|
|
||||||
private void addController(List<Controller> toAdd) {
|
private void addController(List<Controller> toAdd) {
|
||||||
synchronized (activeControllers) {
|
synchronized (activeControllers) {
|
||||||
for(Controller c : toAdd){
|
for (Controller c : toAdd) {
|
||||||
NetworkHIDDevice hiddevice = new NetworkHIDDevice(c.getVID(), c.getPID());
|
NetworkHIDDevice hiddevice = new NetworkHIDDevice(c.getVID(), c.getPID());
|
||||||
hiddevice.sendAttach();
|
hiddevice.sendAttach();
|
||||||
NetworkManager.getInstance().addHIDDevice(hiddevice);
|
NetworkManager.getInstance().addHIDDevice(hiddevice);
|
||||||
activeControllers.put(c,hiddevice);
|
activeControllers.put(c, hiddevice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleControllerInputs() {
|
private void handleControllerInputs() {
|
||||||
synchronized (activeControllers) {
|
synchronized (activeControllers) {
|
||||||
for(Entry<Controller, NetworkHIDDevice> entry : activeControllers.entrySet()){
|
for (Entry<Controller, NetworkHIDDevice> entry : activeControllers.entrySet()) {
|
||||||
byte[] data = entry.getKey().getLatestData();
|
byte[] data = entry.getKey().getLatestData();
|
||||||
if(data != null){
|
if (data != null) {
|
||||||
NetworkHIDDevice device = entry.getValue();
|
NetworkHIDDevice device = entry.getValue();
|
||||||
device.sendRead(data);
|
device.sendRead(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void attachAllActiveControllers() {
|
public void attachAllActiveControllers() {
|
||||||
synchronized (activeControllers) {
|
synchronized (activeControllers) {
|
||||||
for(Entry<Controller, NetworkHIDDevice> entry : activeControllers.entrySet()){
|
for (Entry<Controller, NetworkHIDDevice> entry : activeControllers.entrySet()) {
|
||||||
NetworkHIDDevice device = entry.getValue();
|
NetworkHIDDevice device = entry.getValue();
|
||||||
device.sendAttach();
|
device.sendAttach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param HIDhandle
|
* @param HIDhandle
|
||||||
* @return returns the controller for the given handle. returns null if the controller with the given handle is not found.
|
* @return returns the controller for the given handle. returns null if the controller with the given handle is not found.
|
||||||
*/
|
*/
|
||||||
public Controller getControllerByHIDHandle(int HIDhandle) {
|
public Controller getControllerByHIDHandle(int HIDhandle) {
|
||||||
for(Entry<Controller, NetworkHIDDevice> entry: activeControllers.entrySet()){
|
for (Entry<Controller, NetworkHIDDevice> entry : activeControllers.entrySet()) {
|
||||||
if(entry.getValue().getHidHandle() == HIDhandle){
|
if (entry.getValue().getHidHandle() == HIDhandle) {
|
||||||
return entry.getKey();
|
return entry.getKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,154 +37,133 @@ import com.ivan.xinput.exceptions.XInputNotLoadedException;
|
|||||||
import lombok.Synchronized;
|
import lombok.Synchronized;
|
||||||
import net.ash.HIDToVPADNetworkClient.controller.Controller;
|
import net.ash.HIDToVPADNetworkClient.controller.Controller;
|
||||||
import net.ash.HIDToVPADNetworkClient.controller.Controller.ControllerType;
|
import net.ash.HIDToVPADNetworkClient.controller.Controller.ControllerType;
|
||||||
import net.ash.HIDToVPADNetworkClient.controller.PureJavaHidController;
|
|
||||||
import net.ash.HIDToVPADNetworkClient.controller.LinuxDevInputController;
|
import net.ash.HIDToVPADNetworkClient.controller.LinuxDevInputController;
|
||||||
|
import net.ash.HIDToVPADNetworkClient.controller.PureJavaHidController;
|
||||||
import net.ash.HIDToVPADNetworkClient.controller.XInput13Controller;
|
import net.ash.HIDToVPADNetworkClient.controller.XInput13Controller;
|
||||||
import net.ash.HIDToVPADNetworkClient.controller.XInput14Controller;
|
import net.ash.HIDToVPADNetworkClient.controller.XInput14Controller;
|
||||||
import net.ash.HIDToVPADNetworkClient.controller.XInputController;
|
import net.ash.HIDToVPADNetworkClient.controller.XInputController;
|
||||||
import net.ash.HIDToVPADNetworkClient.exeption.ControllerInitializationFailedException;
|
import net.ash.HIDToVPADNetworkClient.exeption.ControllerInitializationFailedException;
|
||||||
import net.ash.HIDToVPADNetworkClient.util.PureJavaHidApiManager;
|
import net.ash.HIDToVPADNetworkClient.util.PureJavaHidApiManager;
|
||||||
|
import net.ash.HIDToVPADNetworkClient.util.Settings;
|
||||||
import purejavahidapi.HidDeviceInfo;
|
import purejavahidapi.HidDeviceInfo;
|
||||||
import purejavahidapi.PureJavaHidApi;
|
|
||||||
|
|
||||||
public class ControllerManager{
|
public class ControllerManager {
|
||||||
private static Map<String,Controller> attachedControllers = new HashMap<String,Controller>();
|
private static Map<String, Controller> attachedControllers = new HashMap<String, Controller>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detects all attached controller.
|
* Detects all attached controller.
|
||||||
*/
|
*/
|
||||||
@Synchronized("attachedControllers")
|
@Synchronized("attachedControllers")
|
||||||
public static void detectControllers() {
|
public static void detectControllers() {
|
||||||
String os = System.getProperty("os.name");
|
Map<String, ControllerType> connectedDevices = new HashMap<String, ControllerType>();
|
||||||
//System.out.println("[ControllerDetector] OS: " + os);
|
|
||||||
|
if (Settings.isLinux()) {
|
||||||
Map<String,ControllerType> connectedDevices = new HashMap<String,ControllerType>();
|
|
||||||
|
|
||||||
if (os.contains("Linux")) {
|
|
||||||
connectedDevices.putAll(detectLinuxControllers());
|
connectedDevices.putAll(detectLinuxControllers());
|
||||||
} else if (os.contains("Windows")) {
|
} else if (Settings.isWindows()) {
|
||||||
connectedDevices.putAll(detectWindowsControllers());
|
connectedDevices.putAll(detectWindowsControllers());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (os.contains("Mac OS X")) {
|
connectedDevices.putAll(detectHIDDevices());
|
||||||
connectedDevices.putAll(detectOSXHIDDevices());
|
|
||||||
PureJavaHidApiManager.MAC_OS_X = true;
|
// Remove detached devices
|
||||||
} else {
|
|
||||||
connectedDevices.putAll(detectHIDDevices());
|
|
||||||
PureJavaHidApiManager.MAC_OS_X = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Remove detached devices
|
|
||||||
List<String> toRemove = new ArrayList<String>();
|
List<String> toRemove = new ArrayList<String>();
|
||||||
for(String s : attachedControllers.keySet()){
|
for (String s : attachedControllers.keySet()) {
|
||||||
if(!connectedDevices.containsKey(s)){
|
if (!connectedDevices.containsKey(s)) {
|
||||||
toRemove.add(s);
|
toRemove.add(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(String remove : toRemove){
|
for (String remove : toRemove) {
|
||||||
attachedControllers.get(remove).destroyAll();
|
attachedControllers.get(remove).destroyAll();
|
||||||
attachedControllers.remove(remove);
|
attachedControllers.remove(remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add attached devices!
|
// Add attached devices!
|
||||||
for(Entry<String, ControllerType> entry : connectedDevices.entrySet()){
|
for (Entry<String, ControllerType> entry : connectedDevices.entrySet()) {
|
||||||
String deviceIdentifier = entry.getKey();
|
String deviceIdentifier = entry.getKey();
|
||||||
if(!attachedControllers.containsKey(deviceIdentifier)){
|
if (!attachedControllers.containsKey(deviceIdentifier)) {
|
||||||
Controller c = null;
|
Controller c = null;
|
||||||
switch(entry.getValue()){
|
switch (entry.getValue()) {
|
||||||
case PureJAVAHid:
|
case PureJAVAHid:
|
||||||
try {
|
try {
|
||||||
c= PureJavaHidController.getInstance(deviceIdentifier);
|
c = PureJavaHidController.getInstance(deviceIdentifier);
|
||||||
} catch (ControllerInitializationFailedException e) {
|
} catch (ControllerInitializationFailedException e) {
|
||||||
//e.printStackTrace();
|
// e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LINUX:
|
case LINUX:
|
||||||
try {
|
try {
|
||||||
c = new LinuxDevInputController(deviceIdentifier);
|
c = new LinuxDevInputController(deviceIdentifier);
|
||||||
} catch (ControllerInitializationFailedException e) {
|
} catch (ControllerInitializationFailedException e) {
|
||||||
//e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/*
|
/*
|
||||||
* TODO:
|
* TODO: Currently the XInput will be set active automatically. But this should move to something for the settings?
|
||||||
* Currently the XInput will be set active automatically.
|
*/
|
||||||
* But this should move to something for the settings?
|
case XINPUT14:
|
||||||
*/
|
try {
|
||||||
case XINPUT14:
|
c = new XInput14Controller(deviceIdentifier);
|
||||||
try {
|
c.setActive(true);
|
||||||
c = new XInput14Controller(deviceIdentifier);
|
} catch (ControllerInitializationFailedException e) {
|
||||||
c.setActive(true);
|
// e.printStackTrace();
|
||||||
} catch (ControllerInitializationFailedException e) {
|
}
|
||||||
//e.printStackTrace();
|
break;
|
||||||
}
|
case XINPUT13:
|
||||||
break;
|
try {
|
||||||
case XINPUT13:
|
c = new XInput13Controller(deviceIdentifier);
|
||||||
try {
|
c.setActive(true);
|
||||||
c = new XInput13Controller(deviceIdentifier);
|
} catch (ControllerInitializationFailedException e) {
|
||||||
c.setActive(true);
|
// e.printStackTrace();
|
||||||
} catch (ControllerInitializationFailedException e) {
|
}
|
||||||
//e.printStackTrace();
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(c != null){ //I don't like that starting the Thread happens here =/
|
if (c != null) { // I don't like that starting the Thread
|
||||||
|
// happens here =/
|
||||||
new Thread(c).start();
|
new Thread(c).start();
|
||||||
attachedControllers.put(deviceIdentifier,c);
|
attachedControllers.put(deviceIdentifier, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized("attachedControllers")
|
@Synchronized("attachedControllers")
|
||||||
public static List<Controller> getAttachedControllers() {
|
public static List<Controller> getAttachedControllers() {
|
||||||
return new ArrayList<Controller>(attachedControllers.values());
|
return new ArrayList<Controller>(attachedControllers.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, ControllerType> detectHIDDevices() {
|
private static Map<String, ControllerType> detectHIDDevices() {
|
||||||
Map<String,ControllerType> connectedDevices = new HashMap<String,ControllerType>();
|
Map<String, ControllerType> connectedDevices = new HashMap<String, ControllerType>();
|
||||||
|
|
||||||
for (HidDeviceInfo info : PureJavaHidApi.enumerateDevices()) {
|
for (HidDeviceInfo info : PureJavaHidApiManager.getAttachedController()) {
|
||||||
if(info.getUsagePage() == 0x05 || info.getUsagePage() == 0x04 || (info.getVendorId() == 0x57e) || (info.getVendorId() == 0x054c) ){
|
String path = info.getPath();
|
||||||
connectedDevices.put(info.getPath(),ControllerType.PureJAVAHid);
|
|
||||||
}
|
if (Settings.isMacOSX()) path = path.substring(0, 13);
|
||||||
|
connectedDevices.put(path, ControllerType.PureJAVAHid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return connectedDevices;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Map<String, ControllerType> detectOSXHIDDevices() {
|
|
||||||
Map<String,ControllerType> connectedDevices = new HashMap<String,ControllerType>();
|
|
||||||
|
|
||||||
for (HidDeviceInfo info : PureJavaHidApi.enumerateDevices()) {
|
|
||||||
if(info.getUsagePage() == 0x05 || info.getUsagePage() == 0x04 || (info.getVendorId() == 0x57e) || (info.getVendorId() == 0x054c) ){
|
|
||||||
connectedDevices.put(info.getPath().substring(0, 13),ControllerType.PureJAVAHid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return connectedDevices;
|
return connectedDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, ControllerType> detectWindowsControllers() {
|
private static Map<String, ControllerType> detectWindowsControllers() {
|
||||||
Map<String,ControllerType> result = new HashMap<String,ControllerType>();
|
Map<String, ControllerType> result = new HashMap<String, ControllerType>();
|
||||||
ControllerType type = ControllerType.XINPUT13;
|
ControllerType type = ControllerType.XINPUT13;
|
||||||
if(XInputDevice.isAvailable() || XInputDevice14.isAvailable()) {
|
if (XInputDevice.isAvailable() || XInputDevice14.isAvailable()) {
|
||||||
if(XInputDevice14.isAvailable()){
|
if (XInputDevice14.isAvailable()) {
|
||||||
type = ControllerType.XINPUT14;
|
type = ControllerType.XINPUT14;
|
||||||
}
|
}
|
||||||
for(int i =0;i<4;i++){
|
for (int i = 0; i < 4; i++) {
|
||||||
XInputDevice device;
|
XInputDevice device;
|
||||||
try {
|
try {
|
||||||
device = XInputDevice.getDeviceFor(i);
|
device = XInputDevice.getDeviceFor(i);
|
||||||
if(device.poll() && device.isConnected()){ //Check if it is this controller is connected
|
if (device.poll() && device.isConnected()) { // Check if it is this controller is connected
|
||||||
result.put(XInputController.XINPUT_INDENTIFER + i, type);
|
result.put(XInputController.XINPUT_INDENTIFER + i, type);
|
||||||
}
|
}
|
||||||
} catch (XInputNotLoadedException e) {
|
} catch (XInputNotLoadedException e) {
|
||||||
//This shouln't happen?
|
// This shouln't happen?
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,28 +173,28 @@ public class ControllerManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, ControllerType> detectLinuxControllers() {
|
private static Map<String, ControllerType> detectLinuxControllers() {
|
||||||
Map<String,ControllerType> result = new HashMap<String,ControllerType>();
|
Map<String, ControllerType> result = new HashMap<String, ControllerType>();
|
||||||
File devInput = new File("/dev/input");
|
File devInput = new File("/dev/input");
|
||||||
if (!devInput.exists()) return result;
|
if (!devInput.exists()) return result;
|
||||||
|
|
||||||
File[] linuxControllers = devInput.listFiles(new FilenameFilter() {
|
File[] linuxControllers = devInput.listFiles(new FilenameFilter() {
|
||||||
public boolean accept(File dir, String name) {
|
public boolean accept(File dir, String name) {
|
||||||
return name.startsWith("js"); //js0, js1, etc...
|
return name.startsWith("js"); // js0, js1, etc...
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (File controller : linuxControllers) {
|
for (File controller : linuxControllers) {
|
||||||
result.put(controller.getAbsolutePath(),ControllerType.LINUX);
|
result.put(controller.getAbsolutePath(), ControllerType.LINUX);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized("attachedControllers")
|
@Synchronized("attachedControllers")
|
||||||
public static List<Controller> getActiveControllers() {
|
public static List<Controller> getActiveControllers() {
|
||||||
List<Controller> active = new ArrayList<Controller>();
|
List<Controller> active = new ArrayList<Controller>();
|
||||||
for(Controller c : attachedControllers.values()){
|
for (Controller c : attachedControllers.values()) {
|
||||||
if(c.isActive()){
|
if (c.isActive()) {
|
||||||
active.add(c);
|
active.add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -224,7 +203,7 @@ public class ControllerManager{
|
|||||||
|
|
||||||
@Synchronized("attachedControllers")
|
@Synchronized("attachedControllers")
|
||||||
public static void deactivateAllAttachedControllers() {
|
public static void deactivateAllAttachedControllers() {
|
||||||
for(Controller c : attachedControllers.values()){
|
for (Controller c : attachedControllers.values()) {
|
||||||
c.setActive(false);
|
c.setActive(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,66 +35,66 @@ import net.ash.HIDToVPADNetworkClient.network.commands.DetachCommand;
|
|||||||
import net.ash.HIDToVPADNetworkClient.network.commands.DeviceCommand;
|
import net.ash.HIDToVPADNetworkClient.network.commands.DeviceCommand;
|
||||||
import net.ash.HIDToVPADNetworkClient.network.commands.ReadCommand;
|
import net.ash.HIDToVPADNetworkClient.network.commands.ReadCommand;
|
||||||
import net.ash.HIDToVPADNetworkClient.util.HandleFoundry;
|
import net.ash.HIDToVPADNetworkClient.util.HandleFoundry;
|
||||||
import net.ash.HIDToVPADNetworkClient.util.Utilities;
|
|
||||||
|
|
||||||
public class NetworkHIDDevice {
|
public class NetworkHIDDevice {
|
||||||
@Getter private final short vid;
|
@Getter private final short vid;
|
||||||
@Getter private final short pid;
|
@Getter private final short pid;
|
||||||
|
|
||||||
@Getter @Setter private short deviceslot;
|
@Getter @Setter private short deviceslot;
|
||||||
@Getter @Setter private byte padslot;
|
@Getter @Setter private byte padslot;
|
||||||
|
|
||||||
@Getter private int hidHandle = HandleFoundry.next();
|
@Getter private int hidHandle = HandleFoundry.next();
|
||||||
@Getter(AccessLevel.PRIVATE) private List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
|
@Getter(AccessLevel.PRIVATE) private List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
|
||||||
|
|
||||||
@Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) private ReadCommand latestRead;
|
@Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) private ReadCommand latestRead;
|
||||||
|
|
||||||
private Object readCommandLock = new Object();
|
private Object readCommandLock = new Object();
|
||||||
|
|
||||||
public NetworkHIDDevice(short vid, short pid){
|
public NetworkHIDDevice(short vid, short pid) {
|
||||||
this.vid = vid;
|
this.vid = vid;
|
||||||
this.pid = pid;
|
this.pid = pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCommand(DeviceCommand command){
|
private void addCommand(DeviceCommand command) {
|
||||||
this.commands.add(command);
|
this.commands.add(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearCommands(){
|
private void clearCommands() {
|
||||||
this.commands.clear();
|
this.commands.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendAttach(){
|
public void sendAttach() {
|
||||||
addCommand(new AttachCommand(getHidHandle(), getVid(), getPid(),this));
|
addCommand(new AttachCommand(getHidHandle(), getVid(), getPid(), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendDetach(){
|
public void sendDetach() {
|
||||||
addCommand(new DetachCommand(getHidHandle(),this));
|
addCommand(new DetachCommand(getHidHandle(), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] lastdata = null;
|
private byte[] lastdata = null;
|
||||||
public void sendRead(byte[] data){
|
|
||||||
if(!Arrays.equals(lastdata, data)){
|
public void sendRead(byte[] data) {
|
||||||
|
if (!Arrays.equals(lastdata, data)) {
|
||||||
synchronized (readCommandLock) {
|
synchronized (readCommandLock) {
|
||||||
setLatestRead(new ReadCommand(getHidHandle(),data, this)); //Only get the latest Value.
|
setLatestRead(new ReadCommand(getHidHandle(), data, this)); // Only get the latest Value.
|
||||||
}
|
}
|
||||||
lastdata = data.clone();
|
lastdata = data.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<? extends DeviceCommand> getCommandList() {
|
public Collection<? extends DeviceCommand> getCommandList() {
|
||||||
List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
|
List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
|
||||||
commands.addAll(getCommands());
|
commands.addAll(getCommands());
|
||||||
DeviceCommand lastRead;
|
DeviceCommand lastRead;
|
||||||
|
|
||||||
synchronized (readCommandLock) {
|
synchronized (readCommandLock) {
|
||||||
if((lastRead = getLatestRead()) != null){
|
if ((lastRead = getLatestRead()) != null) {
|
||||||
commands.add(lastRead);
|
commands.add(lastRead);
|
||||||
setLatestRead(null);
|
setLatestRead(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCommands();
|
clearCommands();
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,15 +108,11 @@ public class NetworkHIDDevice {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) return true;
|
||||||
return true;
|
if (obj == null) return false;
|
||||||
if (obj == null)
|
if (getClass() != obj.getClass()) return false;
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
NetworkHIDDevice other = (NetworkHIDDevice) obj;
|
NetworkHIDDevice other = (NetworkHIDDevice) obj;
|
||||||
if (hidHandle != other.hidHandle)
|
if (hidHandle != other.hidHandle) return false;
|
||||||
return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package net.ash.HIDToVPADNetworkClient.network;
|
package net.ash.HIDToVPADNetworkClient.network;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -37,39 +38,40 @@ import net.ash.HIDToVPADNetworkClient.util.Settings;
|
|||||||
import net.ash.HIDToVPADNetworkClient.util.Utilities;
|
import net.ash.HIDToVPADNetworkClient.util.Utilities;
|
||||||
|
|
||||||
@Log
|
@Log
|
||||||
public class NetworkManager implements Runnable{
|
public class NetworkManager implements Runnable {
|
||||||
private final TCPClient tcpClient = new TCPClient();
|
private final TCPClient tcpClient = new TCPClient();
|
||||||
private UDPClient udpClient = null;
|
private UDPClient udpClient = null;
|
||||||
|
|
||||||
private static NetworkManager instance = null;
|
private static NetworkManager instance = null;
|
||||||
|
|
||||||
private List<DeviceCommand> ownCommands = new ArrayList<DeviceCommand>();
|
private List<DeviceCommand> ownCommands = new ArrayList<DeviceCommand>();
|
||||||
|
|
||||||
private NetworkManager() {
|
private NetworkManager() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NetworkManager getInstance(){
|
public static NetworkManager getInstance() {
|
||||||
if(instance == null){
|
if (instance == null) {
|
||||||
instance = new NetworkManager();
|
instance = new NetworkManager();
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter private List<NetworkHIDDevice> devices = new ArrayList<NetworkHIDDevice>();
|
@Getter private List<NetworkHIDDevice> devices = new ArrayList<NetworkHIDDevice>();
|
||||||
|
|
||||||
public void addHIDDevice(NetworkHIDDevice device){
|
public void addHIDDevice(NetworkHIDDevice device) {
|
||||||
if(!getDevices().contains(device)){
|
if (!getDevices().contains(device)) {
|
||||||
synchronized (devices) {
|
synchronized (devices) {
|
||||||
getDevices().add(device);
|
getDevices().add(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We want to remove them at the end of a cycle. To make sure the detach was send before removing.
|
* We want to remove them at the end of a cycle. To make sure the detach was send before removing.
|
||||||
*/
|
*/
|
||||||
@Getter private List<NetworkHIDDevice> toRemove = new ArrayList<NetworkHIDDevice>();
|
@Getter private List<NetworkHIDDevice> toRemove = new ArrayList<NetworkHIDDevice>();
|
||||||
|
|
||||||
@Synchronized("toRemove")
|
@Synchronized("toRemove")
|
||||||
public void removeHIDDevice(NetworkHIDDevice device) {
|
public void removeHIDDevice(NetworkHIDDevice device) {
|
||||||
device.sendDetach();
|
device.sendDetach();
|
||||||
@ -79,10 +81,10 @@ public class NetworkManager implements Runnable{
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(true){
|
while (true) {
|
||||||
proccessCommands();
|
proccessCommands();
|
||||||
Utilities.sleep(Settings.getProcessCmdInterval());
|
Utilities.sleep(Settings.PROCESS_CMD_INTERVAL);
|
||||||
if(i++ > Settings.getPingInterval() / Settings.getProcessCmdInterval()){
|
if (i++ > Settings.PING_INTERVAL / Settings.PROCESS_CMD_INTERVAL) {
|
||||||
ping();
|
ping();
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
@ -90,82 +92,84 @@ public class NetworkManager implements Runnable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void ping() {
|
private void ping() {
|
||||||
if(isConnected() || tcpClient.isShouldRetry())sendingCommand(new PingCommand());
|
if (isConnected() || tcpClient.isShouldRetry()) sendingCommand(new PingCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void proccessCommands(){
|
public void proccessCommands() {
|
||||||
List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
|
List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
|
||||||
commands.addAll(ownCommands); //TODO: Does this need a synchronized block? It _should_ be only access from this thread. Need to think about it
|
commands.addAll(ownCommands); // TODO: Does this need a synchronized
|
||||||
|
// block? It _should_ be only access from
|
||||||
|
// this thread. Need to think about it
|
||||||
ownCommands.clear();
|
ownCommands.clear();
|
||||||
synchronized (toRemove) {
|
synchronized (toRemove) {
|
||||||
synchronized (devices) {
|
synchronized (devices) {
|
||||||
for(NetworkHIDDevice device : getDevices()){
|
for (NetworkHIDDevice device : getDevices()) {
|
||||||
commands.addAll(device.getCommandList());
|
commands.addAll(device.getCommandList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(commands.isEmpty())return;
|
if (commands.isEmpty()) return;
|
||||||
|
|
||||||
//Split up into "read commands" and other commands.
|
// Split up into "read commands" and other commands.
|
||||||
List<ReadCommand> readCommands = new ArrayList<ReadCommand>();
|
List<ReadCommand> readCommands = new ArrayList<ReadCommand>();
|
||||||
{
|
{
|
||||||
for(DeviceCommand command : commands){
|
for (DeviceCommand command : commands) {
|
||||||
if(command instanceof ReadCommand){
|
if (command instanceof ReadCommand) {
|
||||||
readCommands.add((ReadCommand) command);
|
readCommands.add((ReadCommand) command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commands.removeAll(readCommands);
|
commands.removeAll(readCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!readCommands.isEmpty()){
|
if (!readCommands.isEmpty()) {
|
||||||
sendingRead(readCommands);
|
sendingRead(readCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!commands.isEmpty()){
|
if (!commands.isEmpty()) {
|
||||||
for(DeviceCommand command : commands){
|
for (DeviceCommand command : commands) {
|
||||||
sendingCommand(command);
|
sendingCommand(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (toRemove) {
|
synchronized (toRemove) {
|
||||||
synchronized (devices) {
|
synchronized (devices) {
|
||||||
for(NetworkHIDDevice d: toRemove){
|
for (NetworkHIDDevice d : toRemove) {
|
||||||
commands.remove(d);
|
commands.remove(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendingCommand(DeviceCommand command) {
|
private void sendingCommand(DeviceCommand command) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if(isConnected() || tcpClient.isShouldRetry()){
|
if (isConnected() || tcpClient.isShouldRetry()) {
|
||||||
if(command instanceof AttachCommand){
|
if (command instanceof AttachCommand) {
|
||||||
result = sendAttach((AttachCommand) command);
|
result = sendAttach((AttachCommand) command);
|
||||||
}else if(command instanceof DetachCommand){
|
} else if (command instanceof DetachCommand) {
|
||||||
result = sendDetach((DetachCommand) command);
|
result = sendDetach((DetachCommand) command);
|
||||||
}else if(command instanceof PingCommand){
|
} else if (command instanceof PingCommand) {
|
||||||
sendPing((PingCommand) command);
|
sendPing((PingCommand) command);
|
||||||
result = true;
|
result = true;
|
||||||
}else{
|
} else {
|
||||||
log.info("UNKNOWN COMMAND!");
|
log.info("UNKNOWN COMMAND!");
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
Utilities.sleep(Settings.getSendingCmdSleepIfNotConnected());
|
Utilities.sleep(Settings.SENDING_CMD_SLEEP_IF_NOT_CONNECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add the command again on errors
|
// Add the command again on errors
|
||||||
if(!result){
|
if (!result) {
|
||||||
addCommand(command);
|
addCommand(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: PONG from WiiU? Hey Quark ;)
|
// TODO: PONG from WiiU? Hey Quark ;)
|
||||||
private void sendPing(PingCommand command) {
|
private void sendPing(PingCommand command) {
|
||||||
if(sendTCP(Protocol.getRawPingDataToSend(command))){
|
if (sendTCP(Protocol.getRawPingDataToSend(command))) {
|
||||||
log.info("PING");
|
log.info("PING");
|
||||||
}else{
|
} else {
|
||||||
log.info("Sending the PING failed");
|
log.info("Sending the PING failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,65 +178,65 @@ public class NetworkManager implements Runnable{
|
|||||||
byte[] sendData;
|
byte[] sendData;
|
||||||
try {
|
try {
|
||||||
sendData = Protocol.getRawDetachDataToSend(command);
|
sendData = Protocol.getRawDetachDataToSend(command);
|
||||||
if(sendTCP(sendData)){
|
if (sendTCP(sendData)) {
|
||||||
log.info("Success detach command for device (" + command.getSender() + ") sent!");
|
log.info("Success detach command for device (" + command.getSender() + ") sent!");
|
||||||
}else{
|
} else {
|
||||||
log.info("Sending the detach command for device (" + command.getSender() + ") failed. sendTCP failed");
|
log.info("Sending the detach command for device (" + command.getSender() + ") failed. sendTCP failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Maybe move it into the Protocol class?
|
// TODO: Maybe move it into the Protocol class?
|
||||||
private boolean sendAttach(AttachCommand command) {
|
private boolean sendAttach(AttachCommand command) {
|
||||||
//Send the TCP command
|
// Send the TCP command
|
||||||
byte[] sendData = null;
|
byte[] sendData = null;
|
||||||
try {
|
try {
|
||||||
sendData = Protocol.getRawAttachDataToSend(command);
|
sendData = Protocol.getRawAttachDataToSend(command);
|
||||||
}catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.info("Building the attach command for device (" + command.getSender() + ") failed." + e.getMessage());
|
log.info("Building the attach command for device (" + command.getSender() + ") failed." + e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(sendTCP(sendData)){
|
if (sendTCP(sendData)) {
|
||||||
byte configFound = 0;
|
byte configFound = 0;
|
||||||
try {
|
try {
|
||||||
configFound = recvTCPByte();
|
configFound = recvTCPByte();
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
if(configFound == Protocol.TCP_CMD_ATTACH_CONFIG_FOUND){
|
if (configFound == Protocol.TCP_CMD_ATTACH_CONFIG_FOUND) {
|
||||||
//log.info("Config on the console found!");
|
// log.info("Config on the console found!");
|
||||||
}else if(configFound == Protocol.TCP_CMD_ATTACH_CONFIG_NOT_FOUND){
|
} else if (configFound == Protocol.TCP_CMD_ATTACH_CONFIG_NOT_FOUND) {
|
||||||
log.info("NO CONFIG FOUND.");
|
log.info("NO CONFIG FOUND.");
|
||||||
return false;
|
return false;
|
||||||
}else if (configFound == 0){
|
} else if (configFound == 0) {
|
||||||
log.info("Failed to get byte.");
|
log.info("Failed to get byte.");
|
||||||
disconnect();
|
disconnect();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte userDataOkay = 0;
|
byte userDataOkay = 0;
|
||||||
try {
|
try {
|
||||||
userDataOkay = recvTCPByte();
|
userDataOkay = recvTCPByte();
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
if(userDataOkay == Protocol.TCP_CMD_ATTACH_USERDATA_OKAY){
|
if (userDataOkay == Protocol.TCP_CMD_ATTACH_USERDATA_OKAY) {
|
||||||
//log.info("userdata okay!");
|
// log.info("userdata okay!");
|
||||||
}else if(userDataOkay == Protocol.TCP_CMD_ATTACH_USERDATA_BAD){
|
} else if (userDataOkay == Protocol.TCP_CMD_ATTACH_USERDATA_BAD) {
|
||||||
log.info("USERDATA BAD.");
|
log.info("USERDATA BAD.");
|
||||||
return false;
|
return false;
|
||||||
}else if (userDataOkay == 0){
|
} else if (userDataOkay == 0) {
|
||||||
log.info("Failed to get byte.");
|
log.info("Failed to get byte.");
|
||||||
disconnect();
|
disconnect();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//We receive our device slot and pad slot
|
// We receive our device slot and pad slot
|
||||||
short deviceslot = -1;
|
short deviceslot = -1;
|
||||||
byte padslot = -1;
|
byte padslot = -1;
|
||||||
try {
|
try {
|
||||||
@ -242,45 +246,45 @@ public class NetworkManager implements Runnable{
|
|||||||
log.info("Recieving data after sending a attach failed for device (" + command.getSender() + ") failed." + e.getMessage());
|
log.info("Recieving data after sending a attach failed for device (" + command.getSender() + ") failed." + e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deviceslot < 0 || padslot < 0){
|
if (deviceslot < 0 || padslot < 0) {
|
||||||
log.info("Recieving data after sending a attach failed for device (" + command.getSender() + ") failed. We need to disconnect =(");
|
log.info("Recieving data after sending a attach failed for device (" + command.getSender() + ") failed. We need to disconnect =(");
|
||||||
disconnect();
|
disconnect();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Let's save them for later.
|
// Let's save them for later.
|
||||||
NetworkHIDDevice sender = command.getSender();
|
NetworkHIDDevice sender = command.getSender();
|
||||||
if(sender != null){
|
if (sender != null) {
|
||||||
sender.setDeviceslot(deviceslot);
|
sender.setDeviceslot(deviceslot);
|
||||||
sender.setPadslot(padslot);
|
sender.setPadslot(padslot);
|
||||||
}else{
|
} else {
|
||||||
log.info("Something really went wrong. Got an attach event with out an " + NetworkHIDDevice.class.getSimpleName());
|
log.info("Something really went wrong. Got an attach event with out an " + NetworkHIDDevice.class.getSimpleName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
log.info("Attaching done!");
|
log.info("Attaching done!");
|
||||||
return true;
|
return true;
|
||||||
}else{
|
} else {
|
||||||
log.info("Sending the attach command for device (" + command.getSender() + ") failed. sendTCP failed");
|
log.info("Sending the attach command for device (" + command.getSender() + ") failed. sendTCP failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendingRead(List<ReadCommand> readCommands) {
|
private void sendingRead(List<ReadCommand> readCommands) {
|
||||||
byte[] rawCommand;
|
byte[] rawCommand;
|
||||||
try {
|
try {
|
||||||
rawCommand = Protocol.getRawReadDataToSend(readCommands);
|
rawCommand = Protocol.getRawReadDataToSend(readCommands);
|
||||||
if(sendUDP(rawCommand) == true){
|
if (sendUDP(rawCommand) == true) {
|
||||||
System.out.println("UDP Packet sent: "+ Utilities.ByteArrayToString(rawCommand));
|
System.out.println("UDP Packet sent: " + Utilities.ByteArrayToString(rawCommand));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Sending read data failed.");
|
System.out.println("Sending read data failed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean sendUDP(byte[] rawCommand) {
|
private boolean sendUDP(byte[] rawCommand) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if(udpClient != null && isConnected()){
|
if (udpClient != null && isConnected()) {
|
||||||
try {
|
try {
|
||||||
udpClient.send(rawCommand);
|
udpClient.send(rawCommand);
|
||||||
result = true;
|
result = true;
|
||||||
@ -291,10 +295,10 @@ public class NetworkManager implements Runnable{
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean sendTCP(byte[] rawCommand) {
|
private boolean sendTCP(byte[] rawCommand) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if(tcpClient != null){
|
if (tcpClient != null) {
|
||||||
try {
|
try {
|
||||||
tcpClient.send(rawCommand);
|
tcpClient.send(rawCommand);
|
||||||
result = true;
|
result = true;
|
||||||
@ -304,9 +308,9 @@ public class NetworkManager implements Runnable{
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
//ControllerManager.deactivateAllAttachedControllers();
|
// ControllerManager.deactivateAllAttachedControllers();
|
||||||
tcpClient.abort();
|
tcpClient.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +321,7 @@ public class NetworkManager implements Runnable{
|
|||||||
private byte recvTCPByte() throws IOException {
|
private byte recvTCPByte() throws IOException {
|
||||||
return tcpClient.recvByte();
|
return tcpClient.recvByte();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
return (tcpClient != null && tcpClient.isConnected());
|
return (tcpClient != null && tcpClient.isConnected());
|
||||||
}
|
}
|
||||||
@ -329,7 +333,7 @@ public class NetworkManager implements Runnable{
|
|||||||
tcpClient.connect(ip);
|
tcpClient.connect(ip);
|
||||||
System.out.println("TCP Connected!");
|
System.out.println("TCP Connected!");
|
||||||
udpClient = UDPClient.createUDPClient(ip);
|
udpClient = UDPClient.createUDPClient(ip);
|
||||||
if(udpClient != null){
|
if (udpClient != null) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -342,7 +346,7 @@ public class NetworkManager implements Runnable{
|
|||||||
this.ownCommands.add(command);
|
this.ownCommands.add(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReconnecting() {
|
public boolean isReconnecting() {
|
||||||
return !tcpClient.isConnected() && tcpClient.isShouldRetry();
|
return !tcpClient.isConnected() && tcpClient.isShouldRetry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,77 +35,67 @@ import net.ash.HIDToVPADNetworkClient.network.commands.ReadCommand;
|
|||||||
|
|
||||||
@Log
|
@Log
|
||||||
public class Protocol {
|
public class Protocol {
|
||||||
public static final int TCP_PORT = 8112;
|
public static final int TCP_PORT = 8112;
|
||||||
public static final int UDP_PORT = 8113;
|
public static final int UDP_PORT = 8113;
|
||||||
|
|
||||||
public static final byte TCP_HANDSHAKE = 0x12;
|
|
||||||
public static final byte TCP_SAME_CLIENT = 0x20;
|
|
||||||
public static final byte TCP_NEW_CLIENT = 0x21;
|
|
||||||
|
|
||||||
public static final byte TCP_CMD_ATTACH = 0x01;
|
|
||||||
public static final byte TCP_CMD_DETACH = 0x02;
|
|
||||||
public static final byte TCP_CMD_PING = (byte)0xF0;
|
|
||||||
|
|
||||||
public static final byte UDP_CMD_DATA = 0x03;
|
|
||||||
|
|
||||||
|
|
||||||
public static final byte TCP_CMD_ATTACH_CONFIG_FOUND = (byte) 0xE0;
|
|
||||||
public static final byte TCP_CMD_ATTACH_CONFIG_NOT_FOUND = (byte) 0xE1;
|
|
||||||
public static final byte TCP_CMD_ATTACH_USERDATA_OKAY = (byte) 0xE8;
|
|
||||||
public static final byte TCP_CMD_ATTACH_USERDATA_BAD = (byte) 0xE9;
|
|
||||||
|
|
||||||
private Protocol(){}
|
|
||||||
|
|
||||||
public enum HandshakeReturnCode {
|
|
||||||
BAD_HANDSHAKE,
|
|
||||||
SAME_CLIENT,
|
|
||||||
NEW_CLIENT
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] getRawAttachDataToSend(AttachCommand command) throws IOException {
|
|
||||||
return ByteBuffer.allocate(9)
|
|
||||||
.put(Protocol.TCP_CMD_ATTACH)
|
|
||||||
.putInt(command.getHandle())
|
|
||||||
.putShort(command.getVid())
|
|
||||||
.putShort(command.getPid())
|
|
||||||
.array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] getRawDetachDataToSend(DetachCommand command) throws IOException {
|
|
||||||
return ByteBuffer.allocate(5)
|
|
||||||
.put(Protocol.TCP_CMD_DETACH)
|
|
||||||
.putInt(command.getHandle())
|
|
||||||
.array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] getRawPingDataToSend(PingCommand command){
|
|
||||||
return new byte[]{Protocol.TCP_CMD_PING};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] getRawReadDataToSend(List<ReadCommand> readCommands) throws IOException {
|
public static final byte TCP_HANDSHAKE = 0x12;
|
||||||
|
public static final byte TCP_SAME_CLIENT = 0x20;
|
||||||
|
public static final byte TCP_NEW_CLIENT = 0x21;
|
||||||
|
|
||||||
|
public static final byte TCP_CMD_ATTACH = 0x01;
|
||||||
|
public static final byte TCP_CMD_DETACH = 0x02;
|
||||||
|
public static final byte TCP_CMD_PING = (byte) 0xF0;
|
||||||
|
|
||||||
|
public static final byte UDP_CMD_DATA = 0x03;
|
||||||
|
|
||||||
|
public static final byte TCP_CMD_ATTACH_CONFIG_FOUND = (byte) 0xE0;
|
||||||
|
public static final byte TCP_CMD_ATTACH_CONFIG_NOT_FOUND = (byte) 0xE1;
|
||||||
|
public static final byte TCP_CMD_ATTACH_USERDATA_OKAY = (byte) 0xE8;
|
||||||
|
public static final byte TCP_CMD_ATTACH_USERDATA_BAD = (byte) 0xE9;
|
||||||
|
|
||||||
|
private Protocol() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum HandshakeReturnCode {
|
||||||
|
BAD_HANDSHAKE, SAME_CLIENT, NEW_CLIENT
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getRawAttachDataToSend(AttachCommand command) throws IOException {
|
||||||
|
return ByteBuffer.allocate(9).put(Protocol.TCP_CMD_ATTACH).putInt(command.getHandle()).putShort(command.getVid()).putShort(command.getPid()).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getRawDetachDataToSend(DetachCommand command) throws IOException {
|
||||||
|
return ByteBuffer.allocate(5).put(Protocol.TCP_CMD_DETACH).putInt(command.getHandle()).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getRawPingDataToSend(PingCommand command) {
|
||||||
|
return new byte[] { Protocol.TCP_CMD_PING };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getRawReadDataToSend(List<ReadCommand> readCommands) throws IOException {
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
DataOutputStream dos = new DataOutputStream(bos);
|
DataOutputStream dos = new DataOutputStream(bos);
|
||||||
dos.writeByte(Protocol.UDP_CMD_DATA);
|
dos.writeByte(Protocol.UDP_CMD_DATA);
|
||||||
dos.writeByte(readCommands.size());
|
dos.writeByte(readCommands.size());
|
||||||
|
|
||||||
for(ReadCommand command : readCommands){
|
for (ReadCommand command : readCommands) {
|
||||||
NetworkHIDDevice sender = command.getSender();
|
NetworkHIDDevice sender = command.getSender();
|
||||||
byte[] data = command.getData();
|
byte[] data = command.getData();
|
||||||
if(data.length > 0xFF){
|
if (data.length > 0xFF) {
|
||||||
log.info("Tried to send too much data. Maximum is 0xFF bytes read command.");
|
log.info("Tried to send too much data. Maximum is 0xFF bytes read command.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte newLength = (byte)(data.length & 0xFF);
|
byte newLength = (byte) (data.length & 0xFF);
|
||||||
|
|
||||||
dos.writeInt(command.getHandle());
|
dos.writeInt(command.getHandle());
|
||||||
dos.writeShort(sender.getDeviceslot());
|
dos.writeShort(sender.getDeviceslot());
|
||||||
dos.writeByte(sender.getPadslot());
|
dos.writeByte(sender.getPadslot());
|
||||||
|
|
||||||
dos.write(newLength);
|
dos.write(newLength);
|
||||||
dos.write(data, 0, newLength);
|
dos.write(data, 0, newLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bos.toByteArray();
|
return bos.toByteArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,109 +39,112 @@ import net.ash.HIDToVPADNetworkClient.util.Settings;
|
|||||||
|
|
||||||
@Log
|
@Log
|
||||||
public class TCPClient {
|
public class TCPClient {
|
||||||
private Socket sock;
|
private Socket sock;
|
||||||
private DataInputStream in;
|
private DataInputStream in;
|
||||||
private DataOutputStream out;
|
private DataOutputStream out;
|
||||||
@Getter private int clientID = HandleFoundry.next();
|
@Getter private int clientID = HandleFoundry.next();
|
||||||
|
|
||||||
@Getter @Setter(AccessLevel.PRIVATE)
|
@Getter @Setter(AccessLevel.PRIVATE) private int shouldRetry = Settings.MAXIMUM_TRIES_FOR_RECONNECTING;
|
||||||
private int shouldRetry = Settings.getMaxTriesForReconnecting();
|
|
||||||
|
private String ip;
|
||||||
private String ip;
|
|
||||||
|
public TCPClient() {
|
||||||
public TCPClient() {
|
}
|
||||||
}
|
|
||||||
|
public synchronized void connect(String ip) throws Exception {
|
||||||
public synchronized void connect(String ip) throws Exception {
|
|
||||||
|
sock = new Socket();
|
||||||
sock = new Socket();
|
sock.connect(new InetSocketAddress(ip, Protocol.TCP_PORT), 2000);
|
||||||
sock.connect(new InetSocketAddress(ip, Protocol.TCP_PORT), 2000);
|
in = new DataInputStream(sock.getInputStream());
|
||||||
in = new DataInputStream(sock.getInputStream());
|
out = new DataOutputStream(sock.getOutputStream());
|
||||||
out = new DataOutputStream(sock.getOutputStream());
|
|
||||||
|
HandshakeReturnCode resultHandshake = doHandshake();
|
||||||
HandshakeReturnCode resultHandshake = doHandshake();
|
if (resultHandshake == HandshakeReturnCode.BAD_HANDSHAKE) {
|
||||||
if(resultHandshake == HandshakeReturnCode.BAD_HANDSHAKE){
|
log.info("[TCP] Handshaking failed");
|
||||||
log.info("[TCP] Handshaking failed");
|
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}else{
|
} else {
|
||||||
if(resultHandshake == HandshakeReturnCode.NEW_CLIENT && this.ip != null){
|
if (resultHandshake == HandshakeReturnCode.NEW_CLIENT && this.ip != null) {
|
||||||
//We check the IP to be sure it's the first time we connect to a WiiU. //TODO: Sending a ID from the WiiU which will be compared?
|
// We check the IP to be sure it's the first time we connect to
|
||||||
//we are new to the client.
|
// a WiiU. //TODO: Sending a ID from the WiiU which will be
|
||||||
|
// compared?
|
||||||
|
// we are new to the client.
|
||||||
ActiveControllerManager.getInstance().attachAllActiveControllers();
|
ActiveControllerManager.getInstance().attachAllActiveControllers();
|
||||||
}else if(resultHandshake == HandshakeReturnCode.SAME_CLIENT){
|
} else if (resultHandshake == HandshakeReturnCode.SAME_CLIENT) {
|
||||||
|
|
||||||
}
|
}
|
||||||
this.ip = ip;
|
this.ip = ip;
|
||||||
shouldRetry = 0;
|
shouldRetry = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized HandshakeReturnCode doHandshake() throws Exception {
|
private synchronized HandshakeReturnCode doHandshake() throws Exception {
|
||||||
if (recvByte() != Protocol.TCP_HANDSHAKE) return HandshakeReturnCode.BAD_HANDSHAKE;
|
if (recvByte() != Protocol.TCP_HANDSHAKE) return HandshakeReturnCode.BAD_HANDSHAKE;
|
||||||
send(clientID);
|
send(clientID);
|
||||||
log.info("[TCP] Handshaking...");
|
log.info("[TCP] Handshaking...");
|
||||||
HandshakeReturnCode test = (recvByte() == Protocol.TCP_NEW_CLIENT) ? HandshakeReturnCode.NEW_CLIENT : HandshakeReturnCode.SAME_CLIENT;
|
HandshakeReturnCode test = (recvByte() == Protocol.TCP_NEW_CLIENT) ? HandshakeReturnCode.NEW_CLIENT : HandshakeReturnCode.SAME_CLIENT;
|
||||||
return test;
|
return test;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean abort(){
|
public synchronized boolean abort() {
|
||||||
try {
|
try {
|
||||||
shouldRetry = Settings.getMaxTriesForReconnecting();
|
shouldRetry = Settings.MAXIMUM_TRIES_FOR_RECONNECTING;
|
||||||
sock.close();
|
sock.close();
|
||||||
clientID = HandleFoundry.next();
|
clientID = HandleFoundry.next();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println(e.getMessage()); //TODO: handle
|
System.out.println(e.getMessage()); // TODO: handle
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void send(byte[] rawCommand) throws IOException {
|
public synchronized void send(byte[] rawCommand) throws IOException {
|
||||||
try{
|
try {
|
||||||
out.write(rawCommand);
|
out.write(rawCommand);
|
||||||
out.flush();
|
out.flush();
|
||||||
}catch(IOException e){
|
} catch (IOException e) {
|
||||||
try {
|
try {
|
||||||
if(shouldRetry++ < Settings.getMaxTriesForReconnecting()){
|
if (shouldRetry++ < Settings.MAXIMUM_TRIES_FOR_RECONNECTING) {
|
||||||
System.out.println("Trying again to connect! Attempt number " + shouldRetry);
|
System.out.println("Trying again to connect! Attempt number " + shouldRetry);
|
||||||
connect(ip); //TODO: this is for reconnecting when the WiiU switches the application. But this breaks disconnecting, woops.
|
connect(ip); // TODO: this is for reconnecting when the WiiU
|
||||||
}else{
|
// switches the application. But this breaks
|
||||||
|
// disconnecting, woops.
|
||||||
|
} else {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
//e1.printStackTrace();
|
// e1.printStackTrace();
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void send(int value) throws IOException {
|
public synchronized void send(int value) throws IOException {
|
||||||
send(ByteBuffer.allocate(4).putInt(value).array());
|
send(ByteBuffer.allocate(4).putInt(value).array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized byte recvByte() throws IOException {
|
public synchronized byte recvByte() throws IOException {
|
||||||
try{
|
try {
|
||||||
return in.readByte();
|
return in.readByte();
|
||||||
}catch(IOException e){
|
} catch (IOException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized short recvShort() throws IOException {
|
public synchronized short recvShort() throws IOException {
|
||||||
try{
|
try {
|
||||||
return in.readShort();
|
return in.readShort();
|
||||||
}catch(IOException e){
|
} catch (IOException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean isConnected(){
|
public synchronized boolean isConnected() {
|
||||||
return (sock != null && sock.isConnected() && !sock.isClosed());
|
return (sock != null && sock.isConnected() && !sock.isClosed());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShouldRetry() {
|
public boolean isShouldRetry() {
|
||||||
return this.shouldRetry < Settings.getMaxTriesForReconnecting();
|
return this.shouldRetry < Settings.MAXIMUM_TRIES_FOR_RECONNECTING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,25 +29,26 @@ import java.net.SocketException;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
public class UDPClient {
|
public class UDPClient {
|
||||||
private final DatagramSocket sock;
|
private final DatagramSocket sock;
|
||||||
private final InetAddress host;
|
private final InetAddress host;
|
||||||
|
|
||||||
private UDPClient(String ip) throws SocketException, UnknownHostException{
|
private UDPClient(String ip) throws SocketException, UnknownHostException {
|
||||||
sock = new DatagramSocket();
|
sock = new DatagramSocket();
|
||||||
host = InetAddress.getByName(ip);
|
host = InetAddress.getByName(ip);
|
||||||
}
|
}
|
||||||
public static UDPClient createUDPClient(String ip){
|
|
||||||
UDPClient result = null;
|
public static UDPClient createUDPClient(String ip) {
|
||||||
|
UDPClient result = null;
|
||||||
try {
|
try {
|
||||||
result = new UDPClient(ip);
|
result = new UDPClient(ip);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//handle?
|
// handle?
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(byte[] data) throws IOException {
|
public void send(byte[] data) throws IOException {
|
||||||
DatagramPacket packet = new DatagramPacket(data, data.length, host, Protocol.UDP_PORT);
|
DatagramPacket packet = new DatagramPacket(data, data.length, host, Protocol.UDP_PORT);
|
||||||
sock.send(packet);
|
sock.send(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,21 +20,22 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package net.ash.HIDToVPADNetworkClient.network.commands;
|
package net.ash.HIDToVPADNetworkClient.network.commands;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.ash.HIDToVPADNetworkClient.network.NetworkHIDDevice;
|
import net.ash.HIDToVPADNetworkClient.network.NetworkHIDDevice;
|
||||||
|
|
||||||
public class AttachCommand extends DeviceCommand {
|
public class AttachCommand extends DeviceCommand {
|
||||||
@Getter private final short vid;
|
@Getter private final short vid;
|
||||||
@Getter private final short pid;
|
@Getter private final short pid;
|
||||||
|
|
||||||
public AttachCommand(int hidHandle, short vid, short pid, NetworkHIDDevice sender) {
|
public AttachCommand(int hidHandle, short vid, short pid, NetworkHIDDevice sender) {
|
||||||
super(hidHandle,sender);
|
super(hidHandle, sender);
|
||||||
this.vid = vid;
|
this.vid = vid;
|
||||||
this.pid = pid;
|
this.pid = pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "AttachCommand [vid=" + vid + ", pid=" + pid+ ", handle=" + getHandle() + ", sender=" + getSender() + "]";
|
return "AttachCommand [vid=" + vid + ", pid=" + pid + ", handle=" + getHandle() + ", sender=" + getSender() + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,9 @@ package net.ash.HIDToVPADNetworkClient.network.commands;
|
|||||||
|
|
||||||
import net.ash.HIDToVPADNetworkClient.network.NetworkHIDDevice;
|
import net.ash.HIDToVPADNetworkClient.network.NetworkHIDDevice;
|
||||||
|
|
||||||
public class DetachCommand extends DeviceCommand{
|
public class DetachCommand extends DeviceCommand {
|
||||||
public DetachCommand(int hidHandle, NetworkHIDDevice sender){
|
public DetachCommand(int hidHandle, NetworkHIDDevice sender) {
|
||||||
super(hidHandle,sender);
|
super(hidHandle, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,18 +20,19 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package net.ash.HIDToVPADNetworkClient.network.commands;
|
package net.ash.HIDToVPADNetworkClient.network.commands;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import net.ash.HIDToVPADNetworkClient.network.NetworkHIDDevice;
|
import net.ash.HIDToVPADNetworkClient.network.NetworkHIDDevice;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public abstract class DeviceCommand {
|
public abstract class DeviceCommand {
|
||||||
private final int handle;
|
private final int handle;
|
||||||
private final NetworkHIDDevice sender;
|
private final NetworkHIDDevice sender;
|
||||||
private final Class<? extends DeviceCommand> type;
|
private final Class<? extends DeviceCommand> type;
|
||||||
|
|
||||||
protected DeviceCommand(int hidHandle,NetworkHIDDevice sender){
|
protected DeviceCommand(int hidHandle, NetworkHIDDevice sender) {
|
||||||
this.handle = hidHandle;
|
this.handle = hidHandle;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.type = this.getClass();
|
this.type = this.getClass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,13 @@ import net.ash.HIDToVPADNetworkClient.network.NetworkHIDDevice;
|
|||||||
|
|
||||||
public class PingCommand extends DeviceCommand {
|
public class PingCommand extends DeviceCommand {
|
||||||
public PingCommand() {
|
public PingCommand() {
|
||||||
this((short) 0,null);
|
this((short) 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PingCommand(int hidHandle, NetworkHIDDevice sender) {
|
private PingCommand(int hidHandle, NetworkHIDDevice sender) {
|
||||||
super(hidHandle, sender);
|
super(hidHandle, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "PingCommand []";
|
return "PingCommand []";
|
||||||
|
@ -24,13 +24,14 @@ package net.ash.HIDToVPADNetworkClient.network.commands;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.ash.HIDToVPADNetworkClient.network.NetworkHIDDevice;
|
import net.ash.HIDToVPADNetworkClient.network.NetworkHIDDevice;
|
||||||
|
|
||||||
public class ReadCommand extends DeviceCommand{
|
public class ReadCommand extends DeviceCommand {
|
||||||
@Getter private final byte[] data;
|
@Getter private final byte[] data;
|
||||||
public ReadCommand(int hidHandle,byte[] data, NetworkHIDDevice sender) {
|
|
||||||
|
public ReadCommand(int hidHandle, byte[] data, NetworkHIDDevice sender) {
|
||||||
super(hidHandle, sender);
|
super(hidHandle, sender);
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ReadCommand [handle=" + getHandle() + ", sender=" + getSender() + "]";
|
return "ReadCommand [handle=" + getHandle() + ", sender=" + getSender() + "]";
|
||||||
|
@ -28,12 +28,13 @@ package net.ash.HIDToVPADNetworkClient.util;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class HandleFoundry {
|
public class HandleFoundry {
|
||||||
//We start with a random value, so we have at each startup a different clientID!
|
// We start with a random value, so we have at each startup a different clientID!
|
||||||
private static int h = new Random().nextInt();
|
private static int h = new Random().nextInt() % 10000;
|
||||||
|
|
||||||
private HandleFoundry(){}
|
private HandleFoundry() {
|
||||||
|
}
|
||||||
public static int next() {
|
|
||||||
return h++;
|
public static int next() {
|
||||||
}
|
return h++;
|
||||||
|
}
|
||||||
}
|
}
|
@ -22,6 +22,7 @@
|
|||||||
package net.ash.HIDToVPADNetworkClient.util;
|
package net.ash.HIDToVPADNetworkClient.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import purejavahidapi.HidDevice;
|
import purejavahidapi.HidDevice;
|
||||||
@ -29,30 +30,50 @@ import purejavahidapi.HidDeviceInfo;
|
|||||||
import purejavahidapi.PureJavaHidApi;
|
import purejavahidapi.PureJavaHidApi;
|
||||||
|
|
||||||
public class PureJavaHidApiManager {
|
public class PureJavaHidApiManager {
|
||||||
|
|
||||||
private PureJavaHidApiManager(){}
|
private PureJavaHidApiManager() {
|
||||||
|
}
|
||||||
public static boolean MAC_OS_X;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches the corresponding HIDDevice for the given path
|
* Searches the corresponding HIDDevice for the given path
|
||||||
* @param path Path of the HIDDevice
|
*
|
||||||
|
* @param path
|
||||||
|
* Path of the HIDDevice
|
||||||
* @return It the device is found, it will be returned. Otherwise null is returned.
|
* @return It the device is found, it will be returned. Otherwise null is returned.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static HidDevice getDeviceByPath(String path) throws IOException{
|
public static HidDevice getDeviceByPath(String path) throws IOException {
|
||||||
List<HidDeviceInfo> devList = PureJavaHidApi.enumerateDevices();
|
List<HidDeviceInfo> devList = PureJavaHidApi.enumerateDevices();
|
||||||
|
HidDevice result = null;
|
||||||
for (HidDeviceInfo info : devList) {
|
for (HidDeviceInfo info : devList) {
|
||||||
if (MAC_OS_X) {
|
result = openDeviceByPath(info, path);
|
||||||
if(info.getPath().substring(0, 13).equals(path)){
|
if (result != null) return result;
|
||||||
return PureJavaHidApi.openDevice(info);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(info.getPath().equals(path)){
|
|
||||||
return PureJavaHidApi.openDevice(info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HidDevice openDeviceByPath(HidDeviceInfo info, String expected_path) throws IOException {
|
||||||
|
if (info == null) return null;
|
||||||
|
String real_path = info.getPath();
|
||||||
|
|
||||||
|
if (Settings.isMacOSX()) real_path = real_path.substring(0, 13);
|
||||||
|
|
||||||
|
if (real_path.equals(expected_path)){
|
||||||
|
return PureJavaHidApi.openDevice(info);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<HidDeviceInfo> getAttachedController() {
|
||||||
|
List<HidDeviceInfo> connectedGamepads = new ArrayList<HidDeviceInfo>();
|
||||||
|
|
||||||
|
for (HidDeviceInfo info : PureJavaHidApi.enumerateDevices()) {
|
||||||
|
if (info.getUsagePage() == 0x05 || info.getUsagePage() == 0x04 || (info.getVendorId() == 0x57e) || (info.getVendorId() == 0x054c)) {
|
||||||
|
connectedGamepads.add(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return connectedGamepads;
|
||||||
|
}
|
||||||
}
|
}
|
@ -26,144 +26,136 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import lombok.extern.java.Log;
|
import lombok.extern.java.Log;
|
||||||
|
import net.ash.HIDToVPADNetworkClient.controller.Controller.ControllerType;
|
||||||
|
import net.ash.HIDToVPADNetworkClient.util.Settings.Platform;
|
||||||
|
|
||||||
//TODO autosave IP addr
|
//TODO autosave IP addr
|
||||||
|
|
||||||
@Log
|
@Log
|
||||||
public class Settings {
|
public class Settings {
|
||||||
private static final String CONFIG_FILE_NAME = "config.properties";
|
private static final String CONFIG_FILE_NAME = "hidtovpad.properties";
|
||||||
|
|
||||||
@Getter
|
|
||||||
private static int detectControllerInterval = 1000;
|
|
||||||
@Getter
|
|
||||||
private static int handleInputsInterval = 15;
|
|
||||||
@Getter
|
|
||||||
private static int maxTriesForReconnecting = 10;
|
|
||||||
@Getter
|
|
||||||
private static int sleepAfterPolling = 10;
|
|
||||||
/**
|
|
||||||
* What does this even mean?
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private static int sendingCmdSleepIfNotConnected = 500;
|
|
||||||
@Getter
|
|
||||||
private static int pingInterval = 1000;
|
|
||||||
@Getter
|
|
||||||
private static int processCmdInterval = 10;
|
|
||||||
@Getter
|
|
||||||
private static String ipAddr = "192.168.0.35"; //@Maschell, you're welcome
|
|
||||||
|
|
||||||
private Settings() {}
|
public static final int DETECT_CONTROLLER_INTERVAL = 1000;
|
||||||
|
public static final int HANDLE_INPUTS_INTERVAL = 15;
|
||||||
|
public static final int MAXIMUM_TRIES_FOR_RECONNECTING = 10;
|
||||||
|
public static final int SLEEP_AFER_POLLING = 10;
|
||||||
|
public static final int SENDING_CMD_SLEEP_IF_NOT_CONNECTED = 500;
|
||||||
|
public static final int PING_INTERVAL = 1000;
|
||||||
|
public static final int PROCESS_CMD_INTERVAL = 10;
|
||||||
|
|
||||||
|
@Getter @Setter private static String ipAddr = "192.168.0.35"; // @Maschell, you're welcome
|
||||||
|
|
||||||
|
private Settings() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void loadSettings() {
|
public static void loadSettings() {
|
||||||
File configDir = new File(getConfigDir());
|
File configDir = new File(getConfigDir());
|
||||||
if (!configDir.exists()) {
|
if (!configDir.exists()) {
|
||||||
log.info("Creating " + configDir.getAbsolutePath() + "...");
|
log.info("Creating " + configDir.getAbsolutePath() + "...");
|
||||||
configDir.mkdirs();
|
configDir.mkdirs();
|
||||||
}
|
}
|
||||||
File configFile = new File(getConfigDir() + CONFIG_FILE_NAME);
|
File configFile = getConfigFile();
|
||||||
if (!configFile.exists()) {
|
if (!configFile.exists()) {
|
||||||
log.info("Creating " + configFile.getAbsolutePath() + " with default values...");
|
log.info("Creating " + configFile.getAbsolutePath() + " with default values...");
|
||||||
try {
|
try {
|
||||||
configFile.createNewFile();
|
configFile.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.severe("Could not create config file!");
|
log.severe("Could not create config file!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
log.warning("Using default values");
|
log.warning("Using default values");
|
||||||
}
|
}
|
||||||
saveSettings(configFile);
|
saveSettings(configFile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("Loading config from " + configFile.getAbsolutePath() + "...");
|
log.info("Loading config from " + configFile.getAbsolutePath() + "...");
|
||||||
|
|
||||||
Properties prop = new Properties();
|
Properties prop = new Properties();
|
||||||
try {
|
try {
|
||||||
prop.load(new FileInputStream(configFile));
|
prop.load(new FileInputStream(configFile));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.severe("Error while loading config file!");
|
log.severe("Error while loading config file!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
log.warning("Using default values");
|
log.warning("Using default values");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
String s_detectControllerInterval = prop.getProperty("detectControllerInterval");
|
|
||||||
String s_handleInputsInterval = prop.getProperty("handleInputsInterval");
|
Settings.ipAddr = prop.getProperty("ipAddr");
|
||||||
String s_maxTriesForReconnecting = prop.getProperty("maxTriesForReconnecting");
|
|
||||||
String s_sleepAfterPolling = prop.getProperty("sleepAfterPolling");
|
log.info("Loaded config successfully!");
|
||||||
String s_sendingCmdSleepIfNotConnected = prop.getProperty("sendingCmdSleepIfNotConnected");
|
|
||||||
String s_pingInterval = prop.getProperty("pingInterval");
|
|
||||||
String s_processCmdInterval = prop.getProperty("processCmdInterval");
|
|
||||||
String s_ipAddr = prop.getProperty("ipAddr");
|
|
||||||
|
|
||||||
int detectControllerInterval, handleInputsInterval, maxTriesForReconnecting, sleepAfterPolling, sendingCmdSleepIfNotConnected, pingInterval, processCmdInterval;
|
|
||||||
|
|
||||||
try {
|
|
||||||
detectControllerInterval = Integer.parseInt(s_detectControllerInterval);
|
|
||||||
handleInputsInterval = Integer.parseInt(s_handleInputsInterval);
|
|
||||||
maxTriesForReconnecting = Integer.parseInt(s_maxTriesForReconnecting);
|
|
||||||
sleepAfterPolling = Integer.parseInt(s_sleepAfterPolling);
|
|
||||||
sendingCmdSleepIfNotConnected = Integer.parseInt(s_sendingCmdSleepIfNotConnected);
|
|
||||||
pingInterval = Integer.parseInt(s_pingInterval);
|
|
||||||
processCmdInterval = Integer.parseInt(s_processCmdInterval);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
log.warning("Config file contains invalid values!");
|
|
||||||
log.warning("Reconstructing...");
|
|
||||||
saveSettings(configFile);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Settings.detectControllerInterval = detectControllerInterval;
|
|
||||||
Settings.handleInputsInterval = handleInputsInterval;
|
|
||||||
Settings.maxTriesForReconnecting = maxTriesForReconnecting;
|
|
||||||
Settings.sleepAfterPolling = sleepAfterPolling;
|
|
||||||
Settings.sendingCmdSleepIfNotConnected = sendingCmdSleepIfNotConnected;
|
|
||||||
Settings.pingInterval = pingInterval;
|
|
||||||
Settings.processCmdInterval = processCmdInterval;
|
|
||||||
Settings.ipAddr = s_ipAddr;
|
|
||||||
|
|
||||||
log.info("Loaded config successfully!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static File getConfigFile() {
|
||||||
|
return new File(getConfigDir() + CONFIG_FILE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveSettings() {
|
||||||
|
File configFile = getConfigFile();
|
||||||
|
if (configFile.exists()) {
|
||||||
|
log.info("Settings saved.");
|
||||||
|
saveSettings(configFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void saveSettings(File configFile) {
|
private static void saveSettings(File configFile) {
|
||||||
Properties prop = new Properties();
|
Properties prop = new Properties();
|
||||||
prop.setProperty("detectControllerInterval", Integer.toString(Settings.detectControllerInterval));
|
|
||||||
prop.setProperty("handleInputsInterval", Integer.toString(Settings.handleInputsInterval));
|
prop.setProperty("ipAddr", Settings.ipAddr);
|
||||||
prop.setProperty("maxTriesForReconnecting", Integer.toString(Settings.maxTriesForReconnecting));
|
|
||||||
prop.setProperty("sleepAfterPolling", Integer.toString(Settings.sleepAfterPolling));
|
try {
|
||||||
prop.setProperty("sendingCmdSleepIfNotConnected", Integer.toString(Settings.sendingCmdSleepIfNotConnected));
|
FileOutputStream outStream = new FileOutputStream(configFile);
|
||||||
prop.setProperty("pingInterval", Integer.toString(Settings.pingInterval));
|
prop.store(outStream, "HIDToVPADNetworkClient");
|
||||||
prop.setProperty("processCmdInterval", Integer.toString(Settings.processCmdInterval));
|
outStream.close();
|
||||||
prop.setProperty("ipAddr", Settings.ipAddr);
|
} catch (FileNotFoundException e) {
|
||||||
|
log.severe("Could not open the new config file!");
|
||||||
try {
|
e.printStackTrace();
|
||||||
FileOutputStream outStream = new FileOutputStream(configFile);
|
log.warning("New file will not be written.");
|
||||||
prop.store(outStream, "HIDToVPADNetworkClient");
|
return;
|
||||||
outStream.close();
|
} catch (IOException e) {
|
||||||
} catch (FileNotFoundException e) {
|
log.severe("Could not write the new config file!");
|
||||||
log.severe("Could not open the new config file!");
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
log.warning("New file will not be written.");
|
||||||
log.warning("New file will not be written.");
|
return;
|
||||||
return;
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
log.severe("Could not write the new config file!");
|
|
||||||
e.printStackTrace();
|
|
||||||
log.warning("New file will not be written.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getConfigDir() {
|
private static String getConfigDir() {
|
||||||
String os = System.getProperty("os.name");
|
return "config/";
|
||||||
if (os.contains("Windows")) {
|
}
|
||||||
return System.getenv("APPDATA") + "/HIDToVPADNetworkClient/";
|
|
||||||
} else if (os.contains("Mac OS X")) {
|
public static boolean isLinux() {
|
||||||
return System.getProperty("user.home") + "/Library/Application Support/HIDToVPADNetworkClient/";
|
return getPlattform() == Platform.LINUX;
|
||||||
} else { //Linux
|
}
|
||||||
return System.getProperty("user.home") + "/.config/HIDToVPADNetworkClient/";
|
|
||||||
}
|
public static boolean isWindows() {
|
||||||
|
return getPlattform() == Platform.WINDOWS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMacOSX() {
|
||||||
|
return getPlattform() == Platform.MAC_OS_X;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Platform getPlattform() {
|
||||||
|
String os = System.getProperty("os.name");
|
||||||
|
|
||||||
|
if (os.contains("Linux")) {
|
||||||
|
return Platform.LINUX;
|
||||||
|
} else if (os.contains("Windows")) {
|
||||||
|
return Platform.WINDOWS;
|
||||||
|
} else if (os.contains("Mac OS X")) {
|
||||||
|
return Platform.MAC_OS_X;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Platform {
|
||||||
|
LINUX, WINDOWS, MAC_OS_X, UNKNOWN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,16 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package net.ash.HIDToVPADNetworkClient.util;
|
package net.ash.HIDToVPADNetworkClient.util;
|
||||||
|
|
||||||
public class Utilities{
|
public class Utilities {
|
||||||
|
|
||||||
private Utilities(){}
|
private Utilities() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Let me just sleep!
|
* Let me just sleep!
|
||||||
* @param ms sleep duration in ms
|
*
|
||||||
|
* @param ms
|
||||||
|
* sleep duration in ms
|
||||||
*/
|
*/
|
||||||
public static void sleep(int ms) {
|
public static void sleep(int ms) {
|
||||||
try {
|
try {
|
||||||
@ -35,36 +38,42 @@ public class Utilities{
|
|||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a byte array to a formated String
|
* Convert a byte array to a formated String
|
||||||
* @param ba byte array
|
*
|
||||||
|
* @param ba
|
||||||
|
* byte array
|
||||||
* @return String representing the binary data
|
* @return String representing the binary data
|
||||||
*/
|
*/
|
||||||
public static String ByteArrayToString(byte[] ba){
|
public static String ByteArrayToString(byte[] ba) {
|
||||||
if(ba == null) return null;
|
if (ba == null) return null;
|
||||||
StringBuilder hex = new StringBuilder(ba.length * 2);
|
StringBuilder hex = new StringBuilder(ba.length * 2);
|
||||||
for(byte b : ba){
|
for (byte b : ba) {
|
||||||
hex.append(String.format("%02X", b));
|
hex.append(String.format("%02X", b));
|
||||||
}
|
}
|
||||||
return hex.toString();
|
return hex.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a signed short value to a unsigned byte
|
* Converts a signed short value to a unsigned byte
|
||||||
* @param value short value
|
*
|
||||||
|
* @param value
|
||||||
|
* short value
|
||||||
* @return converted value
|
* @return converted value
|
||||||
*/
|
*/
|
||||||
public static short signedShortToByte(int value){
|
public static short signedShortToByte(int value) {
|
||||||
return (short) (((((short)value) + Short.MAX_VALUE + 1) >> 8) & 0xFF);
|
return (short) (((((short) value) + Short.MAX_VALUE + 1) >> 8) & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a signed short value to a unsigned byte
|
* Converts a signed short value to a unsigned byte
|
||||||
* @param value short value
|
*
|
||||||
|
* @param value
|
||||||
|
* short value
|
||||||
* @return converted value
|
* @return converted value
|
||||||
*/
|
*/
|
||||||
public static short signedShortToByte(short value){
|
public static short signedShortToByte(short value) {
|
||||||
return signedShortToByte((int) value);
|
return signedShortToByte((int) value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user