Compare commits

..

15 Commits

Author SHA1 Message Date
Ben V. Brown
3d1d47acee Long overdue additions
Closes #329
Closes #324
Closes #331
Should Close #321
Should Close #301
2018-07-27 19:21:12 +10:00
Julius Vitkauskas
e598d1cbbb Update Lithuanian translation (#335) 2018-07-27 16:22:44 +10:00
nils måsén
20d1874aee Add Swedish translation (#318)
* Swedish language
2018-06-20 08:43:12 +10:00
Alessandro Gatti
030a714ff2 Initialise variables before usage / Cleanup (#315) 2018-06-17 09:41:53 +10:00
L0laapk3
67066f218f added dutch translation (#307)
* added dutch translation

* fixed caps

* dutch language improvements

* dutch language improvements
2018-06-02 10:44:26 +10:00
Alessandro Gatti
50fe2bcff1 Shrink GUI code and simplify LCD rotation. (#300)
* Inline more methods in FRToSI2C.

* Shrink down GUI code.

* Simplify LCD rotation handling.

* Extract version headers.
2018-05-26 14:21:42 +10:00
dogtopus
a576f44ba2 Add binary generation (#310) 2018-05-26 14:21:06 +10:00
Ben V. Brown
74de59c235 Update readme 2018-05-25 22:24:20 +10:00
Valmantas Palikša
fc669dc274 Use LTO to save up to 7k of flash (#305) 2018-05-18 18:54:57 +10:00
Ben V. Brown
b0b512030f Fix up menu icons
Sorry this got lost 😠
Fixed now :)
Fixes #214 finally.
2018-05-11 13:10:36 +10:00
Ben V. Brown
48cc1ff8cc Add auto-repeat to temp adjust
Fixes #285
2018-05-11 13:06:10 +10:00
Ben V. Brown
c9a56392a0 Bring back cooling blink
Fixes #289
2018-05-11 13:01:21 +10:00
Ben V. Brown
b6b207568c Delay I2C DMA thread on oled slightly
The flickering on the LCD screen was caused by the OLED DMA taking slightly longer than the delays, so the tail end would flicker if the buffer was cleared before it finished writing.

In future may want to double buffer the LCD.

Fixes #290
2018-05-11 12:54:55 +10:00
Alessandro Gatti
8bf65351ea Shrink OLED driver code. (#296)
* Precompute command header.
* Update data header on-demand.
* Use more aggressive inlining.
* Do not clear number buffer twice.
2018-05-11 12:32:37 +10:00
Alessandro Gatti
215fe8e9e8 Reduce code size for accelerometer support (#288)
* Reduce the LIS2DH12 driver's code size.
* Reduce the MMA8652FC driver's code size.
* Make orientation detection smaller.


* Inlined C++ class constructor.
* De-unroll I2C register writes.
* Removed unused setSensitivity method.
2018-05-10 10:02:29 +10:00
17 changed files with 1076 additions and 842 deletions

View File

@@ -1,10 +1,12 @@
# TS100
This is a complete rewrite of the open source software for the ts100 soldering iron.
The version two fork of this code has no shared code with the original firmware from Miniware (E-design) group.
This project is considered feature complete for use as a soldering iron, *so please suggest any feature improvements you would like!*
A short(ish) video that goes through every single menu option in the firmware is available [over here](https://www.youtube.com/watch?v=WlnpboYfxNk).
This video was created on an earlier 1.x version of the firmware, so alot has changed and a new video will be coming soon for the 2.x fork.
A short(ish) video that goes through every single menu option in the firmware is available [over here](https://www.youtube.com/watch?v=WlnpboYfxNk).
This video was created on an earlier 1.x version of the firmware, so alot has changed but should be fairly intuitive as the menu has vastly improved.
*This firmware does **NOT** support the usb port while running for changing settings. This is done through the onscreen menu only. Logos are edited using the tool or python script and uploaded in DFU mode.*
@@ -12,6 +14,7 @@ This video was created on an earlier 1.x version of the firmware, so alot has ch
Please calibrate your irons voltage reading when you are using a lithium battery after any firmware upgrades.*
## Features
* PID iron temperature control
* Automatic sleep with selectable sensitivity
* Motion wake support
@@ -26,10 +29,11 @@ Please calibrate your irons voltage reading when you are using a lithium battery
* Battery charge level indicatior if power source set to a lipo cell count.
* Custom bootup logo support
* Automatic LCD rotation based on orientation
* Supports both the version 1 and version 2 hardware
## Upgrading your ts100 iron
This is completely safe, if it goes wrong just put the .hex file from the official website onto the unit and your back to the old firmware. Downloads for the hex files to flash are available on the [releases page.](https://github.com/Ralim/ts100/releases) The file you want is called *ts100.hex* unless you want the translations, they are ts100_*language short name*.hex.
This is completely safe, if it goes wrong just put the .hex file from the official website onto the unit and your back to the old firmware. Downloads for the hex files to flash are available on the [releases page.](https://github.com/Ralim/ts100/releases) The file you want is called *ts100_EN.hex* unless you want the translations, they are ts100_*language short name*.hex.
Officially the bootloader on the iron only works under windows. However, users have reported that it does work under Mac, and can be made to work under Linux *sometimes*. Details over on the [wiki page](https://github.com/Ralim/ts100/wiki/Upgrading-Firmware).
@@ -55,13 +59,15 @@ There are further instructions on the [wiki](https://github.com/Ralim/ts100/wiki
This new firmware uses a new menu system to allow access to the settings on the device.
When on the main screen, the unit shows prompts for the two most common operations.
* Pressing the button near the tip enters soldering mode
* Pressing the button near the USB enters the settings menu.
* Holding the button near the tip will enter soldering temperature adjust mode (This is the same as the one in the soldering menu, just to let you edit before heating up).
* Holding the button near the USB end will show the firmware version details.
## Soldering mode
In this mode the iron works as you would expect, pressing either button will take you to a temperature change screen.
In this mode the iron works as you would expect, pressing either button will take you to a temperature change screen.
Use each button to go up and down in temperature. Pressing both buttons will exit you from the temperature menu (or wait 3 seconds and it will time out).
Pressing both buttons or holding the button near the USB will exit the soldering mode.
Holding the button at the front of the iron will enter boost mode (if enabled).
@@ -70,28 +76,17 @@ Holding the button at the front of the iron will enter boost mode (if enabled).
This menu allows you to cycle through all the options and set their values.
The button near the USB cycles through the options, and the one near the tip changes the selected option.
Note that settings are not saved until you exit the menu, and some settings such as screen flip do not apply until a power cycle is applied.
If you leave the unit alone (ie don't press any buttons) on a setting, after 3 seconds the screen will scroll a longer version of the name
Note that settings are not saved until you exit the menu.
If you leave the unit alone (ie don't press any buttons) on a setting, after 3 seconds the screen will scroll a rough description of the setting.
* PWRSC -> Power source, select a cell count if using a LiPo, or DC to disable the shutdown. (Sets it to minimum of 10V).
* STMP -> The temperature the unit drops to in sleep mode
* SLTME -> Sleep time, how long it takes before the unit goes to sleep
* SHTME -> Shutdown Time, how long the unit will wait after movement before shutting down completely
* MSENSE -> Motion Sensitivity,0*9,0 means motion sensing is turned off, 9 is most sensitive, 1 is least sensitive (ie takes more movement to trigger)
* ADVDSP -> Enable the advanced display (shows more details)
* DSPROT -> Display rotation mode, Automatic, Left handed or Right handed
* BOOST -> Enable boost mode
* BTMP -> Set the temperature for the boost mode
* ASART -> Automatically start the unit when power is applied (i.e. the unit will go straight into soldering mode)
* CLBLNK -> Blink the screen as an alert when cooling down
* TMP CAL -> Use to calibrate offset on the tip temperature
* RESET -> Use to force a complete reset on exit of the settings menu
* TMPUNIT -> Temperature unit, C or F
The menu is arranged so that the most often used settings are first.
With submenu's being selected to enter using the front button (as if you were going to change the setting).
Scrolling through the submenu will return you back to its entry location after you scroll through all of the options.
### Calibrating input voltage
Due to the tolerance on the resistors used for the input voltage divider, some irons can be up to 0.6V out on the voltage measurement.
Please calibrate your iron if you have any issues with the cutoff voltage.
Please calibrate your iron if you have any issues with the cutoff voltage.
Note that cutoff messages can also be triggered by using a power supply that is too weak and fails under the load of the iron.
This is more critical than before with the new cell count based cutout voltage.
@@ -99,19 +94,11 @@ To calibrate your Iron:
1. Measure the input voltage with a multimeter and note it down.
2. Connect the input to your iron.
3. On the home screen (showing iron symbol), press both buttons simultainiously.
4. The iron will now show the tip temperature.
5. Press the button near the soldering iron tip.
6. The screen will display the measured input voltage.
7. If this is the same as what you measured before skip to step 13
8. Otherwise, press the button near the USB end of the iron
9. The voltage will now slowly blink.
10. Use the buttons to adjust the reading up and down until it reads as close as possible to the voltage you measured earlier.
11. When it is reading as close as possible, press both buttons at once.
12. The screen will go back to just showing the input voltage.
13. Press the button near the tip of the iron to exit back to the live temperature display.
14. Press both buttons at once to exit back to the idle screen.
15. You're done. Enjoy your iron.
3. Enter the settings menu
4. Under the advanced submenu
5. Select the calibrate voltage option
6. Use the front and back buttons to adjust the displayed voltage to minimise the error to your origional measurement
7. Hold both buttons to save and exit to the menu
### Calibrating tip offset
@@ -120,13 +107,13 @@ Some tips will have an offset on their readings, to calibrate this out perform t
1. Connect power to your iron
2. Make sure the tip is at room temperature (ie. wait for a fair while after using the iron before calibration)
3. Enter the settings menu
4. Scroll down to *TMP CAL*
4. Scroll down to the advanced menu, and then the temperature calibration
5. Press the button to change the option (tip button)
6. The display will start to scroll a warning message to check that the tip is at ambient temperature!
7. Press the button near the tip of the iron to confirm.
8. The display will go to "...." for a short period of time as the unit measures the tip temperature and the handle temperature and compares them
9. The display will then go back to *TMP CAL*
10. Calibration is done, just exit the settings menu as normal
10. Calibration is done, just exit the settings menu as normal
11. You're done. Enjoy your iron.
### Boost mode
@@ -135,7 +122,6 @@ This allows you to change the front key (one near the tip) to become a boost but
The boost temperature is set in the settings menu.
## Thanks
If you love this firmware and want to continue my caffine addiction, you can do so here (or email me for other options) : https://paypal.me/RalimTek

View File

@@ -32,7 +32,7 @@ HEXFILE_DIR=Hexfile
OUTPUT_DIR=Objects
# code optimisation ------------------------------------------------------------
OPTIM=-Os -finline-small-functions -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections
OPTIM=-Os -flto -finline-small-functions -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections
# global defines ---------------------------------------------------------------
@@ -73,7 +73,7 @@ LINKER_FLAGS=-Wl,--gc-sections \
-mcpu=cortex-m3 \
-mthumb \
-mfloat-abi=soft \
-lm
-lm -Os -flto -Wl,--undefined=vTaskSwitchContext
# compiler flags ---------------------------------------------------------------
CPUFLAGS=-D GCC_ARMCM3 \
@@ -177,7 +177,7 @@ OUT_OBJS_CPP=$(addprefix $(OUTPUT_DIR)/,$(OBJS_CPP))
OUT_OBJS_S=$(addprefix $(OUTPUT_DIR)/,$(OBJS_S))
OUT_HEXFILE=$(addprefix $(HEXFILE_DIR)/,$(OUTPUT_EXE))
all: $(OUT_HEXFILE).hex
all: $(OUT_HEXFILE).hex $(OUT_HEXFILE).bin
#
# The rule to create the target directory
@@ -185,13 +185,17 @@ all: $(OUT_HEXFILE).hex
# Create hexfile
%.hex : %.elf
$(SIZE) -x $^
$(SIZE) $^
$(OBJCOPY) $^ -O ihex $@
%.bin : %.elf
$(SIZE) $^
$(OBJCOPY) $^ -O binary $@
$(OUT_HEXFILE).elf : $(OUT_OBJS) $(OUT_OBJS_CPP) $(OUT_OBJS_S) Makefile $(LDSCRIPT)
@test -d $(@D) || mkdir -p $(@D)
@echo Linking $(OUTPUT_EXE).elf
@$(CPP) $(CXXFLAGS) $(OUT_OBJS) $(OUT_OBJS_CPP) $(OUT_OBJS_S) $(LIBS) $(LINKER_FLAGS)
@$(CPP) $(CXXFLAGS) $(OUT_OBJS_S) $(OUT_OBJS) $(OUT_OBJS_CPP) $(LIBS) $(LINKER_FLAGS)
$(OUT_OBJS): $(OUTPUT_DIR)/%.o : %.c Makefile
@test -d $(@D) || mkdir -p $(@D)

View File

@@ -35,3 +35,5 @@ make -j16 lang=LT
rm -rf Objects/src
make -j16 lang=UA
rm -rf Objects/src
make -j16 lang=SR
rm -rf Objects/src

View File

@@ -11,20 +11,28 @@
#include "cmsis_os.h"
class FRToSI2C {
public:
FRToSI2C(I2C_HandleTypeDef* i2chandle);
void FRToSInit();
public:
FRToSI2C(I2C_HandleTypeDef *i2chandle) : i2c(i2chandle),
I2CSemaphore(nullptr) {
}
void FRToSInit() {
I2CSemaphore = xSemaphoreCreateBinary();
xSemaphoreGive(I2CSemaphore);
}
void CpltCallback(); //Normal Tx Callback
void Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize,
uint8_t *pData, uint16_t Size);
uint8_t *pData, uint16_t Size);
void Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
void Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size);
private:
I2C_HandleTypeDef* i2c;
private:
I2C_HandleTypeDef *i2c;
SemaphoreHandle_t I2CSemaphore;
};

View File

@@ -602,16 +602,20 @@ const uint8_t SettingsMenuIcons[] = {
// Soldering
//width = 16
//height = 16
0x00,0x02,0x04,0x08,0x12,0x24,0xC4,0x42,0x82,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x07,0x0A,0x14,0x28,0x50,0x60,0x00,
0x00, 0x02, 0x04, 0x08, 0x12, 0x24, 0xC4, 0x42, 0x82, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x02, 0x07, 0x0A, 0x14, 0x28, 0x50,
0x60, 0x00,
//Sleep
//width = 16
//height = 16
0x00,0xC6,0xE6,0xF6,0xBE,0x9E,0x8E,0x86,0x00,0x00,0x40,0x40,0xC0,0xC0,0xC0,0x00,
0x00,0x01,0x01,0x01,0x45,0x65,0x75,0x5D,0x4C,0x00,0x06,0x07,0x07,0x05,0x04,0x00,
0x00, 0xC6, 0xE6, 0xF6, 0xBE, 0x9E, 0x8E, 0x86, 0x00, 0x00,
0x40, 0x40, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x01, 0x01, 0x01,
0x45, 0x65, 0x75, 0x5D, 0x4C, 0x00, 0x06, 0x07, 0x07, 0x05,
0x04, 0x00,
@@ -624,14 +628,18 @@ const uint8_t SettingsMenuIcons[] = {
//Wrench
///width = 16
//height = 16
0x00,0x18,0x30,0x32,0x7E,0x7C,0xF0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x0F,0x3E,0x7E,0x4C,0x0C,0x18,0x00,
0x00, 0x18, 0x30, 0x32, 0x7E, 0x7C, 0xF0, 0xC0, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x03, 0x0F, 0x3E, 0x7E, 0x4C, 0x0C,
0x18, 0x00,
#ifdef NOTUSED
//Calibration (Not used, kept for future menu layouts)
//width = 16
//height = 16
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE8,0x70,0x7A,0x5E,0x8E,0x1C,0x30,0x00,
0x00,0x10,0x38,0x1C,0x0E,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE8, 0x70,
0x7A, 0x5E, 0x8E, 0x1C, 0x30, 0x00, 0x00, 0x10, 0x38, 0x1C,
0x0E, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
#endif
};

View File

@@ -10,16 +10,16 @@
#include "stm32f1xx_hal.h"
#include "FRToSI2C.hpp"
#include "LIS2DH12_defines.hpp"
#include "hardware.h"
class LIS2DH12 {
public:
LIS2DH12(FRToSI2C* i2cHandle);
LIS2DH12(FRToSI2C* i2cHandle) : i2c(i2cHandle) {}
void initalize();
uint8_t getOrientation();
Orientation getOrientation() { return static_cast<Orientation>((I2C_RegisterRead(LIS_INT2_SRC) >> 2) - 1); }
void getAxisReadings(int16_t *x, int16_t *y, int16_t *z);
private:
void setSensitivity(uint8_t threshold, uint8_t filterTime); // Sets the sensitivity of the unit
void I2C_RegisterWrite(uint8_t reg, uint8_t data);
uint8_t I2C_RegisterRead(uint8_t reg);
FRToSI2C* i2c;

View File

@@ -10,17 +10,18 @@
#include "stm32f1xx_hal.h"
#include "MMA8652FC_defines.h"
#include "FRToSI2C.hpp"
#include "hardware.h"
class MMA8652FC {
public:
MMA8652FC(FRToSI2C* i2cHandle);
MMA8652FC(FRToSI2C* i2cHandle) : i2c(i2cHandle) {}
void initalize(); // Initalize the system
uint8_t getOrientation();// Reads the I2C register and returns the orientation (true == left)
Orientation getOrientation();// Reads the I2C register and returns the orientation (true == left)
void getAxisReadings(int16_t *x, int16_t *y, int16_t *z);
private:
void setSensitivity(uint8_t threshold, uint8_t filterTime); // Sets the sensitivity of the unit
void I2C_RegisterWrite(uint8_t reg, uint8_t data);
uint8_t I2C_RegisterRead(uint8_t reg);

View File

@@ -12,6 +12,7 @@
#include <hardware.h>
#include "stm32f1xx_hal.h"
#include <stdbool.h>
#include <string.h>
#include "FRToSI2C.hpp"
#include "Font.h"
#ifdef __cplusplus
@@ -21,34 +22,67 @@ extern "C" {
#ifdef __cplusplus
}
#endif
#define DEVICEADDR_OLED (0x3c<<1)
#define OLED_WIDTH 96
#define DEVICEADDR_OLED (0x3c<<1)
#define OLED_WIDTH 96
#define FRAMEBUFFER_START 17
class OLED {
public:
OLED(FRToSI2C* i2cHandle); // Initialize Driver and store I2C pointer
OLED(FRToSI2C* i2cHandle); // Initialize Driver and store I2C pointer
void initialize(); // Startup the I2C coms (brings screen out of reset etc)
void refresh(); // Draw the buffer out to the LCD using the DMA Channel
// Draw the buffer out to the LCD using the DMA Channel
void refresh() {
i2c->Transmit( DEVICEADDR_OLED, screenBuffer, FRAMEBUFFER_START + (OLED_WIDTH * 2));
//DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms
//or we need to goto double buffering
}
void drawChar(char c, char preCursorCommand = '\0'); // Draw a character to a specific location
void displayOnOff(bool on); // Turn the screen on or not
// Turn the screen on or not
void displayOnOff(bool on) {
displayOnOffState = on;
screenBuffer[1] = on ? 0xAF : 0xAE;
}
void setRotation(bool leftHanded); // Set the rotation for the screen
bool getRotation(); // Get the current rotation of the LCD
// Get the current rotation of the LCD
bool getRotation() const {
return inLeftHandedMode;
}
void print(const char* string); // Draw a string to the current location, with current font
void setCursor(int16_t x, int16_t y); // Set the cursor location by pixels
void setCharCursor(int16_t x, int16_t y); //Set cursor location by chars in current font
// Set the cursor location by pixels
void setCursor(int16_t x, int16_t y) {
cursor_x = x;
cursor_y = y;
}
//Set cursor location by chars in current font
void setCharCursor(int16_t x, int16_t y) {
cursor_x = x * fontWidth;
cursor_y = y * fontHeight;
}
void setFont(uint8_t fontNumber); // (Future) Set the font that is being used
void drawImage(const uint8_t* buffer, uint8_t x, uint8_t width);
void drawImage(const uint8_t* buffer, uint8_t x, uint8_t width) {
drawArea(x, 0, width, 16, buffer);
}
// Draws an image to the buffer, at x offset from top to bottom (fixed height renders)
void printNumber(uint16_t number, uint8_t places);
// Draws a number at the current cursor location
void clearScreen(); // Clears the buffer
void drawBattery(uint8_t state); // Draws the battery level symbol
void drawCheckbox(bool state); // Draws a checkbox
// Clears the buffer
void clearScreen() {
memset(&screenBuffer[FRAMEBUFFER_START], 0, OLED_WIDTH * 2);
}
// Draws the battery level symbol
void drawBattery(uint8_t state) {
drawSymbol(3 + (state > 10 ? 10 : state));
}
// Draws a checkbox
void drawCheckbox(bool state) {
drawSymbol((state) ? 16 : 17);
}
void drawSymbol(uint8_t symbolID);//Used for drawing symbols of a predictable width
void drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
const uint8_t* ptr);
void fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
const uint8_t value);
void drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t* ptr); //Draw an area, but y must be aligned on 0/8 offset
void fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t value); //Fill an area, but y must be aligned on 0/8 offset
void drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,bool clear);
void drawHeatSymbol(uint8_t state);
private:
@@ -57,7 +91,6 @@ private:
FRToSI2C* i2c; //i2c Pointer
const uint8_t* currentFont; // Pointer to the current font used for rendering to the buffer
uint8_t screenBuffer[16 + 96 + 96 + 10]; // The data buffer
uint8_t* firstStripPtr; // Pointers to the strips to allow for buffer having extra content
uint8_t* secondStripPtr; //Pointers to the strips
bool inLeftHandedMode; // Whether the screen is in left or not (used for offsets in GRAM)
@@ -65,6 +98,7 @@ private:
uint8_t fontWidth, fontHeight;
int16_t cursor_x, cursor_y;
uint8_t displayOffset;
uint8_t screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
};
#endif /* OLED_HPP_ */

View File

@@ -13,6 +13,12 @@
extern "C" {
#endif
enum Orientation {
ORIENTATION_LEFT_HAND = 0,
ORIENTATION_RIGHT_HAND = 1,
ORIENTATION_FLAT = 3
};
#define KEY_B_Pin GPIO_PIN_6
#define KEY_B_GPIO_Port GPIOA
#define TMP36_INPUT_Pin GPIO_PIN_7

View File

@@ -7,11 +7,6 @@
#include "FRToSI2C.hpp"
FRToSI2C::FRToSI2C(I2C_HandleTypeDef* i2chandle) {
i2c = i2chandle;
I2CSemaphore = NULL;
}
void FRToSI2C::CpltCallback() {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
i2c->State = HAL_I2C_STATE_READY;//Force state reset
@@ -19,8 +14,6 @@ void FRToSI2C::CpltCallback() {
xSemaphoreGiveFromISR(I2CSemaphore, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
void FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
@@ -69,14 +62,7 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
} else {
NVIC_SystemReset();
}
}
}
void FRToSI2C::FRToSInit() {
I2CSemaphore = xSemaphoreCreateBinary();
xSemaphoreGive(I2CSemaphore);
}
void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t* pData, uint16_t Size) {

View File

@@ -7,39 +7,32 @@
#include <LIS2DH12.hpp>
#include "cmsis_os.h"
LIS2DH12::LIS2DH12(FRToSI2C* i2cHandle) {
i2c = i2cHandle;
}
typedef struct {
const uint8_t reg;
const uint8_t value;
} LIS_REG;
static const LIS_REG i2c_registers[] = {
{LIS_CTRL_REG1, 0x17}, // 25Hz
{LIS_CTRL_REG2, 0b00001000}, // Highpass filter off
{LIS_CTRL_REG3, 0b01100000}, // Setup interrupt pins
{LIS_CTRL_REG4, 0b00001000}, // Block update mode off, HR on
{LIS_CTRL_REG5, 0b00000010},
{LIS_CTRL_REG6, 0b01100010},
//Basically setup the unit to run, and enable 4D orientation detection
{LIS_INT2_CFG, 0b01111110}, //setup for movement detection
{LIS_INT2_THS, 0x28},
{LIS_INT2_DURATION, 64},
{LIS_INT1_CFG, 0b01111110},
{LIS_INT1_THS, 0x28},
{LIS_INT1_DURATION, 64}
};
void LIS2DH12::initalize() {
I2C_RegisterWrite(LIS_CTRL_REG1, 0x17); //25Hz
I2C_RegisterWrite(LIS_CTRL_REG2, 0b00001000); //Highpass filter off
I2C_RegisterWrite(LIS_CTRL_REG3, 0b01100000); //Setup interrupt pins
I2C_RegisterWrite(LIS_CTRL_REG4, 0b00001000); //Block update mode off,HR on
I2C_RegisterWrite(LIS_CTRL_REG5, 0b00000010);
I2C_RegisterWrite(LIS_CTRL_REG6, 0b01100010);
//Basically setup the unit to run, and enable 4D orientation detection
I2C_RegisterWrite(LIS_INT2_CFG, 0b01111110); //setup for movement detection
I2C_RegisterWrite(LIS_INT2_THS, 0x28);
I2C_RegisterWrite(LIS_INT2_DURATION, 64);
I2C_RegisterWrite(LIS_INT1_CFG, 0b01111110); //setup for movement detection
I2C_RegisterWrite(LIS_INT1_THS, 0x28);
I2C_RegisterWrite(LIS_INT1_DURATION, 64);
}
//0=no change, 1= right handed, 2= left handed
uint8_t LIS2DH12::getOrientation() {
// 8=right handed,4=left,16=flat
//So we ignore if not 8/4
uint8_t pos = I2C_RegisterRead(LIS_INT2_SRC);
if (pos == 8)
return 1;
else if (pos == 4)
return 2;
else
return 0;
for (size_t index = 0; index < (sizeof(i2c_registers) / sizeof(i2c_registers[0])); index++) {
I2C_RegisterWrite(i2c_registers[index].reg, i2c_registers[index].value);
}
}
void LIS2DH12::getAxisReadings(int16_t* x, int16_t* y, int16_t* z) {
@@ -52,9 +45,6 @@ void LIS2DH12::getAxisReadings(int16_t* x, int16_t* y, int16_t* z) {
(*z) = ((uint16_t) (tempArr[5] << 8 | tempArr[4]));
}
void LIS2DH12::setSensitivity(uint8_t threshold, uint8_t filterTime) {
}
void LIS2DH12::I2C_RegisterWrite(uint8_t reg, uint8_t data) {
i2c->Mem_Write(LIS2DH_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, &data, 1);

View File

@@ -8,9 +8,26 @@
#include <MMA8652FC.hpp>
#include "cmsis_os.h"
MMA8652FC::MMA8652FC(FRToSI2C* i2cHandle) {
i2c = i2cHandle;
}
typedef struct {
const uint8_t reg;
const uint8_t val;
} MMA_REG;
static const MMA_REG i2c_registers[] = {
{CTRL_REG2, 0}, //Normal mode
{CTRL_REG2, 0x40}, // Reset all registers to POR values
{FF_MT_CFG_REG, 0x78}, // Enable motion detection for X, Y, Z axis, latch disabled
{PL_CFG_REG, 0x40}, //Enable the orientation detection
{PL_COUNT_REG, 200}, //200 count debounce
{PL_BF_ZCOMP_REG, 0b01000111}, //Set the threshold to 42 degrees
{P_L_THS_REG, 0b10011100}, //Up the trip angles
{CTRL_REG4, 0x01 | (1 << 4)}, // Enable dataready interrupt & orientation interrupt
{CTRL_REG5, 0x01}, // Route data ready interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2
{CTRL_REG2, 0x12}, //Set maximum resolution oversampling
{XYZ_DATA_CFG_REG, (1 << 4)}, //select high pass filtered data
{HP_FILTER_CUTOFF_REG, 0x03}, //select high pass filtered data
{CTRL_REG1, 0x19} // ODR=12 Hz, Active mode
};
void MMA8652FC::I2C_RegisterWrite(uint8_t reg, uint8_t data) {
i2c->Mem_Write( MMA8652FC_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, &data, 1);
@@ -24,47 +41,34 @@ uint8_t MMA8652FC::I2C_RegisterRead(uint8_t reg) {
return tx_data[0];
}
void MMA8652FC::initalize() {
size_t index = 0;
//send all the init commands to the unit
I2C_RegisterWrite(CTRL_REG2, 0); //Normal mode
I2C_RegisterWrite( CTRL_REG2, 0x40); // Reset all registers to POR values
I2C_RegisterWrite(i2c_registers[index].reg, i2c_registers[index].val); index++;
I2C_RegisterWrite(i2c_registers[index].reg, i2c_registers[index].val); index++;
HAL_Delay(2); // ~1ms delay
I2C_RegisterWrite(FF_MT_CFG_REG, 0x78); // Enable motion detection for X, Y, Z axis, latch disabled
I2C_RegisterWrite(PL_CFG_REG, 0x40); //Enable the orientation detection
I2C_RegisterWrite(PL_COUNT_REG, 200); //200 count debounce
I2C_RegisterWrite(PL_BF_ZCOMP_REG, 0b01000111); //Set the threshold to 42 degrees
I2C_RegisterWrite(P_L_THS_REG, 0b10011100); //Up the trip angles
I2C_RegisterWrite( CTRL_REG4, 0); // Disable IRQ's
I2C_RegisterWrite( CTRL_REG5, 0x01); // Route data ready interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2
I2C_RegisterWrite( CTRL_REG2, 0x12); //Set maximum resolution oversampling
I2C_RegisterWrite( XYZ_DATA_CFG_REG, (1 << 4)); //select high pass filtered data
I2C_RegisterWrite( HP_FILTER_CUTOFF_REG, 0x03); //select high pass filtered data
I2C_RegisterWrite( CTRL_REG1, 0x19); // ODR=12 Hz, Active mode
while (index < (sizeof(i2c_registers) / sizeof(i2c_registers[0]))) {
I2C_RegisterWrite(i2c_registers[index].reg, i2c_registers[index].val); index++;
}
}
void MMA8652FC::setSensitivity(uint8_t threshold, uint8_t filterTime) {
uint8_t sens = 9 * 2 + 17;
sens -= 2 * threshold;
I2C_RegisterWrite( CTRL_REG1, 0); // sleep mode
I2C_RegisterWrite(FF_MT_THS_REG, (sens & 0x7F));// Set accumulation threshold
I2C_RegisterWrite(FF_MT_COUNT_REG, filterTime); // Set debounce threshold
I2C_RegisterWrite( CTRL_REG1, 0x31); // ODR=12 Hz, Active mode
}
uint8_t MMA8652FC::getOrientation() {
Orientation MMA8652FC::getOrientation() {
//First read the PL_STATUS register
uint8_t plStatus = I2C_RegisterRead(PL_STATUS_REG);
if ((plStatus & 0b10000000) == 0b10000000) {
plStatus >>= 1; //We don't need the up/down bit
plStatus &= 0x03; //mask to the two lower bits
//0 == left handed
//1 == right handed
return plStatus == 0 ? 2 : 1;
} else
return 0;
return static_cast<Orientation>(plStatus);
}
return ORIENTATION_FLAT;
}
void MMA8652FC::getAxisReadings(int16_t *x, int16_t *y, int16_t *z) {
uint8_t tempArr[6];

View File

@@ -13,7 +13,6 @@
/*http://www.displayfuture.com/Display/datasheet/controller/SSD1307.pdf*/
/*All commands are prefixed with 0x80*/
/*Data packets are prefixed with 0x40*/
const uint8_t configLength = 50;
uint8_t OLED_Setup_Array[] = { /**/
0x80, 0xAE,/*Display off*/
0x80, 0xD5,/*Set display clock divide ratio / osc freq*/
@@ -43,54 +42,42 @@ uint8_t OLED_Setup_Array[] = { /**/
};
//Setup based on the SSD1307 and modified for the SSD1306
const uint8_t REFRESH_COMMANDS[17] = {
0x80, 0xAF,
0x80, 0x21,
0x80, 0x20,
0x80, 0x7F,
0x80, 0xC0,
0x80, 0x22,
0x80, 0x00,
0x80, 0x01,
0x40
};
OLED::OLED(FRToSI2C* i2cHandle) {
i2c = i2cHandle;
cursor_x = cursor_y = 0;
currentFont = FONT_12;
fontWidth = 12;
inLeftHandedMode = false;
firstStripPtr = &screenBuffer[16 + 1];
secondStripPtr = &screenBuffer[16 + 1 + 96];
firstStripPtr = &screenBuffer[FRAMEBUFFER_START];
secondStripPtr = &screenBuffer[FRAMEBUFFER_START + OLED_WIDTH];
fontHeight = 16;
fontWidth = 12;
displayOffset = 0;
displayOnOffState = true;
}
void OLED::initialize() {
memcpy(&screenBuffer[0], &REFRESH_COMMANDS[0], sizeof(REFRESH_COMMANDS));
HAL_Delay(5);
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
HAL_Delay(10);
//Send the setup settings
i2c->Transmit( DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array, configLength);
i2c->Transmit( DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array, sizeof(OLED_Setup_Array));
displayOnOff(true);
}
//Write out the buffer to the OLEd & call any rendering objects
void OLED::refresh() {
screenBuffer[0] = 0x80;
screenBuffer[1] = displayOnOffState ? 0xAF : 0xAE;
screenBuffer[2] = 0x80;
screenBuffer[3] = 0x21;
screenBuffer[4] = 0x80;
screenBuffer[5] = inLeftHandedMode ? 0 : 32; //display is shifted by 32 in left handed mode as driver ram is 128 wide
screenBuffer[6] = 0x80;
screenBuffer[7] = inLeftHandedMode ? 95 : 0x7F; //End address of the ram segment we are writing to (96 wide)
screenBuffer[8] = 0x80; /*Set COM Scan direction*/
screenBuffer[9] = inLeftHandedMode ? 0xC8 : 0xC0;
screenBuffer[10] = 0x80; //Set pages to rollover after 2
screenBuffer[11] = 0x22;
screenBuffer[12] = 0x80;
screenBuffer[13] = 0x00; //start page 0
screenBuffer[14] = 0x80;
screenBuffer[15] = 0x01;
screenBuffer[16] = 0x40; //start of data marker
i2c->Transmit( DEVICEADDR_OLED, screenBuffer, 16 + (96 * 2) + 1);
}
/*
* Prints a char to the screen.
* UTF font handling is done using the two input chars.
@@ -151,25 +138,26 @@ void OLED::drawChar(char c, char PrecursorCommand) {
cursor_x += fontWidth;
}
void OLED::displayOnOff(bool on) {
displayOnOffState = on;
}
void OLED::setRotation(bool leftHanded) {
if (inLeftHandedMode != leftHanded) {
//send command struct again with changes
if (leftHanded == 1) {
if (inLeftHandedMode == leftHanded) {
return;
}
//send command struct again with changes
if (leftHanded) {
OLED_Setup_Array[11] = 0xC8; //c1?
OLED_Setup_Array[19] = 0xA1;
} else if (leftHanded == 0) {
} else {
OLED_Setup_Array[11] = 0xC0;
OLED_Setup_Array[19] = 0xA0;
}
i2c->Transmit( DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array,
configLength);
i2c->Transmit( DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array, sizeof(OLED_Setup_Array));
inLeftHandedMode = leftHanded;
screenBuffer[5] = inLeftHandedMode ? 0 : 32; //display is shifted by 32 in left handed mode as driver ram is 128 wide
screenBuffer[7] = inLeftHandedMode ? 95 : 0x7F; //End address of the ram segment we are writing to (96 wide)
screenBuffer[9] = inLeftHandedMode ? 0xC8 : 0xC0;
}
}
//print a string to the current cursor location
void OLED::print(const char* str) {
@@ -183,14 +171,6 @@ void OLED::print(const char* str) {
}
}
void OLED::setCursor(int16_t x, int16_t y) {
cursor_x = x;
cursor_y = y;
}
void OLED::setCharCursor(int16_t x, int16_t y) {
cursor_x = x * fontWidth;
cursor_y = y * fontHeight;
}
void OLED::setFont(uint8_t fontNumber) {
if (fontNumber == 1) {
//small font
@@ -208,58 +188,35 @@ void OLED::setFont(uint8_t fontNumber) {
}
}
void OLED::drawImage(const uint8_t* buffer, uint8_t x, uint8_t width) {
drawArea(x, 0, width, 16, buffer);
}
//maximum places is 5
void OLED::printNumber(uint16_t number, uint8_t places) {
char buffer[6];
buffer[5] = 0; //null
char buffer[6] = { 0 };
if (places == 5) {
buffer[4] = '0' + number % 10;
number /= 10;
} else
buffer[4] = 0;
}
if (places > 3) {
buffer[3] = '0' + number % 10;
number /= 10;
} else
buffer[3] = 0;
}
if (places > 2) {
buffer[2] = '0' + number % 10;
number /= 10;
} else
buffer[2] = 0;
}
if (places > 1) {
buffer[1] = '0' + number % 10;
number /= 10;
} else
buffer[1] = 0;
}
buffer[0] = '0' + number % 10;
number /= 10;
print(buffer);
}
void OLED::clearScreen() {
memset(firstStripPtr, 0, 96);
memset(secondStripPtr, 0, 96);
}
bool OLED::getRotation() {
return inLeftHandedMode;
}
void OLED::drawBattery(uint8_t state) {
if (state > 10)
state = 10;
drawSymbol(3 + state);
}
void OLED::drawCheckbox(bool state) {
drawSymbol((state) ? 16 : 17);
}
void OLED::drawSymbol(uint8_t symbolID) {
//draw a symbol to the current cursor location
setFont(2);

File diff suppressed because it is too large Load Diff

View File

@@ -191,14 +191,14 @@ const menuitem advancedMenu[] = {
settings_displayCalibrateVIN } }, /*Voltage input cal*/
#ifdef PIDSETTINGS
{ (const char*) SettingsDescriptions[17], { settings_setPIDP }, {
settings_displayPIDP } }, /*Voltage input cal*/
{ (const char*) SettingsDescriptions[18], { settings_setPIDI }, {
settings_displayPIDI } }, /*Voltage input cal*/
{ (const char*) SettingsDescriptions[19], { settings_setPIDD }, {
settings_displayPIDD } }, /*Voltage input cal*/
{ (const char*) SettingsDescriptions[17], {settings_setPIDP}, {
settings_displayPIDP}}, /*Voltage input cal*/
{ (const char*) SettingsDescriptions[18], {settings_setPIDI}, {
settings_displayPIDI}}, /*Voltage input cal*/
{ (const char*) SettingsDescriptions[19], {settings_setPIDD}, {
settings_displayPIDD}}, /*Voltage input cal*/
#endif
{ NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE
{ NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE
};
static void printShortDescriptionSingleLine(uint32_t shortDescIndex) {
@@ -279,7 +279,7 @@ static int userConfirmation(const char* message) {
if (lcdRefresh) {
lcd.refresh();
osDelay(20);
osDelay(40);
lcdRefresh = false;
}
}
@@ -628,14 +628,14 @@ static void settings_setCalibrateVIN(void) {
case BUTTON_B_LONG:
saveSettings();
return;
break;
case BUTTON_NONE:
default:
break;
}
lcd.refresh();
osDelay(50);
osDelay(40);
// Cap to sensible values
if (systemSettings.voltageDiv < 90) {
@@ -646,55 +646,40 @@ static void settings_setCalibrateVIN(void) {
}
}
static void settings_displayCalibrateVIN(void) {
printShortDescription(14, 5);
}
static void settings_displaySolderingMenu(void) {
static void displayMenu(size_t index) {
//Call into the menu
lcd.setFont(1);
lcd.setCursor(0, 0);
//Draw title
lcd.print(SettingsMenuEntries[0]);
lcd.print(SettingsMenuEntries[index]);
//Draw symbol
//16 pixel wide image
lcd.drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * 0]));
lcd.drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * index]));
}
static void settings_displayCalibrateVIN(void) {
printShortDescription(14, 5);
}
static void settings_displaySolderingMenu(void) {
displayMenu(0);
}
static void settings_enterSolderingMenu(void) {
gui_Menu(solderingMenu);
}
static void settings_displayPowerMenu(void) {
lcd.setFont(1);
lcd.setCursor(0, 0);
//Draw title
lcd.print(SettingsMenuEntries[1]);
//Draw symbol
//16 pixel wide image
lcd.drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * 1]));
displayMenu(1);
}
static void settings_enterPowerMenu(void) {
gui_Menu(PowerMenu);
}
static void settings_displayUIMenu(void) {
lcd.setFont(1);
lcd.setCursor(0, 0);
//Draw title
lcd.print(SettingsMenuEntries[2]);
//Draw symbol
//16 pixel wide image
lcd.drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * 2]));
displayMenu(2);
}
static void settings_enterUIMenu(void) {
gui_Menu(UIMenu);
}
static void settings_displayAdvancedMenu(void) {
lcd.setFont(1);
lcd.setCursor(0, 0);
//Draw title
lcd.print(SettingsMenuEntries[3]);
//Draw symbol
//16 pixel wide image
lcd.drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * 3]));
displayMenu(3);
}
static void settings_enterAdvancedMenu(void) {
gui_Menu(advancedMenu);
@@ -807,7 +792,7 @@ void gui_Menu(const menuitem* menu) {
if (lcdRefresh) {
lcd.refresh(); // update the LCD
osDelay(20);
osDelay(40);
lcdRefresh = false;
}
}

View File

@@ -63,12 +63,15 @@ uint16_t getTipRawTemp(uint8_t instant) {
static int64_t filterFP = 0;
const uint8_t filterBeta = 5; //higher values smooth out more, but reduce responsiveness
if (instant) {
if (instant == 1) {
uint16_t itemp = getTipInstantTemperature();
filterFP = (filterFP << filterBeta) - filterFP;
filterFP += (itemp << 9);
filterFP = filterFP >> filterBeta;
return itemp;
} else if (instant == 2) {
filterFP = (getTipInstantTemperature() << 9);
return filterFP >> 9;
} else {
return filterFP >> 9;
}

View File

@@ -97,7 +97,7 @@ void printVoltage() {
lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv) % 10, 1);
}
void GUIDelay() {
osDelay(66); // 15Hz
osDelay(50);
}
void gui_drawTipTemp(bool symbol) {
// Draw tip temp handling unit conversion & tolerance near setpoint
@@ -193,13 +193,13 @@ static void waitForButtonPress() {
ButtonState buttons = getButtonState();
while (buttons) {
buttons = getButtonState();
GUIDelay();
lcd.refresh();
GUIDelay();
}
while (!buttons) {
buttons = getButtonState();
GUIDelay();
lcd.refresh();
GUIDelay();
}
}
@@ -263,6 +263,8 @@ static void gui_drawBatteryIcon() {
static void gui_solderingTempAdjust() {
uint32_t lastChange = xTaskGetTickCount();
currentlyActiveTemperatureTarget = 0;
uint32_t autoRepeatTimer = 0;
uint8_t autoRepeatAcceleration = 0;
for (;;) {
lcd.setCursor(0, 0);
lcd.clearScreen();
@@ -279,10 +281,30 @@ static void gui_solderingTempAdjust() {
return;
break;
case BUTTON_B_LONG:
if (xTaskGetTickCount() - autoRepeatTimer
+ autoRepeatAcceleration> PRESS_ACCEL_INTERVAL_MAX) {
if (!lcd.getRotation()) {
systemSettings.SolderingTemp += 10; // add 10
} else {
systemSettings.SolderingTemp -= 10; // sub 10
}
autoRepeatTimer = xTaskGetTickCount();
autoRepeatAcceleration += PRESS_ACCEL_STEP;
}
break;
case BUTTON_F_LONG:
if (xTaskGetTickCount() - autoRepeatTimer
+ autoRepeatAcceleration> PRESS_ACCEL_INTERVAL_MAX) {
if (!lcd.getRotation()) {
systemSettings.SolderingTemp -= 10;
} else {
systemSettings.SolderingTemp += 10;
}
autoRepeatTimer = xTaskGetTickCount();
autoRepeatAcceleration += PRESS_ACCEL_STEP;
}
break;
case BUTTON_F_SHORT:
if (lcd.getRotation()) {
@@ -301,6 +323,11 @@ static void gui_solderingTempAdjust() {
default:
break;
}
if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration)
< PRESS_ACCEL_INTERVAL_MIN) {
autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX
- PRESS_ACCEL_INTERVAL_MIN;
}
// constrain between 50-450 C
if (systemSettings.temperatureInF) {
if (systemSettings.SolderingTemp > 850)
@@ -553,6 +580,9 @@ static void gui_solderingMode() {
}
}
static const char *HEADERS[] = {
__DATE__, "Heap: ", "HWMG: ", "HWMP: ", "HWMM: ", "Time: ", "Move: ","Rtip: ","Ctip: ","Vin :" };
void showVersion(void) {
uint8_t screen = 0;
ButtonState b;
@@ -563,35 +593,36 @@ void showVersion(void) {
lcd.print((char *) "V2.05 PCB"); // Print version number
lcd.printNumber(PCBVersion, 1); //Print PCB ID number
lcd.setCursor(0, 8); // second line
lcd.print(HEADERS[screen]);
switch (screen) {
case 0:
lcd.print(__DATE__); // print the compile date
break;
case 1:
lcd.print("Heap: ");
lcd.printNumber(xPortGetFreeHeapSize(), 5);
break;
case 2:
lcd.print("HWMG: ");
lcd.printNumber(uxTaskGetStackHighWaterMark(GUITaskHandle), 5);
break;
case 3:
lcd.print("HWMP: ");
lcd.printNumber(uxTaskGetStackHighWaterMark(PIDTaskHandle), 5);
break;
case 4:
lcd.print("HWMM: ");
lcd.printNumber(uxTaskGetStackHighWaterMark(MOVTaskHandle), 5);
break;
case 5:
lcd.print("Time: ");
lcd.printNumber(xTaskGetTickCount() / 100, 5);
break;
case 6:
lcd.print("Move: ");
lcd.printNumber(lastMovementTime / 100, 5);
break;
case 7:
lcd.printNumber(getTipRawTemp(0),5);
break;
case 8:
lcd.printNumber(tipMeasurementToC(getTipRawTemp(0)),5);
break;
case 9:
printVoltage();
break;
default:
break;
}
@@ -601,8 +632,9 @@ void showVersion(void) {
return;
else if (b == BUTTON_F_SHORT) {
screen++;
screen = screen % 7;
screen = screen % 10;
}
GUIDelay();
}
}
@@ -611,20 +643,9 @@ void startGUITask(void const *argument) {
i2cDev.FRToSInit();
uint8_t tempWarningState = 0;
bool buttonLockout = false;
switch (systemSettings.OrientationMode) {
case 0:
lcd.setRotation(false);
break;
case 1:
lcd.setRotation(true);
break;
case 2:
lcd.setRotation(false);
break;
default:
break;
}
bool tempOnDisplay = false;
getTipRawTemp(2); //reset filter
lcd.setRotation(systemSettings.OrientationMode & 1);
uint32_t ticks = xTaskGetTickCount();
ticks += 400; //4 seconds from now
while (xTaskGetTickCount() < ticks) {
@@ -748,7 +769,11 @@ void startGUITask(void const *argument) {
lcd.setCursor(84, 0);
gui_drawBatteryIcon();
}
if (tipTemp > 50) {
if (tipTemp > 55)
tempOnDisplay = true;
else if (tipTemp < 45)
tempOnDisplay = false;
if (tempOnDisplay) {
//draw temp over the start soldering button
//Location changes on screen rotation
if (lcd.getRotation()) {
@@ -762,7 +787,9 @@ void startGUITask(void const *argument) {
}
//draw in the temp
lcd.setFont(0); //big font
gui_drawTipTemp(false); // draw in the temp
if (!(systemSettings.coolingTempBlink
&& (xTaskGetTickCount() % 50 < 25)))
gui_drawTipTemp(false); // draw in the temp
}
}
@@ -812,7 +839,8 @@ void startPIDTask(void const *argument) {
int32_t rawTempError = currentlyActiveTemperatureTarget
- rawTemp;
int32_t ierror = (rawTempError / ((int32_t)systemSettings.PID_I));
int32_t ierror = (rawTempError
/ ((int32_t) systemSettings.PID_I));
integralCount += ierror;
if (integralCount > (itermMax / 2))
integralCount = itermMax / 2; // prevent too much lead
@@ -822,11 +850,12 @@ void startPIDTask(void const *argument) {
int32_t dInput = (rawTemp - derivativeLastValue);
/*Compute PID Output*/
int32_t output = (rawTempError / ((int32_t)systemSettings.PID_P));
if (((int32_t)systemSettings.PID_I))
int32_t output = (rawTempError
/ ((int32_t) systemSettings.PID_P));
if (((int32_t) systemSettings.PID_I))
output += integralCount;
if (((int32_t)systemSettings.PID_D))
output -= (dInput / ((int32_t)systemSettings.PID_D));
if (((int32_t) systemSettings.PID_D))
output -= (dInput / ((int32_t) systemSettings.PID_D));
if (output > 100) {
output = 100; // saturate
@@ -853,35 +882,20 @@ void startPIDTask(void const *argument) {
#define MOVFilter 8
void startMOVTask(void const *argument) {
osDelay(250); // wait for accelerometer to stabilize
switch (systemSettings.OrientationMode) {
case 0:
lcd.setRotation(false);
break;
case 1:
lcd.setRotation(true);
break;
case 2:
lcd.setRotation(false);
break;
default:
break;
}
lcd.setRotation(systemSettings.OrientationMode & 1);
lastMovementTime = 0;
int16_t datax[MOVFilter];
int16_t datay[MOVFilter];
int16_t dataz[MOVFilter];
int16_t datax[MOVFilter] = { 0 };
int16_t datay[MOVFilter] = { 0 };
int16_t dataz[MOVFilter] = { 0 };
uint8_t currentPointer = 0;
memset(datax, 0, MOVFilter * sizeof(int16_t));
memset(datay, 0, MOVFilter * sizeof(int16_t));
memset(dataz, 0, MOVFilter * sizeof(int16_t));
int16_t tx, ty, tz;
int32_t avgx, avgy, avgz;
int16_t tx = 0, ty = 0, tz = 0;
int32_t avgx = 0, avgy = 0, avgz = 0;
if (systemSettings.sensitivity > 9)
systemSettings.sensitivity = 9;
#if ACCELDEBUG
uint32_t max = 0;
#endif
uint8_t rotation = 0;
Orientation rotation = ORIENTATION_FLAT;
for (;;) {
int32_t threshold = 1500 + (9 * 200);
threshold -= systemSettings.sensitivity * 200; // 200 is the step size
@@ -894,19 +908,16 @@ void startMOVTask(void const *argument) {
rotation = accel.getOrientation();
}
if (systemSettings.OrientationMode == 2) {
if (rotation != 0) {
lcd.setRotation(rotation == 2); // link the data through
if (rotation != ORIENTATION_FLAT) {
lcd.setRotation(rotation == ORIENTATION_LEFT_HAND); // link the data through
}
}
datax[currentPointer] = (int32_t) tx;
datay[currentPointer] = (int32_t) ty;
dataz[currentPointer] = (int32_t) tz;
currentPointer = (currentPointer + 1) % MOVFilter;
#if ACCELDEBUG
// Debug for Accel
avgx = avgy = avgz = 0;
// calculate averages
for (uint8_t i = 0; i < MOVFilter; i++) {
avgx += datax[i];
avgy += datay[i];
@@ -915,38 +926,35 @@ void startMOVTask(void const *argument) {
avgx /= MOVFilter;
avgy /= MOVFilter;
avgz /= MOVFilter;
//Sum the deltas
int32_t error = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
#if ACCELDEBUG
// Debug for Accel
lcd.setFont(1);
lcd.setCursor(0, 0);
lcd.printNumber(abs(avgx - (int32_t) tx), 5);
lcd.print(" ");
lcd.printNumber(abs(avgy - (int32_t) ty), 5);
if ((abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)) > max)
max = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
if (error > max) {
max = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
}
lcd.setCursor(0, 8);
lcd.printNumber(max, 5);
lcd.print(" ");
lcd.printNumber((abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)), 5);
lcd.refresh();
if (HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET)
max = 0;
#endif
// calculate averages
avgx = avgy = avgz = 0;
for (uint8_t i = 0; i < MOVFilter; i++) {
avgx += datax[i];
avgy += datay[i];
avgz += dataz[i];
if (HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET) {
max = 0;
}
avgx /= MOVFilter;
avgy /= MOVFilter;
avgz /= MOVFilter;
#endif
// So now we have averages, we want to look if these are different by more
// than the threshold
//Sum the deltas
int32_t error = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
// If error has occurred then we update the tick timer
if (error > threshold) {
lastMovementTime = xTaskGetTickCount();