浏览代码

First implementation

leptun 5 年之前
父节点
当前提交
68491c9d4d
共有 6 个文件被更改,包括 54 次插入6 次删除
  1. 0 4
      Firmware/Marlin_main.cpp
  2. 33 0
      Firmware/backlight.cpp
  3. 13 0
      Firmware/backlight.h
  4. 2 1
      Firmware/eeprom.h
  5. 1 1
      Firmware/pins_Einsy_1_0.h
  6. 5 0
      Firmware/ultralcd.cpp

+ 0 - 4
Firmware/Marlin_main.cpp

@@ -989,10 +989,6 @@ void setup()
 
 	ultralcd_init();
 
-#if (LCD_BL_PIN != -1) && defined (LCD_BL_PIN)
-	analogWrite(LCD_BL_PIN, 255); //set full brightnes
-#endif //(LCD_BL_PIN != -1) && defined (LCD_BL_PIN)
-
 	spi_init();
 
 	lcd_splash();

+ 33 - 0
Firmware/backlight.cpp

@@ -0,0 +1,33 @@
+//backlight.cpp
+
+#include "backlight.h"
+#include <avr/eeprom.h>
+#include <Arduino.h>
+#include "eeprom.h"
+#include "Marlin.h"
+#include "pins.h"
+#include "fastio.h"
+// #include "Timer.h"
+// #include "Configuration.h"
+
+int16_t backlightLevel = 0;
+int16_t backlightLevel_old = 0;
+// uint16_t backlightCounter = 0;
+
+void backlight_update()
+{
+    if (backlightLevel != backlightLevel_old) //update level
+    {
+        analogWrite(LCD_BL_PIN, backlightLevel);
+        backlightLevel_old = backlightLevel;
+        eeprom_update_byte((uint8_t *)EEPROM_BACKLIGHT_LEVEL, backlightLevel);
+    }
+}
+
+void backlight_init()
+{
+    SET_OUTPUT(LCD_BL_PIN);
+    WRITE(LCD_BL_PIN,0);
+    backlightLevel = eeprom_read_byte((uint8_t *)EEPROM_BACKLIGHT_LEVEL);
+    backlight_update();
+}

+ 13 - 0
Firmware/backlight.h

@@ -0,0 +1,13 @@
+//backlight.h
+#ifndef _BACKLIGHT_H
+#define _BACKLIGHT_H
+
+#include <inttypes.h>
+
+extern int16_t backlightLevel;
+
+extern void backlight_update();
+extern void backlight_init();
+
+
+#endif //_BACKLIGHT_H

+ 2 - 1
Firmware/eeprom.h

@@ -201,9 +201,10 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP
 #define EEPROM_SHEETS_BASE (EEPROM_CHECK_GCODE - EEPROM_SHEETS_SIZEOF) // Sheets
 static Sheets * const EEPROM_Sheets_base = (Sheets*)(EEPROM_SHEETS_BASE);
 
+#define EEPROM_BACKLIGHT_LEVEL (EEPROM_SHEETS_BASE-1) // uint8
 
 //This is supposed to point to last item to allow EEPROM overrun check. Please update when adding new items.
-#define EEPROM_LAST_ITEM EEPROM_SHEETS_BASE
+#define EEPROM_LAST_ITEM EEPROM_BACKLIGHT_LEVEL
 // !!!!!
 // !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!!
 // !!!!!

+ 1 - 1
Firmware/pins_Einsy_1_0.h

@@ -99,7 +99,7 @@
 
 //#define KILL_PIN            32
 
-//#define LCD_BL_PIN          5   //backlight control pin
+#define LCD_BL_PIN          5   //backlight control pin
 #define BEEPER              84  // Beeper on AUX-4
 #define LCD_PINS_RS         82
 #define LCD_PINS_ENABLE     61 // !!! changed from 18 (EINY03)

+ 5 - 0
Firmware/ultralcd.cpp

@@ -18,6 +18,7 @@
 
 #include "lcd.h"
 #include "menu.h"
+#include "backlight.h"
 
 #include "util.h"
 #include "mesh_bed_leveling.h"
@@ -5768,6 +5769,8 @@ static void lcd_settings_menu()
 
 	SETTINGS_SD;
 	SETTINGS_SOUND;
+    
+    MENU_ITEM_EDIT_int3_P(_i("Backlight"), &backlightLevel, 0, 255);
 
 	if (farm_mode)
 	{
@@ -8567,6 +8570,7 @@ void ultralcd_init()
         else lcd_autoDeplete = autoDepleteRaw;
 
     }
+    backlight_init();
 	lcd_init();
 	lcd_refresh();
 	lcd_longpress_func = menu_lcd_longpress_func;
@@ -8813,6 +8817,7 @@ void menu_lcd_lcdupdate_func(void)
 		}
 	}
 #endif//CARDINSERTED
+    backlight_update();
 	if (lcd_next_update_millis < _millis())
 	{
 		if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)