29 | class Button
30 | {
31 | private:
32 | unsigned long press_time = 0;
33 | unsigned int click_time = 0;
34 | inline bool read() {
35 | return !digitalRead(_PIN);
36 | }
37 |
38 | public:
39 | bool pressed = false;
40 | bool long_pressed = false;
41 | bool click = false;
42 |
43 |
44 |
45 | bool read(unsigned long time)
46 | {
47 | bool value = read();
48 | if (value && !pressed)
49 | {
50 | press_time = time;
51 | click_time = time;
52 | pressed = true;
53 | }
54 | else if (!value && pressed)
55 | {
56 | pressed = false;
57 | click = false;
58 | long_pressed = false;
59 | }
60 | if (pressed)
61 | {
62 | if (time - press_time > BUTTON_LONG_PRESS_TIME)
63 | {
64 | long_pressed = true;
65 | press_time = time;
66 | }
67 | else {
68 | long_pressed = false;
69 | }
70 | if (time - click_time > BUTTON_CLICK_TIME)
71 | {
72 | click = true;
73 | click_time = time;
74 | }
75 | else {
76 | click = false;
77 | }
78 | }
79 | else {
80 | long_pressed = false;
81 | click = false;
82 | }
83 | return pressed;
84 | }
85 |
86 | void init()
87 | {
88 | pinMode(_PIN, INPUT_PULLUP);
89 | }
90 |
91 | void process(unsigned int time)
92 | {
93 | read(time);
94 | if (click)
95 | {
96 | send(_EVENT_CLICK, 0);
97 | }
98 | if (long_pressed)
99 | {
100 | send(_EVENT_LONG_PRESS, 0);
101 | }
102 | }
103 |
104 | };
105 |
106 | #endif
107 |
--------------------------------------------------------------------------------
/firmware/command.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2021 Frank David Martinez M.
2 | //
3 | // This file is part of HyperController.
4 | //
5 | // HyperController is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // HyperController is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU General Public License
16 | // along with Mnesarco Utils. If not, see .
17 | //
18 |
19 | #ifndef MNESARCO_COMMAND_H
20 | #define MNESARCO_COMMAND_H
21 |
22 | /**
23 | * Syntactic sugar for command management
24 | *
25 | * process_commands {
26 | * command(CMD_ID_X, cmd_funtion_a);
27 | * command(CMD_ID_Y, cmd_funtion_b);
28 | * command(CMD_ID_Z, cmd_funtion_c);
29 | * }
30 | *
31 | */
32 | #define process_commands int _cmdid_1q2w3e4r = read_command_id(); if (_cmdid_1q2w3e4r)
33 | #define command(CMD_ID, CMD) if (CMD_ID == _cmdid_1q2w3e4r) CMD()
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/firmware/config.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2021 Frank David Martinez M.
2 | //
3 | // This file is part of HyperController.
4 | //
5 | // HyperController is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // HyperController is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU General Public License
16 | // along with Mnesarco Utils. If not, see .
17 | //
18 |
19 | #ifndef MNESARCO_3DM_CONFIG_H
20 | #define MNESARCO_3DM_CONFIG_H
21 |
22 | // +----------------------------------------------------------+
23 | // | Firmware Identification |
24 | // +----------------------------------------------------------+
25 |
26 | #define FIRMWARE_NAME "Mnesarco's Hyper Controller Firmware"
27 | #define FIRMWARE_VERSION "1.0.0"
28 | #define FIRMWARE_COPYRIGHT "Copyright (C) 2021 Frank D. Martinez M. "
29 | #define FIRMWARE_LICENSE "GPLv3 "
30 |
31 |
32 | // +----------------------------------------------------------+
33 | // | Hardware Pinouts |
34 | // +----------------------------------------------------------+
35 |
36 | #define PIN_X A1 // |
37 | #define PIN_Y A0 // | <---- XY Joystick
38 | #define PIN_BTN_XY 10 // |
39 |
40 | #define PIN_Z A3 // |
41 | #define PIN_W A2 // | <---- ZW Joystick
42 | #define PIN_BTN_ZW 16 // |
43 |
44 | #define PIN_KNOB A9 // | <---- Potentiometer
45 |
46 | #define PIN_BTN_A 8 // |
47 | #define PIN_BTN_B 14 // | <---- Push buttons
48 | #define PIN_BTN_C 6 // |
49 |
50 |
51 | // +----------------------------------------------------------+
52 | // | Calibration parameters |
53 | // +----------------------------------------------------------+
54 |
55 | #define BUTTON_LONG_PRESS_TIME 500 // Pressed milliseconds to trigger Long Press event
56 | #define BUTTON_CLICK_TIME 80 // Pressed milliseconds to trigger Click event
57 | #define SENSITIVITY 100 // Higher sensitivity value = slower mouse, should be <= about 500
58 | #define SLOWDOWN 30 // Main loop slowdown (ms)
59 | #define JOYSTICK_THRESHOLD 5 // To avoid oscillations near to center
60 | #define KNOB_THRESHOLD 5 // To avoid oscillations
61 |
62 |
63 | // +----------------------------------------------------------+
64 | // | Event codes (sent through usb) |
65 | // +----------------------------------------------------------+
66 |
67 | #define EVENT_X 1 // |
68 | #define EVENT_Y 2 // | <--- Orthogonal Axes events
69 | #define EVENT_Z 3 // | (translational axes)
70 | #define EVENT_W 4 // |
71 |
72 | #define EVENT_RX 5 // |
73 | #define EVENT_RY 6 // | <--- 45 deg Axes events
74 | #define EVENT_RZ 7 // | (rotational axes)
75 | #define EVENT_RW 8 // |
76 |
77 | #define EVENT_XY0 9 // | <--- Joystick center events
78 | #define EVENT_ZW0 10 // |
79 |
80 | #define EVENT_BUTTON_XY_CLICK 50 // | <--- XY Joystick push button events
81 | #define EVENT_BUTTON_XY_LONG_PRESS 51 // |
82 |
83 | #define EVENT_BUTTON_ZW_CLICK 60 // | <--- ZW Joystick push button events
84 | #define EVENT_BUTTON_ZW_LONG_PRESS 61 // |
85 |
86 | #define EVENT_BUTTON_A_CLICK 70 // |
87 | #define EVENT_BUTTON_A_LONG_PRESS 71 // |
88 | // |
89 | #define EVENT_BUTTON_B_CLICK 80 // | <--- Push buttons events
90 | #define EVENT_BUTTON_B_LONG_PRESS 81 // |
91 | // |
92 | #define EVENT_BUTTON_C_CLICK 90 // |
93 | #define EVENT_BUTTON_C_LONG_PRESS 91 // |
94 |
95 | #define EVENT_KNOB 100 // | <--- Knob (potentiometer) event
96 |
97 | #define EVENT_COMMENT 999 // | <--- Generic text based event
98 |
99 |
100 | // +----------------------------------------------------------+
101 | // | Commands (received through usb) |
102 | // +----------------------------------------------------------+
103 |
104 | #define CMD_FIRMWARE_INFO 1 // Print Firmware version
105 | #define CMD_CALIBRATE 2 // Recalibrate Analogs (all analogs should be physically in zero position)
106 |
107 |
108 | // +----------------------------------------------------------+
109 | // | USB Communication |
110 | // +----------------------------------------------------------+
111 |
112 | #define BAUD_RATE 115200 // Serial port speed
113 |
114 | #endif
115 |
--------------------------------------------------------------------------------
/firmware/joystick.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2021 Frank David Martinez M.
2 | //
3 | // This file is part of HyperController.
4 | //
5 | // HyperController is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // HyperController is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU General Public License
16 | // along with Mnesarco Utils. If not, see .
17 | //
18 |
19 | #ifndef MNESARCO_JOYSTICK_H
20 | #define MNESARCO_JOYSTICK_H
21 |
22 | #include "serial.hpp"
23 |
24 | template
25 | struct Joystick
26 | {
27 | int offset = 0;
28 | int X0 = 0;
29 | int Y0 = 0;
30 | bool moved = false;
31 |
32 | inline void init()
33 | {
34 | pinMode(_PIN_X, INPUT);
35 | pinMode(_PIN_Y, INPUT);
36 | calibrate();
37 | }
38 |
39 | void calibrate()
40 | {
41 | X0 = analogRead(_PIN_X);
42 | Y0 = analogRead(_PIN_Y);
43 | send(_EVENT_XY0, 0);
44 | }
45 |
46 | inline int filter(int value)
47 | {
48 | if (value > _THRESSHOLD)
49 | {
50 | return value - _THRESSHOLD;
51 | }
52 | else if (value < -_THRESSHOLD)
53 | {
54 | return value + _THRESSHOLD;
55 | }
56 | return 0;
57 | }
58 |
59 | inline void send(int event, int value)
60 | {
61 | ::send(event, value / _SENSITIVITY);
62 | }
63 |
64 | inline void process()
65 | {
66 | int x = filter(analogRead(_PIN_X) - X0);
67 | int y = filter(analogRead(_PIN_Y) - Y0);
68 |
69 | // Rotations
70 |
71 | if (x > 0 && y > 0)
72 | {
73 | send(_EVENT_RX, x);
74 | }
75 | else if (x > 0 && y < 0)
76 | {
77 | send(_EVENT_RY, x);
78 | }
79 | else if (x < 0 && y > 0)
80 | {
81 | send(_EVENT_RY, x);
82 | }
83 | else if (x < 0 && y < 0)
84 | {
85 | send(_EVENT_RX, x);
86 | }
87 |
88 | // Translations
89 |
90 | else if (x != 0)
91 | {
92 | send(_EVENT_X, x);
93 | }
94 | else if (y != 0)
95 | {
96 | send(_EVENT_Y, y);
97 | }
98 |
99 | // Neutral
100 |
101 | if (x == 0 && y == 0)
102 | {
103 | if (moved)
104 | {
105 | send(_EVENT_XY0, 0);
106 | moved = false;
107 | }
108 | }
109 | else
110 | {
111 | moved = true;
112 | }
113 |
114 | }
115 |
116 | };
117 |
118 | #endif
--------------------------------------------------------------------------------
/firmware/knob.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2021 Frank David Martinez M.
2 | //
3 | // This file is part of HyperController.
4 | //
5 | // HyperController is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // HyperController is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU General Public License
16 | // along with Mnesarco Utils. If not, see .
17 | //
18 |
19 | #ifndef MNESARCO_KNOB_H
20 | #define MNESARCO_KNOB_H
21 |
22 | #include "serial.hpp"
23 |
24 | template
25 | struct Knob
26 | {
27 | int value = -1024;
28 | int offset = 0;
29 |
30 | void init()
31 | {
32 | pinMode(_PIN, INPUT);
33 | }
34 |
35 | void process()
36 | {
37 | int read = analogRead(_PIN) - offset;
38 | int diff = value - read;
39 | if (diff > _THRESHOLD || diff < - _THRESHOLD)
40 | {
41 | value = read;
42 | send(_EVENT, value);
43 | }
44 | }
45 |
46 | void calibrate()
47 | {
48 | offset = analogRead(_PIN);
49 | send(_EVENT, 0);
50 | }
51 |
52 | };
53 |
54 |
55 | #endif
--------------------------------------------------------------------------------
/firmware/serial.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2021 Frank David Martinez M.
2 | //
3 | // This file is part of HyperController.
4 | //
5 | // HyperController is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // HyperController is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU General Public License
16 | // along with Mnesarco Utils. If not, see .
17 | //
18 |
19 |
20 | #ifndef MNESARCO_3DM_SERIAL_H
21 | #define MNESARCO_3DM_SERIAL_H
22 |
23 | // +--------------------------------------------------------------------------+
24 | // | Serial communitation functions |
25 | // +--------------------------------------------------------------------------+
26 |
27 | // usb setup
28 | void serial_init()
29 | {
30 | Serial.begin(BAUD_RATE);
31 | while (!Serial) {
32 | ; // wait for serial port to connect. Needed for native USB
33 | }
34 | delay(1000);
35 | }
36 |
37 | // Read integer command id from usb
38 | int read_command_id()
39 | {
40 | if (Serial.available() > 0) {
41 | return Serial.parseInt();
42 | }
43 | return 0;
44 | }
45 |
46 | // Send events by usb
47 | // Poor man's "Template argument deduction" not available in arduino.
48 | #define PRINT_CODE Serial.print(event); Serial.print('\t'); Serial.println(value);
49 | void send(int event, int value) { PRINT_CODE }
50 | void send(int event, float value) { PRINT_CODE }
51 | void send(int event, const __FlashStringHelper* value) { PRINT_CODE }
52 | void send(int event, const char* value) { PRINT_CODE }
53 | #undef PRINT_CODE
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/hardware/3dmodel/README.md:
--------------------------------------------------------------------------------
1 | ## 3D Model
2 |
3 | This directory contains a FreeCAD file: `base1.FCStd` which is an enclosure prototype. It was created with **FreeCAD 0.19_pre+**, **Assembly4**, and **Mnesarco Utils**, so in order to open it, you need to have those installed.
4 |
5 |
6 |
7 | There is also a script file: `vars.py` which contains main parameters of the enclosure, it must be in the same directory of `base1.FCStd`, so if you download `base1.FCStd` remember to download also `vars.py` and put both in the same directory.
--------------------------------------------------------------------------------
/hardware/3dmodel/base1.FCStd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mnesarco/HyperController/1efff3751a0c19eda55247764f2215e70af0c5c6/hardware/3dmodel/base1.FCStd
--------------------------------------------------------------------------------
/hardware/3dmodel/vars.py:
--------------------------------------------------------------------------------
1 | SECTION = "Base"
2 | base_l = 175
3 | base_t = 19
4 | base_w = 180
5 | big_round = 76.2
6 | round = 6.35
7 |
8 | SECTION = "Buttons"
9 | buttons_angle = 80
10 | buttons_l = 70
11 | buttons_w = 30
12 | push_size = 10
13 |
14 | SECTION = "Joystick"
15 | joystick1_margin_in = 25
16 | joystick1_margin_left = 20
17 | joystick1_margin_out = 50
18 | joystick1_margin_right = 15
19 | joystick1_margin_top = 30
20 | joystick_h1 = 17
21 | joystick_h2 = 35
22 | joystick_l = 33
23 | joystick_sep = 25
24 | joystick_w = 26
25 |
26 | SECTION = "Enclosure"
27 | top_wall = 5
28 | fillet = 6.25
29 |
30 |
--------------------------------------------------------------------------------
/hardware/axes.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mnesarco/HyperController/1efff3751a0c19eda55247764f2215e70af0c5c6/hardware/axes.pdf
--------------------------------------------------------------------------------
/hardware/labels.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mnesarco/HyperController/1efff3751a0c19eda55247764f2215e70af0c5c6/hardware/labels.pdf
--------------------------------------------------------------------------------
/hardware/logo.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mnesarco/HyperController/1efff3751a0c19eda55247764f2215e70af0c5c6/hardware/logo.pdf
--------------------------------------------------------------------------------
/hardware/schema.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mnesarco/HyperController/1efff3751a0c19eda55247764f2215e70af0c5c6/hardware/schema.pdf
--------------------------------------------------------------------------------