saveload.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "heater3.h"
  2. #include "saveload.h"
  3. #include "potentiometers.h"
  4. #include "lcd-twi.h"
  5. extern heater_str heater[2];
  6. extern opamp_str opamp[2];
  7. extern preset_str preset[2];
  8. void LoadPrefs()
  9. {
  10. for(uint8_t addr = 0; addr < 4; addr++)
  11. {
  12. EEAR = addr;
  13. EECR |= (1 << EERE);
  14. switch(addr)
  15. {
  16. case 0:
  17. heater[CH0].preset = EEDR;
  18. break;
  19. case 1:
  20. heater[CH1].preset = EEDR;
  21. break;
  22. case 2:
  23. heater[CH0].tset = EEDR;
  24. break;
  25. case 3:
  26. heater[CH1].tset = EEDR;
  27. break;
  28. }
  29. }
  30. }
  31. void SavePrefs()
  32. {
  33. cli();
  34. for(uint8_t addr = 0; addr < 4; addr++)
  35. {
  36. EEAR = addr;
  37. switch(addr)
  38. {
  39. case 0:
  40. EEDR = heater[CH0].preset;
  41. break;
  42. case 1:
  43. EEDR = heater[CH1].preset;
  44. break;
  45. case 2:
  46. EEDR = heater[CH0].tset;
  47. break;
  48. case 3:
  49. EEDR = heater[CH1].tset;
  50. break;
  51. }
  52. EECR |= (1 << EEMPE);
  53. EECR |= (1 << EEPE);
  54. while(EECR & (1 << EEPE));
  55. }
  56. sei();
  57. }
  58. void LoadPreset(uint8_t ch)
  59. {
  60. uint8_t offset;
  61. for(offset = 0; offset < sizeof(preset_str); offset++)
  62. {
  63. EEAR = 0x30 + (heater[ch].preset * sizeof(preset_str)) + offset;
  64. EECR |= (1 << EERE);
  65. ((uint8_t*)&preset[ch])[offset] = EEDR;
  66. }
  67. SetGainData(ch, preset[ch].gain);
  68. SetShiftData(ch, preset[ch].shift);
  69. SetDriveData(ch, preset[ch].drive);
  70. SwitchDrive(ch, OFF);
  71. }
  72. void SavePreset(uint8_t ch)
  73. {
  74. uint8_t offset;
  75. static FILE lcd_stdout = FDEV_SETUP_STREAM(lcd_putchar, NULL, _FDEV_SETUP_WRITE);
  76. cli();
  77. LCD_SendCmd(LCD_CLR);
  78. LCD_SetPos(0, 0);
  79. fprintf(&lcd_stdout, "ÑÎÕÐÀÍÅÍÈÅ...");
  80. LCD_SetPos(0, 1);
  81. for(offset = 0; offset < sizeof(preset_str); offset++)
  82. {
  83. EEAR = 0x30 + (preset[ch].number * sizeof(preset_str)) + offset;
  84. EEDR = ((uint8_t*)&preset[ch])[offset];
  85. EECR |= (1 << EEMPE);
  86. EECR |= (1 << EEPE);
  87. while(EECR & (1 << EEPE));
  88. if((offset + 1) % 5 == 0)
  89. LCD_SendData(0xFF);
  90. }
  91. sei();
  92. }