Skip to content

Commit

Permalink
Changed Predefined settings files and added some only for V3. Added d…
Browse files Browse the repository at this point in the history
…ouble press threshold/time variable and documentation.
  • Loading branch information
JacksonSmith43 committed Apr 29, 2024
1 parent dd77cad commit 8036da6
Show file tree
Hide file tree
Showing 38 changed files with 2,328 additions and 101 deletions.
1 change: 1 addition & 0 deletions FabiWare/FabiWare.ino
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const struct SlotSettings defaultSlotSettings = {
0x0000FF, // default slot color: blue
"en_US", // en_US as default keyboard layout.
500, // Threshold for long button press.
500, // Threshold/time for double press for slot change.
};


Expand Down
1 change: 1 addition & 0 deletions FabiWare/FlipWare.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct SlotSettings {
uint32_t sc; // slotcolor (0x: rrggbb)
char kbdLayout[6];
uint16_t lp; // Threshold long button press.
uint16_t dp; // Threshold/Time for double press for slot change.
};

/**
Expand Down
13 changes: 13 additions & 0 deletions FabiWare/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const struct atCommandType atCommands[] PROGMEM = {
{"KR" , PARTYPE_STRING}, {"RA" , PARTYPE_NONE }, {"KL" , PARTYPE_STRING },
/***** Long press time/threshold. *****/
{"LP", PARTYPE_UINT},
/***** Double press time/threshold. *****/
{"DP", PARTYPE_UINT},

