Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

track and return Operating Mode with BLE #1553

Merged
merged 4 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions source/Core/BSP/Pinecilv2/ble_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "log.h"
#include "uuid.h"

#include "OperatingModes.h"
#include "USBPD.h"
#include "ble_characteristics.h"
#include "ble_handlers.h"
Expand All @@ -30,7 +31,8 @@
#include "pd.h"
#endif

extern TickType_t lastMovementTime;
extern TickType_t lastMovementTime;
extern OperatingMode currentMode;

int ble_char_read_status_callback(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset) {
if (attr == NULL || attr->uuid == NULL) {
Expand Down Expand Up @@ -123,6 +125,9 @@ int ble_char_read_status_callback(struct bt_conn *conn, const struct bt_gatt_att
case 13:
// Operating mode
// TODO: Needs tracking
temp = currentMode;
memcpy(buf, &temp, sizeof(temp));
return sizeof(temp);
break;
case 14:
// Estimated watts
Expand Down Expand Up @@ -237,4 +242,4 @@ int ble_char_write_setting_value_callback(struct bt_conn *conn, const struct bt_
}
MSG("Unhandled attr write %d | %d\n", (uint32_t)attr->uuid, uuid_value);
return 0;
}
}
2 changes: 2 additions & 0 deletions source/Core/Threads/OperatingModes/DebugMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
extern osThreadId GUITaskHandle;
extern osThreadId MOVTaskHandle;
extern osThreadId PIDTaskHandle;
extern OperatingMode currentMode;

void showDebugMenu(void) {
currentMode = OperatingMode::debug;
uint8_t screen = 0;
ButtonState b;
for (;;) {
Expand Down
3 changes: 3 additions & 0 deletions source/Core/Threads/OperatingModes/HomeScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
uint8_t buttonAF[sizeof(buttonA)];
uint8_t buttonBF[sizeof(buttonB)];
uint8_t disconnectedTipF[sizeof(disconnectedTip)];
extern OperatingMode currentMode;

void renderHomeScreenAssets(void) {

Expand All @@ -29,6 +30,7 @@ void drawHomeScreen(bool buttonLockout) {
renderHomeScreenAssets();

for (;;) {
currentMode = OperatingMode::idle;
ButtonState buttons = getButtonState();
if (buttons != BUTTON_NONE) {
OLED::setDisplayState(OLED::DisplayState::ON);
Expand Down Expand Up @@ -63,6 +65,7 @@ void drawHomeScreen(bool buttonLockout) {
}
break;
case BUTTON_B_SHORT:
currentMode = OperatingMode::settings;
enterSettingsMenu(); // enter the settings menu
{
OLED::useSecondaryFramebuffer(true);
Expand Down
8 changes: 8 additions & 0 deletions source/Core/Threads/OperatingModes/OperatingModes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Created by Thomas White on 3/02/2023.
//

#include "OperatingModes.h"

// Global variables
OperatingMode currentMode = OperatingMode::idle;
7 changes: 7 additions & 0 deletions source/Core/Threads/OperatingModes/OperatingModes.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ extern "C" {
#endif

// Exposed modes
enum OperatingMode {
idle = 0,
soldering = 1,
sleeping = 2,
settings = 3,
debug = 4
};

void performCJCC(void); // Used to calibrate the Cold Junction offset
void gui_solderingTempAdjust(void); // For adjusting the setpoint temperature of the iron
Expand Down
3 changes: 3 additions & 0 deletions source/Core/Threads/OperatingModes/Sleep.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "OperatingModes.h"

extern OperatingMode currentMode;

int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) {
// Drop to sleep temperature and display until movement or button press
currentMode = OperatingMode::sleeping;

for (;;) {
// user moved or pressed a button, go back to soldering
Expand Down
4 changes: 3 additions & 1 deletion source/Core/Threads/OperatingModes/Soldering.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

#include "OperatingModes.h"

extern bool heaterThermalRunaway;
extern bool heaterThermalRunaway;
extern OperatingMode currentMode;

void gui_solderingMode(uint8_t jumpToSleep) {
/*
Expand All @@ -20,6 +21,7 @@ void gui_solderingMode(uint8_t jumpToSleep) {
*/
bool boostModeOn = false;
bool buttonsLocked = false;
currentMode = OperatingMode::soldering;

if (jumpToSleep) {
if (gui_SolderingSleepingMode(jumpToSleep == 2, true) == 1) {
Expand Down