forked from MarlinFirmware/Marlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Laser Based I2C Ammeter Feature (MarlinFirmware#21835)
- Loading branch information
1 parent
a3063a9
commit 2fd9971
Showing
12 changed files
with
314 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Marlin 3D Printer Firmware | ||
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] | ||
* | ||
* Based on Sprinter and grbl. | ||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "../inc/MarlinConfig.h" | ||
|
||
#if ENABLED(I2C_AMMETER) | ||
#include "ammeter.h" | ||
|
||
INA226 ina; | ||
|
||
Ammeter ammeter; | ||
|
||
float Ammeter::scale; | ||
float Ammeter::current; | ||
|
||
void Ammeter::init() { | ||
ina.begin(); | ||
ina.configure(INA226_AVERAGES_16, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US, INA226_MODE_SHUNT_BUS_CONT); | ||
ina.calibrate(I2C_AMMETER_SHUNT_RESISTOR,I2C_AMMETER_IMAX); | ||
} | ||
|
||
float Ammeter::read() { | ||
scale = 1; | ||
current = ina.readShuntCurrent(); | ||
if (current <= .0001) current = 0; // Cleanup lsb bit amplification errors | ||
if (current < .1) scale = 1000; | ||
return current * scale; | ||
} | ||
|
||
#endif //I2C_AMMETER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Marlin 3D Printer Firmware | ||
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] | ||
* | ||
* Based on Sprinter and grbl. | ||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
#pragma once | ||
|
||
#include "../inc/MarlinConfigPre.h" | ||
|
||
#include <Wire.h> | ||
#include <INA226.h> | ||
|
||
#ifndef I2C_AMMETER_IMAX | ||
#define I2C_AMMETER_IMAX .500 // Calibration range 500 Milli Amps | ||
#endif | ||
|
||
class Ammeter { | ||
private: | ||
static float scale; | ||
|
||
public: | ||
static float current; | ||
static void init(); | ||
static float read(); | ||
|
||
}; | ||
|
||
extern Ammeter ammeter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Marlin 3D Printer Firmware | ||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] | ||
* | ||
* Based on Sprinter and grbl. | ||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
#pragma once | ||
|
||
// | ||
// lcd/dogm/status/ammeter.h - Status Screen Laser Ammeter bitmaps | ||
// | ||
#if ENABLED(I2C_AMMETER) | ||
|
||
#define STATUS_AMMETER_WIDTH 20 | ||
|
||
const unsigned char status_ammeter_bmp_mA[] PROGMEM = { | ||
B00000000,B11111100,B00000000, | ||
B00000011,B00000011,B00000000, | ||
B00000100,B00000000,B10000000, | ||
B00001000,B00000000,B01000000, | ||
B00010000,B00000110,B00100000, | ||
B00010000,B00001001,B00100000, | ||
B00100000,B00001001,B00010000, | ||
B00100011,B01001111,B00010000, | ||
B11100010,B10101001,B00011100, | ||
B00100010,B10101001,B00010000, | ||
B00100010,B10101001,B00010000, | ||
B00010000,B00000000,B00100000, | ||
B00010000,B00000000,B00100000, | ||
B00001000,B00000000,B01000000, | ||
B00000100,B00000000,B10000000, | ||
B00000011,B00000011,B00000000, | ||
B00000000,B11111100,B00000000 | ||
}; | ||
|
||
const unsigned char status_ammeter_bmp_A[] PROGMEM = { | ||
B00000000,B11111100,B00000000, | ||
B00000011,B00000011,B00000000, | ||
B00000100,B00000000,B10000000, | ||
B00001000,B00000000,B01000000, | ||
B00010000,B00000000,B00100000, | ||
B00010000,B00110000,B00100000, | ||
B00100000,B01001000,B00010000, | ||
B00100000,B01001000,B00010000, | ||
B11100000,B01111000,B00011100, | ||
B00100000,B01001000,B00010000, | ||
B00100000,B01001000,B00010000, | ||
B00010000,B01001000,B00100000, | ||
B00010000,B00000000,B00100000, | ||
B00001000,B00000000,B01000000, | ||
B00000100,B00000000,B10000000, | ||
B00000011,B00000011,B00000000, | ||
B00000000,B11111100,B00000000, | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.