Skip to content

Commit

Permalink
Merge pull request #107 from voroshkov/dev
Browse files Browse the repository at this point in the history
merge powerdown feature by @Smeat to master
  • Loading branch information
voroshkov authored Jul 4, 2019
2 parents c86bb51 + 1bce858 commit 514fddd
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Android/ChorusRFLaptimer/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "app.andrey_voroshkov.chorus_laptimer"
minSdkVersion 16
targetSdkVersion 26
versionCode 24
versionName "0.7.12"
versionCode 25
versionName "0.7.14"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
archivesBaseName = "ChorusRFLaptimer"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,7 @@ public static void applyInAppPreferences() {
}
}

if (app.deviceStates != null) {
String statuses = app.preferences.getString(DEVICE_ENABLED, "");
if (!statuses.equals("")) {
String[] statusesArray = TextUtils.split(statuses, STRING_ITEMS_DELIMITER);
int statusesCount = statusesArray.length;
for(int i = 0; i < app.deviceStates.size(); i++) {
if (i < statusesCount) {
app.changeDeviceEnabled(i, Boolean.parseBoolean(statusesArray[i]));
}
}
}
}

}

public static void applyDeviceDependentPreferences() {
Expand Down Expand Up @@ -282,6 +271,19 @@ public static void applyDeviceDependentPreferences() {
}
}

String enabledStatuses = app.preferences.getString(DEVICE_ENABLED, "");
if (!enabledStatuses.equals("")) {
String[] enabledStatusesArray = TextUtils.split(enabledStatuses, STRING_ITEMS_DELIMITER);
int statusesCount = enabledStatusesArray.length;
for(int i = 0; i < app.deviceStates.size(); i++) {
if (i < statusesCount) {
boolean prefEnabledStatus = Boolean.parseBoolean(enabledStatusesArray[i]);
app.changeDeviceEnabled(i, prefEnabledStatus);
app.sendBtCommand("R" + String.format("%X", i) + "A" + (prefEnabledStatus ? "1" : "0"));
}
}
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});

viewHolder.isPilotEnabled.setOnClickListener(new CompoundButton.OnClickListener() {
@Override
public void onClick(View v) {
AppState.getInstance().sendBtCommand("R" + deviceId + "A" + (((CompoundButton)v).isChecked() ? 1 : 0));
}
});