/***** slots *****/
{"SA" , PARTYPE_STRING}, {"LO" , PARTYPE_STRING}, {"LA" , PARTYPE_NONE }, {"LI" , PARTYPE_NONE },
Expand Down Expand Up @@ -244,6 +246,17 @@ void performCommand (uint8_t cmd, int16_t par1, char * keystring, int8_t periodi
case CMD_LP:
slotSettings.lp = par1;
break;

case CMD_DP:
slotSettings.dp = par1;
/* mousePress(MOUSE_LEFT);
delay(DEFAULT_CLICK_TIME);
mouseRelease(MOUSE_LEFT);
delay(DEFAULT_CLICK_TIME);
mousePress(MOUSE_LEFT);
delay(DEFAULT_CLICK_TIME);
mouseRelease(MOUSE_LEFT);*/
break;

case CMD_RA:
release_all();
Expand Down
3 changes: 2 additions & 1 deletion FabiWare/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
Currently supported: de_DE, en_US, es_ES, fr_FR, it_IT, sv_SE, da_DK.
AT LP <uint> Long press threshold AKA long press should be active once that time (in [ms]) has been reached.
AT DP <uint> Thrshold for Slot change by double press. In [ms].
Housekeeping commands:
Expand Down Expand Up @@ -166,7 +167,7 @@ enum atCommands {
CMD_ID, CMD_BM, CMD_CL, CMD_CR, CMD_CM, CMD_CD, CMD_PL, CMD_PR, CMD_PM, CMD_HL, CMD_HR, CMD_HM,
CMD_RL, CMD_RR, CMD_RM, CMD_TL, CMD_TR, CMD_TM, CMD_WU, CMD_WD, CMD_WS, CMD_MX, CMD_MY, CMD_JX,
CMD_JY, CMD_JZ, CMD_JT, CMD_JS, CMD_JP, CMD_JR, CMD_JH, CMD_KW, CMD_KP, CMD_KH, CMD_KT, CMD_KR,
CMD_RA, CMD_KL, CMD_LP, CMD_SA, CMD_LO, CMD_LA, CMD_LI, CMD_NE, CMD_DE, CMD_RS, CMD_RE, CMD_NC, CMD_BT,
CMD_RA, CMD_KL, CMD_LP, CMD_DP, CMD_SA, CMD_LO, CMD_LA, CMD_LI, CMD_NE, CMD_DE, CMD_RS, CMD_RE, CMD_NC, CMD_BT,
CMD_SC, CMD_SR, CMD_ER, CMD_CA, CMD_MA, CMD_WA, CMD_TS, CMD_TP, CMD_SP, CMD_SS, CMD_IR, CMD_IP,
CMD_IH, CMD_IS, CMD_IC, CMD_IW, CMD_IL, CMD_IT,
NUM_COMMANDS
Expand Down
60 changes: 38 additions & 22 deletions FabiWare/modes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ void handleUserInteraction() {
int longPressButtonThreshold;

// check sip/puff activities
if (sensorData.pressure > previousPressure) pressureRising = 1;
else pressureRising = 0;
if (sensorData.pressure < previousPressure) pressureFalling = 1;
else pressureFalling = 0;
if (sensorData.pressure > previousPressure)
pressureRising = 1;
else
pressureRising = 0;
if (sensorData.pressure < previousPressure)
pressureFalling = 1;
else
pressureFalling = 0;
previousPressure = sensorData.pressure;

strongDirThreshold = STRONGMODE_MOUSE_JOYSTICK_THRESHOLD;
Expand All @@ -73,14 +77,15 @@ void handleUserInteraction() {
case STRONG_MODE_ENTER_STRONGPUFF: // puffed strong, wait for release
if (sensorData.pressure < slotSettings.tp)
waitStable++;
else waitStable = 0;
else
waitStable = 0;
if (waitStable >= STRONGMODE_STABLETIME)
strongSipPuffState = STRONG_MODE_STRONGPUFF_ACTIVE;
break;

case STRONG_MODE_STRONGPUFF_ACTIVE: // strong puff mode active
isHandled = 0;
//check if strong-puff + button 2/3/4/5 pressed
// check if strong-puff + button 2/3/4/5 pressed
///@note if changing, check for indices of STRONGPUFF_x_BUTTON, i & input map!
for (uint8_t i = 1; i <= 4; i++) {
if (digitalRead(input_map[i]) == LOW) {
Expand All @@ -107,14 +112,15 @@ void handleUserInteraction() {
case STRONG_MODE_ENTER_STRONGSIP: // sipped strong, wait for release
if (sensorData.pressure > slotSettings.ts)
waitStable++;
else waitStable = 0;
else
waitStable = 0;
if (waitStable >= STRONGMODE_STABLETIME)
strongSipPuffState = STRONG_MODE_STRONGSIP_ACTIVE;
break;

case STRONG_MODE_STRONGSIP_ACTIVE: // strong sip mode active
isHandled = 0;
//check if strong-sip + button 2/3/4/5 pressed
// check if strong-sip + button 2/3/4/5 pressed
///@note if changing, check for indices of STRONGSIP_x_BUTTON, i & input map!
for (uint8_t i = 1; i <= 4; i++) {
if (digitalRead(input_map[i]) == LOW) {
Expand Down Expand Up @@ -148,13 +154,13 @@ void handleUserInteraction() {
sipState = 0;
}
break;
default: break;
default:
break;
}


if (strongSipPuffState == STRONG_MODE_IDLE) {

//handle normal sip and puff actions
// handle normal sip and puff actions
switch (puffState) {
case SIP_PUFF_STATE_IDLE:
if (sensorData.pressure > slotSettings.tp) // handle single puff actions
Expand All @@ -172,11 +178,13 @@ void handleUserInteraction() {
handlePress(PUFF_BUTTON);
puffState = SIP_PUFF_STATE_PRESSED;
}
} else if (puffCount) puffCount--;
} else if (puffCount)
puffCount--;
break;

case SIP_PUFF_STATE_PRESSED:
if (puffCount) puffCount--;
if (puffCount)
puffCount--;
if ((sensorData.pressure < slotSettings.tp) && (!puffCount)) {
handleRelease(PUFF_BUTTON);
puffState = 0;
Expand All @@ -200,46 +208,46 @@ void handleUserInteraction() {
handlePress(SIP_BUTTON);
sipState = SIP_PUFF_STATE_PRESSED;
}
} else if (sipCount) sipCount--;
} else if (sipCount)
sipCount--;
break;

case SIP_PUFF_STATE_PRESSED:
if (sipCount) sipCount--;
if (sipCount)
sipCount--;
if ((sensorData.pressure > slotSettings.ts) && (!sipCount)) {
handleRelease(SIP_BUTTON);
sipState = 0;
}
}
}


// check physical buttons 1-5 (only if not handled by any special sip/puff state)
if (strongSipPuffState == STRONG_MODE_IDLE) {
uint16_t thresholdForLongPress = slotSettings.lp;
uint16_t thresholdForLongPress = slotSettings.lp;
uint16_t thresholdDoublePress = slotSettings.dp;
static unsigned long buttonPressStartTime[NUMBER_OF_PHYSICAL_BUTTONS] = { 0 }; // Stores the start time of button presses. So that it can distinguish between the first time a button has been pressed.

for (int i = 0; i < NUMBER_OF_PHYSICAL_BUTTONS; i++) { // update button press / release events

if (buttons[LONG_PRESS_BUTTON_1 + i].mode == CMD_NC) { // Makes sure that that specific button does not have a command (KEY_SPACE) in place.
handleButton(i, !digitalRead(input_map[i])); // Short press.

} else {
if (digitalRead(input_map[i]) == LOW) { // Button has been pressed.
buttonStates |= (1 << i); // Which state is used can be seen using the command AT SR (with Serial Monitor). Also visualises it in the WebGUI.

if (buttonPressStartTime[i] == 0) { //save press timestamp, only if not set already
if (buttonPressStartTime[i] == 0) { // save press timestamp, only if not set already
buttonPressStartTime[i] = millis(); // Saves the time, when the button was pressed.
}

if ((millis() - buttonPressStartTime[i]) >= thresholdForLongPress) { //already a long press?
if ((millis() - buttonPressStartTime[i]) >= thresholdForLongPress) { // already a long press?
handleButton(LONG_PRESS_BUTTON_1 + i, 1); // Long press.
}

} else { // When the button has been released, HIGH.

buttonStates &= ~(1 << i);

if ((millis() - buttonPressStartTime[i]) < thresholdForLongPress) { //was it a short press? If yes, trigger immediately
if ((millis() - buttonPressStartTime[i]) < thresholdForLongPress) { // was it a short press? If yes, trigger immediately
handlePress(i);
handleRelease(i);
}
Expand All @@ -249,5 +257,13 @@ void handleUserInteraction() {
}
}
}
// Double press stuff.
/* for (int i = 0; i < NUMBER_OF_PHYSICAL_BUTTONS; i++)
{ // Created a different one because it avoids errors.
if (input == doubleClick)
{
}
}*/
}
}
12 changes: 6 additions & 6 deletions Settings/1switch-LongpressTest (USB).set
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Slot:moveUp
AT TT 1000
AT LP 1000
AT AP 5
AT AR 2
AT AI 1
Expand All @@ -10,7 +10,7 @@ AT TP 1023
AT BM 1
AT KH KEY_UP
AT BM 2
AT NC
AT NE
AT BM 3
AT NC
AT BM 4
Expand All @@ -20,7 +20,7 @@ AT NC
AT BM 6
AT NC
AT BM 7
AT NE
AT NC
AT BM 8
AT NC
AT BM 9
Expand All @@ -33,7 +33,7 @@ AT BT 1
AT SC 0x036572

Slot:moveDown
AT TT 600
AT DP 600
AT AP 5
AT AR 2
AT AI 1
Expand All @@ -46,15 +46,15 @@ AT KH KEY_DOWN
AT BM 2
AT NC
AT BM 3
AT NC
AT NE
AT BM 4
AT NC
AT BM 5
AT NC
AT BM 6
AT NC
AT BM 7
AT NE
AT NC
AT BM 8
AT NC
AT BM 9
Expand Down
8 changes: 4 additions & 4 deletions Settings/1switch-Mouse (USB).set
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Slot:moveRight
AT TT 0
AT DP 0
AT AP 5
AT AR 2
AT AI 1
Expand Down Expand Up @@ -33,7 +33,7 @@ AT BT 1
AT SC 0x003e8f

Slot:moveDown
AT TT 0
AT DP 0
AT AP 5
AT AR 2
AT AI 1
Expand Down Expand Up @@ -67,7 +67,7 @@ AT BT 1
AT SC 0x9e8400

Slot:moveLeft
AT TT 0
AT DP 0
AT AP 5
AT AR 2
AT AI 1
Expand Down Expand Up @@ -101,7 +101,7 @@ AT BT 1
AT SC 0x2d8000

Slot:moveUp
AT TT 0
AT DP 0
AT AP 5
AT AR 2
AT AI 1
Expand Down
Loading

0 comments on commit 8036da6

Please sign in to comment.