Boolean isEnabled = AppState.getInstance().getIsPilotEnabled(position);
viewHolder.isPilotEnabled.setChecked(isEnabled);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ public static String btDataChunkParser(String chunk) {
int apiVersion = Integer.parseInt(chunk.substring(3,7), 16);
AppState.getInstance().checkApiVersion(moduleId, apiVersion);
break;
case 'A':
int isModuleActive = Integer.parseInt(chunk.substring(3,4), 16);
AppState.getInstance().changeDeviceEnabled(moduleId, (isModuleActive != 0));
break;
}
} else if (dest == 'R') {

Expand Down
31 changes: 28 additions & 3 deletions Arduino/chorus_rf_laptimer/chorus_rf_laptimer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TODO: there's possible optimization in send queue:
remove already existing items from queue
*/

#define API_VERSION 5 // version number to be increased with each API change (int16)
#define API_VERSION 6 // version number to be increased with each API change (int16)

#define EXPERIMENTAL_FEATURES_AVAILABLE // comment out if current code version doesn't contain any experimental features

Expand Down Expand Up @@ -108,6 +108,7 @@ const uint16_t musicNotes[] = {
#define CONTROL_SOUND 'S'
#define CONTROL_THRESHOLD 'T'
#define CONTROL_EXPERIMENTAL_MODE 'E'
#define CONTROL_MODULE_ACTIVE 'A'
// get only:
#define CONTROL_GET_API_VERSION '#'
#define CONTROL_GET_ALL_DATA 'a'
Expand All @@ -131,6 +132,7 @@ const uint16_t musicNotes[] = {
#define RESPONSE_SOUND 'S'
#define RESPONSE_THRESHOLD 'T'
#define RESPONSE_EXPERIMENTAL_MODE 'E'
#define RESPONSE_MODULE_ACTIVE 'A'

#define RESPONSE_API_VERSION '#'
#define RESPONSE_RSSI 'r'
Expand Down Expand Up @@ -158,7 +160,8 @@ const uint16_t musicNotes[] = {
#define SEND_VOLTAGE 13
#define SEND_THRESHOLD_SETUP_MODE 14
#define SEND_EXPERIMENTAL_MODE 15
#define SEND_END_SEQUENCE 16
#define SEND_MODULE_ACTIVE 16
#define SEND_END_SEQUENCE 17
// following items don't participate in "send all items" response
#define SEND_LAST_LAPTIMES 100
#define SEND_TIME 101
Expand Down Expand Up @@ -280,6 +283,7 @@ uint8_t thresholdSetupMode = 0;
uint8_t experimentalMode = 0;
uint16_t frequency = 0;
uint32_t millisUponRequest = 0;
uint8_t isModuleActive = 1; // 0 means this module is inactive and the VRX is disabled

//----- read/write bufs ---------------------------
#define READ_BUFFER_SIZE 30
Expand Down Expand Up @@ -453,9 +457,13 @@ void loop() {
if (send4BitsToSerial(RESPONSE_EXPERIMENTAL_MODE, experimentalMode)) {
onItemSent();
}
case 16: // SEND_MODULE_ACTIVE
if (send4BitsToSerial(RESPONSE_MODULE_ACTIVE, isModuleActive)) {
onItemSent();
}
// Below is a termination case, to notify that data for CONTROL_GET_ALL_DATA is over.
// Must be the last item in the sequence!
case 16: // SEND_END_SEQUENCE
case 17: // SEND_END_SEQUENCE
if (send4BitsToSerial(RESPONSE_END_SEQUENCE, 1)) {
onItemSent();
isSendingData = 0;
Expand Down Expand Up @@ -687,6 +695,12 @@ void handleSerialControlInput(uint8_t *controlData, uint8_t length) {
addToSendQueue(SEND_EXPERIMENTAL_MODE);
isConfigured = 1;
break;
case CONTROL_MODULE_ACTIVE:
valueToSet = TO_BYTE(controlData[1]);
setModuleActive(valueToSet);
addToSendQueue(SEND_MODULE_ACTIVE);
isConfigured = 1;
break;
}
} else { // get value and other instructions
switch (controlByte) {
Expand Down Expand Up @@ -879,6 +893,17 @@ void setExperimentalMode(uint8_t mode) {
#endif
}
// ----------------------------------------------------------------------------
void setModuleActive(uint8_t active) {
isModuleActive = active;
if(active) {
resetModule();
// We need to set the freqency again on power up
setModuleFrequency(frequency);
} else {
powerDownModule();
}
}

void setupThreshold(uint8_t phase) {
// this process assumes the following:
// 1. before the process all VTXs are turned ON, but are distant from the Chorus device, so that Chorus sees the "background" rssi values only
Expand Down
35 changes: 34 additions & 1 deletion Arduino/chorus_rf_laptimer/rx5808spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ void PowerDownFeatures(uint32_t features)
digitalLow(slaveSelectPin);
delayMicroseconds(1);

// send 0x0A
SERIAL_SENDBIT0();
SERIAL_SENDBIT0();
SERIAL_SENDBIT1();
SERIAL_SENDBIT0();
SERIAL_SENDBIT1();

Expand Down Expand Up @@ -113,6 +114,38 @@ void setupSPIpins() {
PowerDownFeatures(PD_IFAF | PD_DIV4 | PD_5GVCO | PD_REG1D8 | PD_DIV80 | PD_PLL1D8 | PD_IF_DEMOD | PD_VAMP | PD_VCLAMP | PD_MIXER | PD_IFABF | PD_6M5 | PD_AU6M5 | PD_6M | PD_AU6M | PD_SYN | PD_REGIF);
}

void powerDownModule() {
// Power down all features
PowerDownFeatures(PD_PLL1D8 | PD_DIV80 | PD_MIXER | PD_IFABF | PD_REG1D8 | PD_6M5 | PD_AU6M5 | PD_6M | PD_AU6M | PD_SYN | PD_5GVCO | PD_DIV4 | PD_DIV4 | PD_BC | PD_REGIF | PD_REGBS | PD_RSSI_SQUELCH | PD_IFAF | PD_IF_DEMOD | PD_VAMP | PD_VCLAMP);
}

// Reset needs to be used to wake the module up if it is completely powered down
void resetModule() {
digitalLow(spiClockPin);
digitalLow(slaveSelectPin);
delayMicroseconds(1);

// State register 0x0F
SERIAL_SENDBIT1();
SERIAL_SENDBIT1();
SERIAL_SENDBIT1();
SERIAL_SENDBIT1();

// write
SERIAL_SENDBIT1();

// set all bits to zero -> reset
for (int i = 20; i > 0; i--) {
SERIAL_SENDBIT0();
}

// Finished clocking data in
digitalHigh(slaveSelectPin);
delayMicroseconds(1);

delay(MIN_TUNE_TIME);
}

uint16_t setModuleFrequency(uint16_t frequency) {
uint8_t i;
uint16_t channelData;
Expand Down
Binary file modified docs/ChorusAPI.xlsx
Binary file not shown.

0 comments on commit 514fddd

Please sign in to comment.