[
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "\n## Valden Heat Pump Controller v1.x\n<b>The Valden Heat Pump controller is an open source platform to precisely control heat pumps. This controller can be used for the automation of newly built Heat Pumps (HPs), as a repair controller for old systems or as control system for performing experiments on refrigeration equipment.</b>\n<br><br>\n\n## Specs\n- 12V 0.5A DC power supply,\n- 230V output,\n- 4 16A relays: Compressor, Hot Circulating Pump (CP) or Air Fan, Cold CP or Air Fan, Crankcase Heater,\n- 2 inputs: Hot and cold side refrigerant over/under pressure NC sensors,\n- up to 12 temperature (T) sensors, -55..+125 °C range,\n- Electronic Expansion Valve (EEV) supported, 6 pin EEV connection: 4 * coils + 2 * 12V,\n- automatically turns on/of system when heating required,\n- automatic power saving mode,\n- built-in protections: cold start, overheat, short-term power loss, power overload, ground loop freeze, compressor protection against liquid and other,\n- LED indication,\n- control via [remote display](https://github.com/openhp/Display/) or local Serial (UART 5V).\n<br><br>\n<img src=\"./m_controller_and_display.jpg\" width=\"800\"><br><br>\n\n## Refrigeration schemes supported\n- Heat Pump (HP) with Electronic Expansion Valve (EEV),\n- HP with capillary tube or TXV,\n- EEV-only controller.<br><br>\n\n## Installations supported\n- Indoor: a house or technical building with an almost stable temperature,\n- Outdoor: harsh climatic conditions taken into account. Outdoor HP installations tested down to a minus 32 °C.<br><br>\n\n## Changelog and history\n- 2018: PCB prototype, first real installation,\n- 2019: 2-layer PCB, through-hole components, integrated buttons and display (public access),\n- 2019: controller redesigned taking into account development and operating experience, 2-layer PCB, SMD,\n- 2019-2021: installations, development, tests, revisions, redesigns (limited access), \n- 06 Feb 2021: product is technically completed and ready for public access. Documentation and release stage,\n- 31 Aug 2021: public access granted.<br><br>\n\n## Get your own PCB copy. Assembly.\n- download PCB Gerber file [here](./Valden_HeatPumpController_Gerber.zip) or get your own copy [there](https://www.pcbway.com/project/shareproject/Valden_Heat_Pump_Controller_v1.html),\n- order electronic components, see BOM (Bill Of Materials) appendix,\n- solder electronic components, [assembly instructions here](https://github.com/openhp/HeatPumpController/wiki/Assembly)<br><br>.\n<img src=\"./m_c_assembly_completed.jpg\" width=\"500\"><br><br>\n\n## Firmware upload\nThis process is the same as for other Arduinos:\n- connect USB-> UART converter,\n- start Arduino IDE,\n- download and open the [firmware file](./Valden_HeatPumpController.ino),\n- select board and MCU in the Tools menu (hint: we are using \"mini\" board with 328p MCU),\n- press the \"Upload\" button in the interface and \"Reset\" on the Arduino.\n\nFor arduinos with an old bootloader you need to update it. (Tools-> Burn Bootloader).<br>\nFor successful compilation, you must have \"SoftwareSerial\", \"OneWire\" and \"DallasTemperature\" libraries installed (see Tools -> Manage Libraries).<br>\nFor the first time it's enough to upload firmware without any tuning. Think of it as of a commercial closed-source controller, where you cannot fine-tune internal options. And any other manual configuration do not required too, just upload firmware. You will see an error LED indication and hear a beep, since no sensors connected to your controller. Follow the next steps.<br>\n<img src=\"./m_add_IDE.png\" height=\"300\"><br><br>\n\n## Self-tests\nQA tests are available to test the assembled board.<br>\nSelf-test helps you check relays, indicators, speaker and temperature sensors.<br>\nTo run a self-tests:\n- uncomment this 3 defines in source code header,\n```c\n//#define SELFTEST_RELAYS_LEDS_SPEAKER    //speaker and relays QA test, uncomment to enable\n//#define SELFTEST_EEV                    //EEV QA test, uncomment to enable\n//#define SELFTEST_T_SENSORS              //temperature sensors QA test, uncomment to enable\n```\n- upload firmware,\n- connect 12V power supply,\n- disconnect +5V wire from USB-UART converter.<br>\n\nTo check EEV connection, you can use a stepper motor.  If you are testing a real EEV, it will be closed after the first \"beep\" and partially opened after the second \"beep\". If it's not, check if stepper or EEV center pin(s) connected to +12V and try to swap coil-end pins (EEV1..EEV4).<br>\n<img src=\"./m_c_selftest_EEV.jpg\" width=\"500\"><br>\nTo check temperature sensors connectors crimp one array of sensors. Plug it to all sensor connectors one-by-one and check results in a serial console.<br>\n<img src=\"./m_c_selftest_t_sensors.jpg\" width=\"500\"><br>\n<img src=\"./m_c_selftest_t_readings.png\"><br>\nAfter tests completed, comment 3 self-test defines.<br>\nChoose your installation scheme and uncomment one of those options:\n```c\n#define SETPOINT_THI \t//\"warm floor\" scheme: \"hot in\" (Thi) temperature used as setpoint\n//#define SETPOINT_TS1 \t//\"swimming pool\" or \"water tank heater\" scheme: \"sensor 1\" (Ts1) is used as setpoint and located somewhere in a water tank\n```\nRe-upload firmware. Your controller is ready for the first start (after wiring). Probably you'll never need to change other options.<br><br>\n\n## Wiring (permanent controller installation).\nHere are no instructions for choosing the right placement for permanent installation of the controller. It depends. You're building your system, and you know much better \"where\" and \"how\".<br>\nAssuming you have installed your controller to the permanent place, the next step is wiring.<br><br>\nWiring is very simple, despite a lot of terminals.<br>\nPhases (1st wire in electrical cables):\n- connect the \"power inlet\" wire to one of the \"phase\" terminals,\n- connect the \"Compressor\" relay output to the Compressor input,\n- connect the \"Hot CP\" relay output to the Hot Circulation Pump input (or to the fan power input of the indoor unit if you are using an air system),\n- connect the \"Cold CP\" relay output to the Cold Circulation Pump input (or to the fan power input of the outdoor unit),\n- when using a compressor heater: connect the \"Crankcase heater\" relay output to the heater cable (highly recommended for outdoor installation and year-round use),\n- connect all the second wires of power cords to the \"neutral\" terminals on the board.<br>\n<img src=\"./m_c_wiring_power.jpg\" width=\"600\"><br>\n\n12V Power Supply:\n- connect the second \"phase\" and one of \"neutral\" terminals to the AC input of the 12V power supply,\n- connect 12V power supply output to GND and 12V<br>\n<img src=\"./m_c_wiring_12v.jpg\" width=\"600\"><br>\n\nCrimp and plug low-voltage connectors:\n- crimp SCT013 sensor wires (the only one low-voltage device in this circuit with interchangeable wires), connect and install it on the inlet phase wire,<br>\n<img src=\"./m_c_wiring_current_sensor.jpg\" width=\"600\"><br>\n- crimp RS485 to the Remote Display, using a wire of desired length (note that A is connected to A, B to B and GND to GND),\n- crimp  12V and GND secondary terminals to the remote display,<br>\n<img src=\"./m_c_wiring_display.jpg\" width=\"600\"><br>\n- connect EEV to EEV terminal,<br>\n<img src=\"./m_c_wiring_EEV.jpg\" width=\"600\"><br>\n- install all T sensors on pipes, insulate tubes,\n- crimp T sensors arrays, you can crimp all four GND wires at every array to one GND connector pin or make 1-to-4 connection somewhere closer to sensors location (same for +5V wires),\n- insert T sensors arrays to appropriate terminals (if you do not need to control over all temperatures, disable and do not install unnecessary sensors),<br>\n<img src=\"./m_c_wiring_t_sensors.jpg\" width=\"600\"><br>\n- crimp and plug pressure sensors outputs: crimp 1st wires together to **12V** (right output of the terminal), 2nd cold side wire to the **Pco** (left), 2nd hot side wire to the **Phi** (middle); use the dummy if no pressure sensors used in your system.\n<img src=\"./m_c_wiring_pressure.jpg\" width=\"600\"><br>\n<img src=\"./m_c_wiring_pressure_dummy.jpg\" width=\"600\"><br>\n\nYou may prefer to solder the wires over using terminals and crimping connectors. But in this case, it will be difficult to disassemble the system if you want to change something. The choice is yours.<br><br>\nAnd one more: **remember! 230V inside!** Do not turn on the phase without need.<br>\nHave you ever received 230V with your own hands? If yes - you know. If no - do not try.<br>\nAlso remember about animals and children during the installation at a permanent place.<br><br>\n\n## Control and usage: serial console\nThis is a first interface to Heat Pump controller you'll see after uploading firmware (Tools->Serial Monitor).<br>\nThe console itself is simple to use, several commands are available. Type in command, press \"Send\". Help and hotkeys:<br>\n![console help screenshot](./m_console_help.png)<br>\nEvery 30 sec. (**HUMAN_AUTOINFO** option) you'll see stats. For example, after a startup of your compressor, you'll see something like this:<br>\n![console statistics screenshot](./m_console_stats.png)<br>\nAt this example, \"hot in\" ~30 °C, compressor ~80 °C and so on. Heat Pump (HP, compressor) ON, Hot water pump ON, Cold water pump ON. Power consumption 980 watts.\nAbbreviations: refer to Appendix A below.<br>\nAlso, you'll see diagnostic messages in your serial console.<br>\nDo not connect +5V wire from USB-UART converter, if you are using a serial console.<br><br>\n\n## Control and usage: [Remote Control Display](https://github.com/openhp/Display/)\nThis is a way for the end user to control Heat Pump.<br>\n<img src=\"./m_display_main.jpg\" width=\"300\"><br><br>\nEnd user does not want to know much about refrigerants, evaporation, discharge temperatures and so on, so this display designed as simple as it was possible. See [Remote Display page](https://github.com/openhp/Display/) for details. And yes, this display is open product too, with available Gerber, PCB and source code.<br><br>\n\n## Control and usage: [Service Display](https://github.com/openhp/ServiceDisplay/) \nOne day I've realized that a netbook with a serial console is a good diagnostic tool, but I want a compact tool to get maximum available information from a Heat Pumps. So, this \"Quickly Assembled Service Display\" appeared. It fits everywhere and with a good power bank it can work 2-3 days long, without any additional power source. The diagnostic display is build from scratch, no PCB and housing here (and no plans to create it), because I do not see this service display as a permanently mounted device. <br>\n<img src=\"./m_tft_mainscreen.jpg\" width=\"300\"><br><br>\nIf you want a compact and visual tool - this device is for you, so check the [Service Display Page](https://github.com/openhp/ServiceDisplay/) .<br><br>\n\n## Starting up the heat pump system for the first time and charging refrigerant\nThis is an easy part, but if you don't have experience it will take time.<br>\nYou have performed a pressure test and vacuuming. It's time to charge your system.<br>\nLet's say you don't know how to calculate the amount of refrigerant in a recently built system, so follow next steps:\n- charge a small amount (for example 300 g) of refrigerant,\n- get ready for a system protective stops by Tae or Tbe temperature, this is a normal system behavior while refilling refrigerant,\n- power on your heat pump,\n- after compressor startup suction temperature will be about -20 ...- 40 °C (according to the suction pressure on the pressure gauge),\n- for single-component refrigerants: slightly open the valve of the HVAC gauge manifold and start adding refrigerant through the gas phase on the cold side,\n- for multi-component refrigerants: turn over the refrigerant cylinder, VERY SLIGHTLY open the HVAC manifold valve and start adding VERY LITTLE amounts through the liquid phase,\n- continue, until the suction temperature (according to the suction pressure on the manometer) is ~ 10 ... 12 °C lower than the temperature of the heat source (example: the temperature at the inlet of the mixture of water and antifreeze from the closed ground loop is + 8 °C, so the suction temperature should be -2 ..- 4),\n- close the manifold valve,\n- at every step check the discharge pressure: it should not be above the discharge sensor temperature (Tbc),\n- wait for the system to heat the target to an almost stable temperature, add little amounts of refrigerant while temperature increases (and suction decreases),\n- stop if you are sure that the heating process proceeding slowly,\n- take a final look and charge when the system is stable and the heat pump stops normally (setpoint is reached), this may take 12 hours or more,\n- after the final refilling difference between the suction pressure temperature and the Tae sensor temperature should be 3 ... 6 °C.\n\nThis algo is good and safe both the first time and as a starting point. As you gain experience, you will get yours much easier and faster.<br>\nAlso, use \"manual EEV mode\" during refilling process.<br>\nKeep your eyes protected and do not freeze your fingers.<br>\n<img src=\"./m_add_charge.jpg\" height=\"200\"><br><br>\n\n## Hints\nFor more information about Heat Pumps look at [Wikipedia HP page](https://en.wikipedia.org/wiki/Heat_pump).<br>\nIf you want to know \"how the refrigeration systems work\", read Patrick Kotzaoglanian books.<br>\nIf you want more technical details, sophisticated schemes, \"how EEV can be driven by temperature\" diagrams, etc. refer to vendor manuals (you'll find all you need in the Alfa Laval brochures, Danfoss guides, and so on).<br>\nFor refrigerants and oils types comparison see wiki.<br><br>\n\n## Personal experience \nNote that the SCT013 sensor and the current monitoring scheme cannot be used for accurate measurements and accurate COP calculations. Use a watt meter for accurate power measurements.<br>\nTemperature sensor installation at a warm floor surface is a bad idea - it's better to get \"hot in\" water temperature coming from all over the floor, as implemented in firmware.<br>\nThe weather-dependent (both outdoor and indoor temperature dependent) system does not work fine for 30-150 m2 buildings. Such a system is too complex and works unpredictable due to random ventilation. And also due to the unpredictability of heat emitted in the house by other sources.<br>\nI tried the scheme with a flooded evaporator in 2019 and found it terribly tricky, then refused to use it.<br>\nDeep regeneration schemes are useful only for some refrigerants and only in certain temperature ranges. I've tried deep regeneration too. As a result, the theory coincided with practice and I also refused this idea.<br>\nIn general, it is possible by complicating the refrigeration scheme to win somewhere 1%, somewhere 3%, but all this leads to significant time and money cost getting suddenly a small profit.<br>\nSummary: If you want experiments - Experiment. Want reliably - make the system simple.<br><br>\n<img src=\"./m_add_freezed1.jpg\" height=\"300\"> <img src=\"./m_add_freezed2.jpg\" height=\"300\"> <img src=\"./m_add_freezed3.jpg\" height=\"300\"><br><br>\n\n## Author\n<br>\ngonzho АТ web.de (c) 2018-2021<br>\n\n## Appendix A: Abbreviations\nAbbreviations used in the documentation and firmware.<br>\nMain sensors:\n| Abbr. | Full name             |\n| ----- | --------------------  |\n| Tae   | after evaporator      | \n| Tbe   | before evaporator     |\n| Tci   | cold side \"input\"     |\n| Tco   | cold side \"output\"    |\n| Tbc   | before condenser      |\n| Tac   | after condenser       |\n| Thi   | hot side \"input\"      |\n| Tho   | hot  side \"output\"    |\n| Tcrc  | crankcase (compressor itself)|\n\nThe additional sensor used in \"swimming pool heater\" or \"water tank heater\" schemes, check **SETPOINT_TS1** option:\n| Abbr. | Full name             |\n| ----- | --------------------  |\n| Ts1   | additional sensor1    |\n\nAdditional sensors, disabled and not used by default:\n| Abbr. | Full name             |\n| ----- | --------------------  |\n| Treg  | regenerator temperature|\n| Ts2   | additional sensor2    |\n\nRelays:\n| Abbr. | Full name             |\n| ----- | --------------------  |\n| RCRCH  | crankcase heater relay\t|\n| RC   | cold side water pump relay\t|\n| RH   | cold side water pump relay    \t|\n| RP   | heat pump (compressor) relay\t|\n\nOther:\n| Abbr. | Full name             \t\t|\n| ----- | --------------------  \t\t|\n| LSM\t| LastStopCause\t\t\t\t|\n| LSC\t| LastStartMessage\t\t\t|\n| CWP/CCP | cold side water (circulating) pump\t|\n| HWP/HCP | cold side water (circulating) pump\t|\n| EEVP\t| EEV position\t\t\t\t|\n| HP\t| heat pump\t\t\t\t|\n\n## Appendix B: LEDs\nLEDs allow you to make rapid diagnostics without connecting a serial console or a Service Display.<br>\n| LED | description |\n| ------------- | ------------- |\n| **EEV_opening**     \t|  EEV is opening  |\n| **EEV_closing**     \t|  EEV is closing  |\n| **EEV_fast**     \t|  EEV mode is \"fast\" (non-precise) |\n| **485_RX**     \t|  485 transceiver is in listening state  |\n| **485_TX**     \t|  485 transceiver transmits a reply  |\n| **Manual mode**     \t|  EEV in a manual mode   |\n| **LSC: error**     \t|  Last stop was caused by an error. If you see this LED ON, it's a reason to connect either console or Service Display. Diagnostics  required.   |\n| **LSC: protection**\t|  Last stop was caused by protection. In some cases (like long powered-on periods or refilling) this can occur. Here no recommendations about diagnostic, since all systems and operation conditions are different. This LED indicates that something exceeded normal run conditions. |\n| **OK**     |  System OK.  |\n| **ERROR**     |  Something wrong: not all T sensors connected, one of the pressure sensors is not OK. Diagnostics required.   |\n| **Relays LEDs**     |  Indicates corresponding relay state  |\n\n## Appendix C: Diagnostic and status messages\n**LastStopCause (LSC) messages. Why the compressor has stopped working.**\n| Message | description |\n| ------------- | ------------- |\n| **Normal_stop**     | Normal stop, i.e. setpoint sensor temperature > setpoint, so heat not needed.    |\n| **P.WtMax:_WATTS_**    | Protective stop. Overcurrent, double-check your system, then **MAX_WATTS** and **POWERON_HIGHTIME** options. |\n| **P.W.wattMIN**    | Protective stop. Abnormally low power consumption (<max watts/5). Check your system, see **MAX_WATTS** option. |\n| **P.W.TcrcMIN**    | Protective stop. Abnormally low \"Compressor\" temperature. Check your system, see **T_WORKINGOK_CRANKCASE_MIN** option. |\n| **P.Tho**         | Protective stop. \"Hot out\" temperature is too high. Check your system, see **T_HOT_MAX** option. |\n| **P.Thi**         | Protective stop. \"Hot in\" temperature is too high. Check system, see **T_HOT_MAX** option. |\n| **P.Tcrc**        | Protective stop. \"Compressor\" temperature is too high. Overheat protection. This is an ordinary situation during long runs. See **T_CRANKCASE_MAX** option and compressor manual if you want to tune it (~115 °C for wide-available compressors). |\n| **P.Tae**        | Protective stop. \"After evaporator\" temperature too low. Preventing cold loop from freezing and protecting suction line from liquid. See **T_COLDREF_MIN** option. |\n| **P.Tbe**        | Protective stop. \"Before evaporator\" temperature too low. Preventing cold loop from freezing. See **T_BEFORE_EVAP_WORK_MIN** option. |\n| **P.Tbc**        | Protective stop. \"Before condenser\" temperature is too high. Overheat protection. This is an ordinary situation during long runs. See **T_BEFORE_CONDENSER_MAX** option. |\n| **P.Tci**        | Protective stop. \"Cold in\" temperature is too low. Preventing cold loop from freezing. See **T_COLD_MIN** option. |\n| **P.Tco**        | Protective stop. \"Cold out\" temperature is too low. Preventing cold loop from freezing. See **T_COLD_MIN** option. |\n| **E.Tci, E.Tco, E.Tbe, E.Tae, E.Ts1, E.Ts2, E.Tcrc, E.Treg, E.Tac, E.Tbc, E.Tho, E.Thi** |    Sensor lost, check wiring. Refer to \"T sensor abbreviations\". |\n| **E.PresCold**    | Cold side pressure too low, check refrigerant charge and pressure sensors. |\n| **E.PresHot**     | Hot side pressure too high, check refrigerant charge and pressure sensors. |\n\n**LastStartMessage (LSM) messages. What condition the system expects. Some informational messages.**\n| Message | description |\n| ------------- | ------------- |\n| **StCntd:_seconds_** \t| Startup countdown, short-term power loss protection. |\n| **HP_Started** \t| Normal start. |\n| **#Thi>Setp.** \t| \"Hot in\" temperature > setpoint, so no reason to start. |\n| **#Ts1>Setp.** \t| \"Ts1\" temperature > setpoint, so no reason to start. See **SETPOINT_TS1** option to switch between Thi and Ts1 as setpoint sensor. |\n| **HWP_OFF** \t\t| Setpoint sensor temperature > setpoint, so after some time (**HOTCIRCLE_STOP_AFTER** option) hot side pump powered off and gone to power saving mode. |\n| **HWP_ON_by_ev** \t| Hot side pump started after power saving. See **HOTCIRCLE_START_EVERY** option. |\n| **#HotPrp:_seconds_** | Hot side pump is on, waiting for T stabilization. Countdown, seconds. See **HOTCIRCLE_CHECK_PREPARE** option. |\n| **#HotSlp:_seconds_** | Hot side pump in power save mode (sleeping). Waiting for next startup. Countdown, seconds. See **HOTCIRCLE_START_EVERY** option. |\n| **#HPSlp:_seconds_**\t| Compressor: pause between starts. Countdown, seconds. **MINCYCLE_POWEROFF** option.|\n| **#CPpStart** \t| Cold side pump started. |\n| **#CPp:_seconds_** \t| Cold side pumping. Preparing the system to compressor start. Countdown, seconds. **COLDCIRCLE_PREPARE** option. |\n| **#Tho>Max** \t\t| \"Hot out\" temperature is too high. See **T_HOT_MAX** option. |\n| **#Thi>Max** \t\t| \"Hot in\" temperature is too high. See **T_HOT_MAX** option. |\n| **#CaseCold**\t\t| Compressor crankcase temperature is too low. The system can't start. This situation occurs on outdoor installations during a winter season and if AC power lost for a few hours. Wait, while the crankcase heater stabilizing your compressor temperature. See **T_CRANKCASE_MIN** option. |\n| **#CaseHot**        | Compressor is still overheated, waiting. See **T_CRANKCASE_MAX** option. |\n| **#Tae<RefMin**    | \"After evaporator\" temperature too low. Preventing cold loop from freezing and protecting suction line from liquid. See **T_COLDREF_MIN** option. |\n| **#Tbe<RefMin**    | \"Before evaporator\" temperature too low. Preventing cold loop from freezing. See **T_COLDREF_MIN** option. |\n| **#Tbc>Max**        | \"Before condenser\" temperature is too high. Overheat protection. See **T_BEFORE_CONDENSER_MAX** option. |\n| **#Tci<ColdMin**    | \"Cold in\" temperature is too low. Preventing cold loop from freezing. See **T_COLD_MIN** option. |\n| **#Tco<ColdMin**    | \"Cold out\" temperature is too low. Preventing cold loop from freezing. See **T_COLD_MIN** option. |\n| **CWP_ON_CoMin**    | Cold side pump started because cold side temperature is too low, so preventing cold loop freeze, see **T_COLD_MIN** option. |\n\n**Additional messages**\n| Message | description |\n| ------------- | ------------- |\n| **OK:Pr.Cold**\t| Cold side pressure restored. |\n| **OK:Pr.Hot**\t\t| Hot side pressure restored.  |\n| **OK:E.T.Sens.**\t| Temperature sensors restored.|\n| **HWP_ON** \t\t| Hot side pump powered on.    |\n| **Err:_errorcode_**\t| Error code: 1 = temperature sensor error, 2 = Hot side pressure too high, 3 = cold side pressure too low. |\n\n##  Appendix D: secret appendix\nAre you still reading? It seems you are interested in Heat Pumps, so this appendix is for you.<br>\nAbout sensors: avoid using cheap \"waterproof epoxy-covered\" sensors. \"Waterproof\" lasts for a short time.<br>\nBuy DS18B20s chips. No matter what sensors are buying: cheap or at a high price. I've never seen \"bad\" DSes. Solder sensors to the wires and cover with two layers of 2-component epoxy resin as pictured below. It will work for years. White/orange - GND, white/blue - signal, orange - +5V.<br>\n<img src=\"./m_ds18b20_epoxy.jpg\" width=\"500\"><br><br>\nFor sensors at your compressor and discharge (+100 °C and higher) use heat-resistant sleeves at every wire.<br>\n<img src=\"./m_ds18b20_wires_protection.jpg\" width=\"500\"><br><br>\nTo get precise temperature readings protect sensors against ambient air temperature influence with additional thermal insulation. Temperature readings from most of the sensors are interesting, but +/- few degrees does not matter. So, cover most of the sensors with thermal insulation as you wish.<br>\nBut two sensors \"Before evaporator\" and \"After evaporator\" are critical to EEV and needs an extra attention. The temperature of these sensors must be as close to the temperature of the copper tube as it possible. So, install Tae and Tbe sensors as pictured below. You can use thermal paste, but it is no significant difference with much more available silicone. Tape not shown at photos below, for clarity, but should be used with every insulation layer.<br>\n<img src=\"./m_ds18b20_evaporator_mount.jpg\" height=\"700\"><br><br>\nAbout water(glycol)<->refrigerant heat exchangers. You can use plate heat exchangers. Pros: the best efficiency. Cons: costs money. Potential oil return difficulties.<br>\n<img src=\"./m_plate_heat_exchangers.jpg\" width=\"500\"><br><br>\nAnd oxygen brazing with (20%+)silver+copper solder required here:<br>\n<img src=\"./m_plate_echangers_oxygen_brazing.jpg\" width=\"500\"><br><br>\nYou can build your own \"tube-in-tube\" heat exchangers. It's not hard. Cheaper. The heat exchange efficiency is worse. No oil return problems. Very easy soldering. Heat exchanger math: 0.7..1.5 m<sup>2</sup> of a copper tube per every 3kW of heat transfer.<br>\n<img src=\"./m_tube-in-tube_diy1.jpg\" width=\"400\"> <img src=\"./m_tube-in-tube_diy2.jpg\" width=\"400\"><br><br>\nAdditionally, you can think \"I'll take an old AC parts... Housing... Slightly change... An hour or two, day of work maximum and I'll get a refrigerant<->water heat exchanger in for a penny!\". This idea is obvious. It was the first thing I've tried. You can try this, but to achieve \"not very bad\" performance it'll take more than a one day and much more than a few $$, even if you have unlimited access to older ACs.<br>\nOk, I think that's enough for this appendix, this is a controller page, and not how-to-build-refrigeration-systems page.<br>\nOverall, your system with sensor locations will look like at a scheme below. Refrigerators (heat pumps) are simple devices.<br>\n<img src=\"./m_Valden_Heat_Pump_Controller_model.jpg\" width=\"1000\"><br><br>\nYour system works (or sleeps) depending on Thi temperature. For the end user it looks like setting up comfortable temperature of the warm floor via Remote Display.\n\n## Appendix E: Firmware options and fine-tuning\n\nQA tests, uncomment to enable\n```c\n//#define SELFTEST_RELAYS_LEDS_SPEAKER \t//speaker and relays QA test, uncomment to enable\n//#define SELFTEST_EEV \t\t\t//EEV QA test, uncomment to enable\n//#define SELFTEST_T_SENSORS \t\t//temperature sensors QA test, uncomment to enable\n```\n\nCommunication protocol with an external world. Choose one\n\n```c\n//#define RS485_JSON 1 \t\t//JSON, external systems integration\n//#define RS485_HUMAN 2 \t//RS485 is used in the same way as the local console, warning: Use only if 2 devices (server and this controller) connected to the same RS485 line\n#define RS485_MODBUS 3 \t\t//default, MODBUS via RS485, connection to the display (both sensor or 1602, see https://GitHub.com/OpenHP/Display/) or connection to any other MODBUS application or device \n```\n\nSystem type, comment both if HP with EEV\n```c\n//#define EEV_ONLY \t//Valden controller as EEV controller: NO target T sensor. No relays. Oly EEV. Sensors required: Tae, Tbe, current sensor. Additional T sensors can be used but not required.\n//#define NO_EEV \t//capillary tube or TXV, EEV not used\n```\n\nSensor used to check setpoint, uncomment one of those options\n```c\n#define SETPOINT_THI \t//\"warm floor\" scheme: \"hot in\" (Thi) temperature used as setpoint\n//#define SETPOINT_TS1 \t//\"swimming pool\" or \"water tank heater\" scheme: \"sensor 1\" (Ts1) is used as setpoint and located somewhere in a water tank\n```\n\nSome more options\n```c\n#define HUMAN_AUTOINFO\t30000\t//print stats to console, every milliseconds\n#define WATCHDOG\t\t//disable for older bootloaders\n```\n\n<b>Next sections: advanced options</b><br>\n<img src=\"./m_add_graph.png\" width=\"826\"><br>\nTemperature sensors used in a system, comment to disable \n\n```c\n#define T_cold_in;\t\t//cold side (heat source) inlet sensor\n#define T_cold_out;\t\t//cold side outlet sensor\n#define T_before_evaporator;\t//\"before\" and \"after evaporator\" sensors required to control EEV, both \"EEV_ONLY\" and \"full\" schemes \n#define T_after_evaporator;\t//\"before\" and \"after evaporator\" sensors required to control EEV, both \"EEV_ONLY\" and \"full\" schemes \n#ifdef SETPOINT_TS1\n\t#define T_sensor_1;\t//T values from the additional sensor S1 used as a \"setpoint\" in \"pool\" or \"water tank heater\" schemes \n#endif\n//#define T_sensor_2;\t\t//additional sensor, any source; for example, outdoor temperature, in-case temperature, and so on\n#define T_crc;\t\t\t//if defined, enables the crankcase T sensor and crankcase heater on the relay \"Crankcase heater\"\n//#define T_regenerator;\t//an additional sensor, the regenerator temperature sensor (inlet or outlet or housing); used only to obtain a temperature data if necessary \n#define T_afrer_condenser;\t//after condenser (and before valve)\n#define T_before_condenser;\t//before condenser (discharge)\n#define T_hot_out;\t\t//hot side outlet\n//In full scheme Hot IN required! Optional in \"EEV_ONLY\" scheme (see \"EEV_ONLY\" option), \n#define T_hot_in;\t\t//hot side inlet\n```\n\nTemperature limits\n```c\n#define MAGIC\t\t0x66;\t//change this value if you want to rewrite the T setpoint in EEPROM \n#define\tT_SETPOINT\t26.0;\t//This is a predefined target temperature value (start temperature). EEPROM-saved. Ways to change this value: 1. Console command 2. Change the \"setpoint\" on a display 3. Change value here AND change \"magic number\" 4. JSON command\n#define T_SETPOINT_MAX\t48.0;\t//maximum \"setpoint\" temperature that an ordinary user can set\n#define T_SETPOINT_MIN\t10.0;\t//min. \"setpoint\" temperature that an ordinary user can set, lower values not recommended until antifreeze fluids at hot side used.\n#define T_CRANKCASE_MIN\t\t8.0;\t//compressor (crankcase) min. temperature, HP will not start if T lower\n#define T_CRANKCASE_MAX\t\t110.0;\t//compressor (crankcase) max. temperature, overheating protection, HP will stop if T higher\n#define T_CRANKCASE_HEAT_THRESHOLD 16.0;//crankcase heater threshold, the compressor heater will be powered on if T lower\n#define T_WORKINGOK_CRANKCASE_MIN  25.0;//compressor temperature: additional check. HP will stop if T is lower than this value after 5 minutes of work. Do not set the value too high to ensure normal operation after long pauses. \n#define T_BEFORE_CONDENSER_MAX\t108.0;\t//discharge MAX, system stops if discharge higher\n#define T_COLDREF_MIN \t\t-14.0;\t//suction min., HP stops if T lower, cold side (glycol) loop freeze protection and compressor protection against liquid \n#define T_BEFORE_EVAP_WORK_MIN \t-25.5;\t//!!!before evaporator (after valve) min. T; can be very low for a few minutes after a startup, ex: capillary tube in some conditions; and for all systems: after long shut-off, lack of refrigerant, 1st starts, and many others\n#define T_COLD_MIN \t\t-15.5;\t//cold side (glycol) loop freeze protection: HP stops if inlet or outlet temperature lower\n#define T_HOT_MAX \t\t50.0;\t//hot loop: HP stops if hot side inlet or outlet temperature higher than this threshold\n```\n\nWatts, cycles times (milliseconds)\n```c\n#define MAX_WATTS\t1000.0 + 70.0 + 80.0\t//power limit, watt, HP stops if exceeded, example: compressor: ~1000 + hot CP 70 + cold CP 80\n#define POWERON_PAUSE     \t300000    //after power on: \t\t\twait 5 minutes before starting HP (power faults protection) \n#define MINCYCLE_POWEROFF \t600000    //after a normal compressor stop: \t10 minutes pause (max 99999 seconds) \n#define MINCYCLE_POWERON  \t3600000  //after compressor start: \t\tminimum compressor operation time, i.e. work time is not less than this value (or more, depending on the setpoint temperature) 60 minutes = 3.6 KK 120mins = 5.4 kK.\n#define POWERON_HIGHTIME\t7000\t//after compressor start: \t\tdefines time when power consumption can be 3 times greater than normal, 7 sec. by default\n#define COLDCIRCLE_PREPARE\t90000\t//before compressor start:\t\tpower on cold CP and wait 90 sec.; if false start: CP will off twice this time; and (hotcircle_stop_after - this_value) must be > hotcircle_check_prepare or HP will go sleep cycle instead of start\n#define DEFFERED_STOP_HOTCIRCLE\t1200000\t//after compressor stop:\t\twait 20 minutes, if no need to start compressor: stop hot WP; value must be > 0\n#define HOTCIRCLE_START_EVERY\t2400000\t//while pauses:\t\t\t\tpump on \"hot side\"  starts every 40 minutes (by default) (max 9999 seconds) to circulate water and get exact temperature reading, option used if \"warm floor\" installation (Thi as setpoint)...\n#define HOTCIRCLE_CHECK_PREPARE\t150000\t//while pauses:\t\t\t\t...and wait for temperature stabilization 2.5 minutes (by default), after that do setpoint checks...\n#define HOTCIRCLE_STOP_AFTER\t(HOTCIRCLE_CHECK_PREPARE + COLDCIRCLE_PREPARE + 30000)\t\t//...and then stop after few minutes of circulating, if temperature is high and no need to start compressor; value must be check_prepare + coldcircle_prepare + 30 seconds (or more)\n```\n\nEEV options.<br>\n<img src=\"./m_add_eev.jpg\" height=\"200\"><br>\nIf you are using a capillary tube or TXV: simply skip next section.<br>\nDepending on how many milliseconds allocated per step, the speed of automatic tuning will change.<br>\nRemember that your refrigeration system reaction on every step is not immediate. The system reacts after a few minutes, sometimes after tens of minutes.<br>\n```c\n#define EEV_MAXPULSES\t\t250\t//max steps, 250 is tested for sanhua 1.3\n\n//steps tuning: milliseconds per fast and slow (precise) steps\n#define EEV_PULSE_FCLOSE_MILLIS\t20\t//fast closing, closing on danger\t\t\t(milliseconds per step)\n#define EEV_PULSE_CLOSE_MILLIS\t60000\t//accurate closing while the compressor works \t\t(milliseconds per step)\n#define EEV_PULSE_WOPEN_MILLIS\t20\t//standby (waiting) pos. set\t\t\t\t(milliseconds per step)\n#define EEV_PULSE_FOPEN_MILLIS\t1400\t//fast opening, fast search \t\t\t\t(milliseconds per step)\n#define EEV_PULSE_OPEN_MILLIS\t70000\t//accurate opening while the compressor works\t\t(milliseconds per step)\n#define EEV_STOP_HOLD\t\t500\t//0.1..1sec for Sanhua\t\thold time\t\t(milliseconds per step)\n#define EEV_CLOSEEVERY\t\t86400000\t//86400000: EEV full close (zero calibration) every 24 hours, executed while HP is NOT working\t(milliseconds per cycle)\n\n//positions\n#define EEV_CLOSE_ADD_PULSES\t8\t//read below, additional steps after zero position while full closing \n#define EEV_OPEN_AFTER_CLOSE\t45\t//0 - set the zero position, then add EEV_CLOSE_ADD_PULSES (zero insurance, read EEV guides for this value) and stop, EEV will be in zero position. \n\t\t\t\t\t//N - set the zero position, then add EEV_CLOSE_ADD_PULSES, than open EEV on EEV_OPEN_AFTER_CLOSE pulses\n\t\t\t\t\t//i.e. it's a \"waiting position\" while HP isn't working, value must be <= MINWORKPOS\n#define EEV_MINWORKPOS\t\t50\t//position will be not less during normal work, open EEV to this position after compressor start\n\n//temperatures\n#define EEV_PRECISE_START\t7.0\t//precise tuning threshold: \t\tmake slower pulses if (real_diff-target_diff) less than this value. Used for fine auto-tuning\n#define EEV_EMERG_DIFF\t\t1.7\t//liquid at suction threshold:\t\tif dangerous condition occurred, real_diff =< (target_diff - EEV_EMERG_DIFF)  then EEV will be closed to min. work position //Ex: EEV_EMERG_DIFF = 2.0, target diff 5.0, if real_diff =< (5.0 - 2.0) then EEV will be closed to EEV_MINWORKPOS\n#define EEV_HYSTERESIS\t\t0.5\t//hysteresis, to stop fine-tuning:\tmust be less than EEV_PRECISE_START, ex: target difference = 4.0, hysteresis = 0.3, no EEV pulses will be done while real difference in range 4.0..4.3 \n#define EEV_TARGET_TEMP_DIFF\t3.6\t//target difference between Before Evaporator and After Evaporator, the head of the whole algorithm\n\n//additional options\n#define EEV_REOPENLAST\t\t1\t//1 = reopen to last position on compressor start, useful for ordinary schemes with everyday working cycles, 0 = not\n#define EEV_REOPENMINTIME\t40000\t//after system start: min. delay between \"min. work pos.\" (must be > 0 in this case and > waiting position) set and reopening start\n//#define EEV_MANUAL\t\t\t//comment to disable, manual set of EEV position via a console; warning: this option will stop all EEV auto-activities, including zero position find procedure; so this option not recommended: switch auto/manual mode from a console\n\n//do not use next option if you're not sure what are you doing\n//#define EEV_DEBUG\t\t\t\t//debug, useful during system fine-tuning, works both with local serial and RS485_HUMAN\n```\n\nCommunication addresses\n```c\nconst char devID  = 0x45;\t//used only if JSON communication, does not matter for MODBUS and Valden display https://github.com/OpenHP/Display/\nconst char hostID = 0x30;\t//used only if JSON communication, not used for MODBUS\n```\n\nLast option\n```c\n#define MAX_SEQUENTIAL_ERRORS \t15 \t\t//max cycles to wait auto-clean error, ex: T sensor appears, stop compressor after counter exceeded (millis_cycle * MAX_SEQUENTIAL_ERRORS)\n```\n## Appendix D: bill of materials\n<img src=\"./m_add_parts.jpg\"><br>\n| Part | Quantity |\n| ------------- | ------------- |\n| **1206 Resistors:**\t||\n| 10\t| 1\t|\n| 100\t| 1\t|\n| 120\t| 1\t|\n| 1K\t| 7\t|\n| 10K\t| 6\t|\n| 100K\t| 2\t|\n| 22\t| 1\t|\n| 2.2K\t| 4\t|\n| 470\t| 10\t|\n| **1206 Caps:**\t||\n| 0.01uF\t| 2\t|\n| 0.1uF\t\t| 4\t|\n| 1uF\t\t| 8\t|\n| 10uF\t\t| 5\t|\n| **1206 LEDs:**\t||\n| Red (error LEDs)\t| 2\t|\n| Green (OK LED)\t| 1\t|\n| Yellow \t\t| 11\t|\n| **SOP(SOIC) ICs:**\t|\t|\n| ADM2587EBRWZ (SOIC-20)\t| 1\t|\n| 74HC4067D (SOIC-24)\t\t| 1\t|\n| 74HC595D (SOP-16)\t\t| 3\t|\n| ULN2003A_(SOP-16)\t\t| 2\t|\n| 817S (SOP-4)\t\t\t| 2\t|\n| **XH2.54 Headers + Plugs:**\t|\t|\n| XH2.54-6P header + 6P plug\t| 4\t|\n| XH2.54-3P header + 3P plugs\t| 2\t|\n| XH2.54-2P header + 2P Plugs\t| 1\t|\n| XH2.54 Crimp terminal\t\t| 40\t|\n| **Power terminals:**\t\t|\t|\n| 6.35 Blade terminal (726386-2 or same)\t\t| 16\t|\n| 6.35 Quick disconnect crimp terminal insulated\t| 16\t|\n| **Others:**\t|\t\t\t\t|\t\n| 10nF HV-9.0x3.0 (blue disc 2kV HV cap)\t| 1\t|\n| 22uf_16v D5.0xF2.0 (electrolytic cap)\t\t| 1\t|\n| Resistor Network\\*4 DIP-1X5P-2.54 (3..5K)\t| 3\t|\n| MMBT2222A (SOT-23-3)\t\t\t\t| 1\t|\n| LM7805 (TO-220)\t\t\t\t| 1\t|\n| SMIH-12VDC-SL-C\t\t\t\t| 4\t|\n| BUZZER-R9.0-2P-4.0\t\t\t\t| 1\t|\n| ARDUINO PRO MINI\t\t\t\t| 1\t|\n| Power supply, 12v1.25A 70x30x40 (or any 0.5A+)| 1\t|\n| DS18B20\t\t\t\t\t| 12\t|\n| USB<->UART (to upload firmware)\t\t| 1\t|\n| Current sensor SCT-013-000\t\t\t| 1\t|\n\n## License\n© 2018-2021 D.A.A. All rights reserved; gonzho AT web.de; https://github.com/openhp/HeatPumpController/.<br>\n\nText, media and other materials licensed under [CC-BY-SA License v4.0](https://creativecommons.org/licenses/by-sa/4.0/).<br>\n<sub>Attribution: You must clearly attribute Valden Heat Pump Controller (https://github.com/openhp/HeatPumpController/) original work in any derivative works.<br>\nShare and Share Alike: If you make modifications or additions to the content you re-use, you must license them under the CC-BY-SA License v4.0 or later.<br>\nIndicate changes: If you make modifications or additions, you must indicate in a reasonable fashion that the original work has been modified.<br>\nYou are free: to share and adapt the material for any purpose, even commercially, as long as you follow the license terms.</sub><br>\n\nThe firmware source code licensed under [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html). <br>\n<sub>This product is distributed in the hope that it will be useful,\tbut 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.</sub><br>\n\nFor third-party libraries licenses used in this product please refer to those libraries.<br>\n## Author\n<br>\ngonzho АТ web.de (c) 2018-2021<br>\n"
  },
  {
    "path": "Valden_HeatPumpController.ino",
    "content": "/*\n\t\n\tValden Heat Pump.\n\t\n\tHeat Pump Controller firmware.\n\t\n\thttps://github.com/OpenHP/\n\t\n\tCopyright (C) 2018-2021 gonzho@web.de\n\t\n\t\n\n\tThis program is free software: you can redistribute it and/or modify\n\tit under the terms of the GNU General Public License as published by\n\tthe Free Software Foundation, either version 3 of the License, or\n\t(at your option) any later version.\n\n\tThis program is distributed in the hope that it will be useful,\n\tbut WITHOUT ANY WARRANTY; without even the implied warranty of\n\tMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\tGNU General Public License for more details.\n\n\tYou should have received a copy of the GNU General Public License\n\talong with this program.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n\n//-----------------------USER OPTIONS-----------------------\n//#define SELFTEST_RELAYS_LEDS_SPEAKER\t\t//speaker and relays QA test, uncomment to enable\n//#define SELFTEST_EEV\t\t\t\t//EEV QA test, uncomment to enable\n//#define SELFTEST_T_SENSORS\t\t\t//temperature sensors QA test, uncomment to enable\n\n//communication protocol with external world\n//#define RS485_JSON\t\t1  \t\t//json, external systems integration\n//#define RS485_HUMAN   \t2\t\t//RS485 is used in the same way as the local console, warning: Use only if 2 devices (server and this controller) connected to the same RS485 line\n#define RS485_MODBUS \t\t3 \t\t//default, MODBUS via RS485, connection to the display (both sensor or 1602, see https://GitHub.com/OpenHP/Display/) or connection to any other MODBUS application or device \n\n//system type, comment both if HP with EEV\n//#define\tEEV_ONLY\t\t\t//Valden controller as EEV controller: NO target T sensor. No relays. Oly EEV. Sensors required: Tae, Tbe, current sensor. Additional T sensors can be used but not required.\n//#define\tNO_EEV\t\t\t\t//capillary tube or TXV, EEV not used\n\n//which sensor is used to check setpoint, uncomment one of options\n#define SETPOINT_THI\t\t\t\t//\"warm floor\" scheme: \"hot in\" (Thi) temperature used as setpoint\n//#define SETPOINT_TS1\t\t\t\t//\"swimming pool\" or \"water tank heater\" scheme: \"sensor 1\" (Ts1) is used as setpoint and located somewhere in a water tank\n\n#define HUMAN_AUTOINFO\t30000\t\t\t//print stats to console, every milliseconds\n\n#define WATCHDOG          \t\t\t//disable for older bootloaders\n//-----------------------USER OPTIONS END-----------------------\n\n\n\n//-----------------------Fine Tuning OPTIONS-----------------------\n//next sections: advanced options\n\n\n\n//-----------------------T Sensors -----------------------\n//temperature sensors used in a system, comment to disable \n#define T_cold_in;\t\t\t//cold side (heat source) inlet sensor\n#define T_cold_out;\t\t\t//cold side outlet sensor\n#define T_before_evaporator;\t\t//\"before\" and \"after evaporator\" sensors required to control EEV, both \"EEV_ONLY\" and \"full\" schemes  \n#define T_after_evaporator;\t\t//\"before\" and \"after evaporator\" sensors required to control EEV, both \"EEV_ONLY\" and \"full\" schemes \n//#define T_separator_gas;\t\t//no longer used (PCB 1.3 MI +) artifact from experimental scheme with separator \n//#define T_separator_liquid;\t\t//no longer used (PCB 1.3 MI +) artifact from experimental scheme with separator \n//#define T_before_valve;\t\t//no longer used (PCB 1.3 MI +) artifact from experimental scheme with separator \n//#define T_suction;\t\t\t//no longer used (PCB 1.3 MI +) artifact from experimental scheme with separator \n#ifdef SETPOINT_TS1\n\t#define T_sensor_1;\t\t//T values from the additional sensor S1 used as a \"setpoint\" in \"pool\" or \"water tank heater\" schemes  \n#endif\n//!!!\n#define T_sensor_2;\t\t\t//additional sensor, any source; for example, outdoor temperature, in-case temperature, and so on\n#define T_crc;\t\t\t\t//if defined, enables the crankcase T sensor and crankcase heater on the relay \"Crankcase heater\"\n//#define T_regenerator;\t\t//an additional sensor, the regenerator temperature sensor (inlet or outlet or housing); used only to obtain a temperature data if necessary \n#define T_afrer_condenser;\t\t//after condenser (and before valve)\n//!!!#define T_before_condenser;\t//before condenser (discharge)\n#define T_hot_out;\t\t\t//hot side outlet\n//In full scheme Hot IN required! Optional in \"EEV_ONLY\" scheme (see \"EEV_ONLY\" option), \n#define T_hot_in;\t\t\t//hot side inlet\n\n//-----------------------TEMPERATURES-----------------------\n#define MAGIC     \t\t0x66;  \t\t//change this value if you want to rewrite the T setpoint in EEPROM \n#define\tT_SETPOINT\t\t26.0;\t\t//This is a predefined target temperature value (start temperature). EEPROM-saved. Ways to change this value: 1. Console command 2. Change the \"setpoint\" on a display 3. Change value here AND change \"magic number\" 4. JSON command\n#define T_SETPOINT_MAX \t\t48.0;  \t\t//maximum \"setpoint\" temperature that an ordinary user can set\n#define T_SETPOINT_MIN\t\t10.0;\t\t//min. \"setpoint\" temperature that an ordinary user can set, lower values not recommended until antifreeze fluids at hot side used.\n#define T_CRANKCASE_MIN \t\t8.0;\t//compressor (crankcase) min. temperature, HP will not start if T lower\n#define T_CRANKCASE_MAX \t\t110.0;\t//compressor (crankcase) max. temperature, overheating protection, HP will stop if T higher\n#define T_CRANKCASE_HEAT_THRESHOLD \t16.0;\t//crankcase heater threshold, the compressor heater will be powered on if T lower\n#define T_WORKINGOK_CRANKCASE_MIN \t25.0;\t//compressor temperature: additional check. HP will stop if T is lower than this value after 5 minutes of work. Do not set the value too high to ensure normal operation after long pauses. \n#define T_BEFORE_CONDENSER_MAX \t108.0;      \t//discharge MAX, system stops if discharge higher\n#define T_COLDREF_MIN \t\t-14.0;\t\t//suction min., HP stops if T lower, cold side (glycol) loop freeze protection and compressor protection against liquid \n#define T_BEFORE_EVAP_WORK_MIN \t-25.5;\t\t//!!!before evaporator (after valve) min. T; can be very low for a few minutes after a startup, ex: capillary tube in some conditions; and for all systems: after long shut-off, lack of refrigerant, 1st starts, and many others\n#define T_COLD_MIN \t\t-15.5;\t\t//cold side (glycol) loop freeze protection: HP stops if inlet or outlet temperature lower\n#define T_HOT_MAX \t\t50.0;\t\t//hot loop: HP stops if hot side inlet or outlet temperature higher than this threshold\n\n//#define T_REG_HEAT_THRESHOLD\t17.0;\t\t//no longer used (PCB 1.3 MI +) artifact from experimental scheme with separator \n//#define T_HOTCIRCLE_DELTA_MIN \t2.0;\t//not used since ~FW v1.6, \"water heater with intermediate heat exchanger\" scheme, where Ts1 == \"sensor in water\"; hot side CP will be switched on if \"Ts1 - hot_out > T_HOTCIRCLE_DELTA_MIN\"\n\n//-----------------------WATTS AND CYCLES TIMES-----------------------\n//time: milliseconds, power: watts\n#define MAX_WATTS\t1000.0 + 70.0 + 80.0\t//power limit, watt, HP stops if exceeded, examples: \t//\tinstallation1: compressor 165: 920 Watts, + 35 watts 25/4 circ. pump at 1st speed + 53 watts 25/4 circ. pump at 2nd speed\n\t\t\t\t\t\t\t\t\t\t\t\t\t//\tinstallation2: compressor unk: ~1000 + hot CP 70 + cold CP 80 = 1150 watts\n\t\t\t\t\t\t\t\t\t\t\t\t\t//\tinstallation3: and so on\n#define POWERON_PAUSE     \t300000    \t//after power on: \t\t\twait 5 minutes before starting HP (power faults protection) \n#define MINCYCLE_POWEROFF \t600000    \t//after a normal compressor stop: \t10 minutes pause (max 99999 seconds) \n#define MINCYCLE_POWERON  \t3600000  \t//after compressor start: \t\tminimum compressor operation time, i.e. work time is not less than this value (or more, depending on the setpoint temperature) 60 minutes = 3.6 KK 120mins = 5.4 kK.\n#define POWERON_HIGHTIME\t7000\t\t//after compressor start: \t\tdefines time when power consumption can be 3 times greater than normal, 7 sec. by default\n#define COLDCIRCLE_PREPARE\t90000\t\t//before compressor start:\t\tpower on cold CP and wait 90 sec.; if false start: CP will off twice this time; and (hotcircle_stop_after - this_value) must be > hotcircle_check_prepare or HP will go sleep cycle instead of start\n#define DEFFERED_STOP_HOTCIRCLE\t1200000\t\t//after compressor stop:\t\twait 20 minutes, if no need to start compressor: stop hot WP; value must be > 0\n#define HOTCIRCLE_START_EVERY\t2400000\t\t//while pauses:\t\t\t\tpump on \"hot side\"  starts every 40 minutes (by default) (max 9999 seconds) to circulate water and get exact temperature reading, option used if \"warm floor\" installation (Thi as setpoint)...\n#define HOTCIRCLE_CHECK_PREPARE\t150000\t\t//while pauses:\t\t\t\t...and wait for temperature stabilization 2.5 minutes (by default), after that do setpoint checks...\n#define HOTCIRCLE_STOP_AFTER\t(HOTCIRCLE_CHECK_PREPARE + COLDCIRCLE_PREPARE + 30000)\t\t//...and then stop after few minutes of circulating, if temperature is high and no need to start compressor; value must be check_prepare + coldcircle_prepare + 30 seconds (or more)\n\n\n//-----------------------EEV-----------------------\n//If you are using a capillary tube or TXV: simply skip next section.\n//Depending on how many milliseconds allocated per step, the speed of automatic tuning will change.\n//Remember that your refrigeration system reaction on every step is not immediate. The system reacts after a few minutes, sometimes after tens of minutes.\n\n#define EEV_MAXPULSES\t\t250\t\t//max steps, 250 is tested for sanhua 1.3\n\n//steps tuning: milliseconds per fast and slow (precise) steps\n#define EEV_PULSE_FCLOSE_MILLIS\t20\t\t//(20 tube evaporator)\t\tfast closing, closing on danger\t\t\t(milliseconds per step)\n#define EEV_PULSE_CLOSE_MILLIS\t45000\t\t//(50000 tube evaporator)\taccurate closing while the compressor works \t(milliseconds per step)\n#define EEV_PULSE_WOPEN_MILLIS\t20\t\t//(20 tube evaporator)\t\tstandby (waiting) pos. set\t\t\t(milliseconds per step)\n#define EEV_PULSE_FOPEN_MILLIS\t1400\t\t//(1300 tube evaporator)\tfast opening, fast search \t\t\t(milliseconds per step)\n#define EEV_PULSE_OPEN_MILLIS\t30000\t\t//(60000 tube evaporator)\taccurate opening while the compressor works\t(milliseconds per step)\n#define EEV_STOP_HOLD\t\t500\t\t//0.1..1sec for Sanhua\t\thold time\t\t\t\t\t(milliseconds per step)\n#define EEV_CLOSEEVERY\t\t86400000\t//86400000: EEV full close (zero calibration) every 24 hours, executed while HP is NOT working\t(milliseconds per cycle)\n\n//positions\n#define EEV_CLOSE_ADD_PULSES\t8\t\t//read below, additional steps after zero position while full closing \n#define EEV_OPEN_AFTER_CLOSE\t45\t\t//0 - set the zero position, then add EEV_CLOSE_ADD_PULSES (zero insurance, read EEV guides for this value) and stop, EEV will be in zero position. \n\t\t\t\t\t\t//N - set the zero position, then add EEV_CLOSE_ADD_PULSES, than open EEV on EEV_OPEN_AFTER_CLOSE pulses\n\t\t\t\t\t\t//i.e. it's a \"waiting position\" while HP isn't working, value must be <= MINWORKPOS\n#define EEV_MINWORKPOS\t\t50\t\t//position will be not less during normal work, open EEV to this position after compressor start\n\n//temperatures\n#define EEV_PRECISE_START\t8.6\t\t//(8.6 tube evaporator) \tprecise tuning threshold: \t\tmake slower pulses if (real_diff-target_diff) less than this value. Used for fine auto-tuning\n#define EEV_EMERG_DIFF\t\t1.7\t\t//(2.5 tube evaporator) \tliquid at suction threshold:\t\tif dangerous condition occurred, real_diff =< (target_diff - EEV_EMERG_DIFF)  then EEV will be closed to min. work position //Ex: EEV_EMERG_DIFF = 2.0, target diff 5.0, if real_diff =< (5.0 - 2.0) then EEV will be closed to EEV_MINWORKPOS\n#define EEV_HYSTERESIS\t\t0.45\t\t//(0.6 tube evaporator) \thysteresis, to stop fine tuning:\tmust be less than EEV_PRECISE_START, ex: target difference = 4.0, hysteresis = 0.3, no EEV pulses will be done while real difference in range 4.0..4.3 \n#define EEV_TARGET_TEMP_DIFF\t3.6\t\t//(3.6 tube evaporator) \ttarget difference between Before Evaporator and After Evaporator, the head of the whole algorithm\n\n//additional options\n#define EEV_REOPENLAST\t\t1\t\t///1 = reopen to last position on compressor start, useful for ordinary schemes with everyday working cycles, 0 = not\n#define EEV_REOPENMINTIME\t40000\t\t//after system start: min. delay between \"min. work pos.\" (must be > 0 in this case and > waiting position) set and reopening start\n//#define EEV_MANUAL\t\t\t\t//comment to disable, manual set of EEV position via a console; warning: this option will stop all EEV auto-activities, including zero position find procedure; so this option not recommended: switch auto/manual mode from a console\n\n//do not use next option if you're not sure what are you doing\n//#define EEV_DEBUG\t\t\t\t//debug, useful during system fine-tuning, works both with local serial and RS485_HUMAN\n//-----------------------ADDRESSES-----------------------\nconst char devID  = 0x45;\t//used only if JSON communication, does not matter for MODBUS and Valden display https://github.com/OpenHP/Display/\nconst char hostID = 0x30;\t//used only if JSON communication, not used for MODBUS\n\n//-----------------------OTHER-----------------------\n#define MAX_SEQUENTIAL_ERRORS \t15 \t\t//max cycles to wait auto-clean error, ex: T sensor appears, stop compressor after counter exceeded (millis_cycle * MAX_SEQUENTIAL_ERRORS)\n//-----------------------Fine Tuning OPTIONS END -----------------------\n\n//-----------------------changelog-----------------------\n/*\nv1.0, 01 Sep 2019:\n+ initial version, hardware and software branch ready\n\nv1.1: 21 Sep 2019:\n+ Dev and Host ID to header\n\nv1.2: 20 Dec 2019:\n+- ?seems to be fixed minor bug while HP stopped: wattage is 0, if tCrc < T_CRANKCASE_HEAT_THRESHOLD and may be few sensors absence\n+ min_user_t/max_user_t to header\n\nv1.3: 05 Jan 2020:\n+ manual EEV mode (high priority, ex: new system 1st starts and charge) \n+ rs485_modbus\n+ reopen to last EEV value at startup\n\nv1.4: 22 Jan 2020\n+ crankcase naming\n\nv1.5: 05 Jun 2020\n+ minor modbus updates\n\nv1.6: 09 Dec 2020\n+ NO_EEV option\n+ some variables renames\n+ Tho instead of Thi (stop conditions) bugfix\n+ Last Start Message added\n\nv1.7: 03 Feb 2021\n+ 1.3 PCB revision support, previous revisions also supported\n+ enable cold circle if tci < col_min (circulate ground loop, if outdoor installation and very cold and deep freeze)\n+ inputs support\n+ add option \"Thi\" and \"Ts1\" to header, enable Ts1 by this option\n+ temperature check after start of hot side circle + 5 mins for Thi target\n\nv1.8: 06 Feb 2021\n+ very rare case: 0.0 readings, 2-3 attempts then pass 0.0\n+ countdown for compressor relay after cold CP start (stab. cold loop T)\n+ self-test options to header\n\nv1.9-1.11: 25-27 Feb 2021:\n+ lot of small workflow logic and user terminal changes\n\nv1.12: 21 Mar 2021:\n+ TS1/THO #define way fix\n+ CWP and HWP prepare optimisation\n\nv1.13: 26 Mar 2021:\n+ rounding error via Modbus found and fixed\n\n//TODO:\n? lower bit resolution for all sensors, except Tbe, Tae, Ts1 ?\n? poss. DoS: infinite read to nowhere, fix it, set finite counter (ex: 200)\n? add \"heater start\" and \"cold circle start\" and \"not start HP\" if t_crc < t_coldin/coldout(?)/tae/tbe(?) + 2.0\n? ref. migration protection for summer season with long waiting periods: start cold circle and crankcase heater if tCrc =< tci+1, add option to header\n? EEV manual mode and position by RS485 python or modbus command ?\n? add speaker and err code for \"\"ERR: no Tae or Tbe for EEV!\"\"\n? deffered HWP stop: check HP stop cause, stop HWP if protective/error stop\n? wclose and fclose to EEV\n? valve_4way\n? rewite re-init proc from MAGIC to another way\n? EEV: target to EEPROM (?? no need ?)\n? EEV: define maximum working position\n*/\n//-----------------------changelog END-----------------------\n\n// DS18B20 pins: GND DATA VDD\n\n//Connections:\n//DS18B20 Pinout (Left to Right, pins down, flat side toward you)\n//- Left   = Ground\n//- Center = Signal (Pin N of arduino):  (with 3.3K to 4.7K resistor to +5 or 3.3 )\n//- Right  = +5 or +3.3 V   \n//\n\n//Speaker\n//\n// high volume scheme:        +---- +5V (12V not tested)\n//                            |\n//                       +----+\n//                    1MOhm   piezo\n//                       +----+\n//                            |(C)\n// pin -> 1.6 kOhms -> (B) 2n2222        < front here\n//                            |(E)\n//                            +--- GND\n//\n\n/*\nscheme SCT-013-000:\n\n2 pins used: tip and sleeve, center (ring) not used http://cms.35g.tw/coding/wp-content/uploads/2014/09/SCT-013-000_UNO-1.jpg\npins are interchangeable due to AC\n\n32 Ohms (22+10) between sensor pins  (35 == ideal)\n\nPin1: \n- via elect. cap. to GND\n- via ~10K..470K resistor to GND\n- via ~10K..470K resistor to +5 (same as prev.)\nif 10K+10K used: current is 25mA\nuse 100K+100K for 3 phases\n\nPin2:\n- to analog pin\n- via 32..35 Ohms resistor to Pin1\n\n+5 -------------------------+\n                            |                  \n                            |                                            \n                            # R1 10K+                        \n                            |                                \n                            |                                \n                            |~2.5 at this point              \n            +---------------+--------------------------------------+----+\n            |               |                                      |    |\n            #_ elect. cap.  # R2 10K+ (same as R1)     SCT-013-000 $    # R3 = 35 Ohms (ideal case), 32 used  \n            |               |                                      |    |\nGND --------+---------------+                                      +----+--------> to Analog pin\n\n\nWARNING: calibrate 3 sensors together, from different sellers, due to case of incorrectly worked 1 of 3 sensor\n\nP(watts)=220*220/R(Ohms)\n*/\n\n//\n//MAX 485 voltage - 5V\n//\n// use resistor at RS-485 GND\n// 1st test: 10k result lot of issues\n// 2nd test: 1k, issues\n// 3rd test: 100, see discussions\n\n\n//16-ch Multiplexer EN pin: active LOW, connect to GND\n\n\n/*\nrelay 1: heat pump\nrelay 2: hot side circulator pump\nrelay 3: cold side circulator pump\nrelay 4: crankcase heater\nrelay 5: (1.3+: not used anymore)\n\nrelay 6: reserved\nrelay 7: reserved\n\nT sensors: \n\n0 cold_in;\n1 cold_out;\n2 before_evaporator;\n3 after_evaporator;\n4 separator_gas;\t//if flooded evaporator: separator out\n5 separator_liquid;\t//if flooded evaporator: separator out\n6 before_valve;\t\t//before expansion valve, if regenerator used\n7 suction;\t\t//compressor suction, if regenerator\n8 sensor_1;\t\t//additional sensor 1\n9 sensor_2;\t\t//additional sensor 2\nA crankcase;\t\t//compressor case\nB regenerator;\nC afrer_condenser;\nD before_condenser;\nE hot_out;\nF hot_in;\n*/\n\nString fw_version = \"1.13\";\n\n//hardware resources\n#define RELAY_HEATPUMP        \tA2\n#define RELAY_HOTSIDE_CIRCLE  \tA1\n\n#define PR_LOW\t\tA6\n#define PR_HIGH\t\tA7\n\n#define OW_BUS_ALLTSENSORS    9\n#define speakerOut            6\n#define em_pin1               A3\n\n\nString hw_version = \"v1.1+\";\n\n#define LATCH_595 \t\t3\n#define CLK_595 \t\t2\n#define DATA_595 \t\t7\n#define OE_595 \t\t\t4\n\n//---------------------------memory debug\n#ifdef __arm__\n\t// should use uinstd.h to define sbrk but Due causes a conflict\n\textern \"C\" char* sbrk(int incr);\n#else // __ARM__\n\textern char *__brkval;\n#endif // __arm__\n     \nint freeMemory() {\n\tchar top;\n\t#ifdef __arm__\n\t\treturn &top - reinterpret_cast<char*>(sbrk(0));\n\t#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)\n\t\treturn &top - __brkval;\n\t#else // __arm__\n\t\treturn __brkval ? &top - __brkval : &top - __malloc_heap_start;\n\t#endif // __arm__\n}\n//---------------------------memory debug END\n\n    \n#include <avr/wdt.h>\n#include <EEPROM.h>\n\n#define SEED \t0xFFFF\n#define POLY\t0xA001\nunsigned int \tcrc16;\nint \t\tcf;\n#define MODBUS_MR 50\t//50 ok now\n\n#include <SoftwareSerial.h>\n#define SerialRX        12\t//RX connected to RO - Receiver Output  \n#define SerialTX        11\t//TX connected to DI - Driver Output Pin\n#define SerialTxControl 13\t//RS485 Direction control DE and RE to this pin\n#define RS485Transmit    HIGH\n#define RS485Receive     LOW\n\nSoftwareSerial RS485Serial(SerialRX, SerialTX); // RX, TX\n\n#include <OneWire.h>\n#include <DallasTemperature.h>\n//library's DEVICE_DISCONNECTED_C -127.0\n\nOneWire ow_ALLTSENSORS(OW_BUS_ALLTSENSORS);\nDallasTemperature s_allTsensors(&ow_ALLTSENSORS);\n\nDeviceAddress dev_addr;\t\t//temp\n\n\n//short names used to prevent unreadeable source\n#ifdef T_cold_in\n\tbool TciE = 1;\n#else\n\tbool TciE = 0;\n#endif\ndouble Tci = -127.0;\n\n#ifdef T_cold_out\n\tbool TcoE = 1;\n#else\n\tbool TcoE = 0;\n#endif\ndouble Tco = -127.0;\n\n#ifdef T_before_evaporator\n\tbool TbeE = 1;\n#else\n\tbool TbeE = 0;\n#endif\ndouble Tbe = -127.0;\n\n\n#ifdef T_after_evaporator\n\tbool TaeE = 1;\n#else\n\tbool TaeE = 0;\n#endif\ndouble Tae = -127.0;\n\n\n/*\n#ifdef T_separator_gas\n\tbool TsgE = 1;\n#else\n\tbool TsgE = 0;\n#endif\ndouble Tsg = -127.0;\n\n\n#ifdef T_separator_liquid\n\tbool TslE = 1;\n#else\n\tbool TslE = 0;\n#endif\ndouble Tsl = -127.0;\n\n\n#ifdef T_before_valve\n\tbool TbvE = 1;\n#else\n\tbool TbvE = 0;\n#endif\ndouble Tbv = -127.0;\n\n\n#ifdef T_suction\n\tbool TsucE = 1;\n#else\n\tbool TsucE = 0;\n#endif\ndouble Tsuc = -127.0;\n*/\n\n#ifdef T_sensor_1\n\tbool Ts1E = 1;\n#else\n\tbool Ts1E = 0;\n#endif\ndouble Ts1 = -127.0;\n\n\n#ifdef T_sensor_2\n\tbool Ts2E = 1;\n#else\n\tbool Ts2E = 0;\n#endif\ndouble Ts2 = -127.0;\t\n\n\n#ifdef T_crc\n\tbool TcrcE = 1;\n#else\n\tbool TcrcE = 0;\n#endif\ndouble Tcrc = -127.0;\n\n#ifdef T_regenerator\n\tbool TregE = 1;\n#else\n\tbool TregE = 0;\n#endif\ndouble Treg = -127.0;\n\n\n#ifdef T_afrer_condenser\n\tbool TacE = 1;\n#else\n\tbool TacE = 0;\n#endif\ndouble Tac = -127.0;\n\n#ifdef T_before_condenser\n\tbool TbcE = 1;\n#else\n\tbool TbcE = 0;\n#endif\ndouble Tbc = -127.0;\n\n#ifdef T_hot_out\n\tbool ThoE = 1;\n#else\n\tbool ThoE = 0;\n#endif\ndouble Tho = -127.0;\n\n#ifdef T_hot_in\n\tbool ThiE = 1;\n#else\n\tbool ThiE = 0;\n#endif\ndouble Thi = -127.0;\n\ndouble T_setpoint \t\t\t= T_SETPOINT;\ndouble T_setpoint_lastsaved\t\t= T_setpoint;\ndouble T_EEV_setpoint \t\t\t= EEV_TARGET_TEMP_DIFF;\ndouble T_EEV_dt\t\t\t\t= 0.0;\t\t//real, used during run\nconst double cT_setpoint_max \t\t= T_SETPOINT_MAX;\nconst double cT_setpoint_min \t\t= T_SETPOINT_MIN;\n//const double cT_hotcircle_delta_min \t= T_HOTCIRCLE_DELTA_MIN;\nconst double cT_crc_min \t\t= T_CRANKCASE_MIN;\nconst double cT_crc_max \t\t= T_CRANKCASE_MAX;\nconst double cT_crc_heat_threshold \t= T_CRANKCASE_HEAT_THRESHOLD;\n//const double cT_reg_heat_threshold \t= T_REG_HEAT_THRESHOLD;\nconst double cT_before_condenser_max \t= T_BEFORE_CONDENSER_MAX;\nconst double cT_coldref_min \t\t= T_COLDREF_MIN;\nconst double cT_before_evap_work_min \t= T_BEFORE_EVAP_WORK_MIN;\nconst double cT_cold_min \t\t= T_COLD_MIN;\nconst double cT_hot_max \t\t= T_HOT_MAX;\n//const double cT_workingOK_cold_delta_min = 0.5; \t// 0.7 - 1st try, 2nd try 0.5\n//const double cT_workingOK_hot_delta_min\t= 0.5;\nconst double cT_workingOK_crc_min \t= T_WORKINGOK_CRANKCASE_MIN;        \t//need to be not very high to normal start after deep freeze\nconst double c_wattage_max \t\t= MAX_WATTS;   \t//FUNAI: 1000W seems to be normal working wattage INCLUDING 1(one) CR25/4 at 3rd speed\n\t\t\t\t\t\t\t//PH165X1CY : 920 Watts, 4.2 A\nconst double c_workingOK_wattage_min \t= c_wattage_max/5;     //\n\nunsigned int pr_low_state_anal  \t= 0;\t//sensors are NC for spec. conditions, so 1 == ok, 0 == error\nunsigned int pr_high_state_anal    \t= 0;\t//\n\nbool pr_low_state_bool  \t= 1;\t//sensors are NC for spec. conditions, so 1 == ok, 0 == error\nbool pr_high_state_bool    \t= 1;\t//\n\nbool heatpump_state    \t\t= 0;\nbool hotside_circle_state  \t= 0;\nbool coldside_circle_state \t= 0;\nbool crc_heater_state    \t= 0;\n//bool reg_heater_state\t\t= 0;\n\n//bool relay6_state\t\t= 0;\n//bool relay7_state\t\t= 0;\n\nbool LED_OK_state\t\t= 0;\nbool LED_ERR_state\t\t= 0;\n\nbool S0_state\t\t\t= 0;\nbool S1_state\t\t\t= 0;\nbool S2_state\t\t\t= 0;\nbool S3_state\t\t\t= 0;\n\nbool EEV1_state\t\t\t= 0;\nbool EEV2_state\t\t\t= 0;\nbool EEV3_state\t\t\t= 0;\nbool EEV4_state\t\t\t= 0;\n\nconst long poweron_pause     \t= POWERON_PAUSE    ;    \t//default 5 mins\nconst long mincycle_poweroff \t= MINCYCLE_POWEROFF;    \t//default 5 mins\nconst long mincycle_poweron  \t= MINCYCLE_POWERON ;  \t\t//default 60 mins\nbool _1st_start_sleeped \t\t= 0;\n//??? TODO: periodical start ?\n//const long floor_circle_maxhalted = 6000000;  //circle NOT works max 100 minutes\nconst long deffered_stop_hotcircle = DEFFERED_STOP_HOTCIRCLE;\n\nint EEV_cur_pos\t\t= 0;\nint EEV_reopen_pos\t= 0;\nbool EEV_must_reopen_flag\t= 0;\n\nint EEV_apulses\t\t= 0;\t\t//for async\nbool EEV_adonotcare\t= 0;\t\t\nconst unsigned char EEV_steps[4] = {0b1010, 0b0110, 0b0101, 0b1001};\nchar EEV_cur_step \t= 0;\nbool EEV_fast\t\t= 0;\t\t\n#ifdef EEV_MANUAL\n\tbool EEV_manual\t\t= 1;\n#else\n\tbool EEV_manual\t\t= 0;\n#endif\nconst bool c_EEV_reopenlast\t= EEV_REOPENLAST;\n\n//main cycle vars\nunsigned long millis_prev\t= 0;\nunsigned long millis_now\t= 0;\nunsigned long millis_cycle\t= 1000;\n\nunsigned long millis_last_heatpump_on  = 0;\nunsigned long millis_last_heatpump_off = 0;\n\nunsigned long millis_last_hotWP_on  = 0;\nunsigned long millis_last_hotWP_off = 0;\n\nunsigned long millis_last_coldWP_off = 0;\n\nunsigned long millis_notification  \t\t= 0;\nunsigned long millis_notification_interval \t= 33000;\n\nunsigned long millis_displ_update          \t= 0;\nunsigned long millis_displ_update_interval \t= 10000;\n\nunsigned long millis_escinput_485\t=  0;  \nunsigned long millis_charinput_485 \t=  0;  \nunsigned long millis_escinput_local\t=  0;  \nunsigned long millis_charinput_local \t=  0;  \n\n\nunsigned long millis_lasteesave\t=  0;  \n\nunsigned long millis_last_printstats = 0;\n\nunsigned long millis_eev_last_close \t=  0;\nunsigned long millis_eev_last_on  \t=  0;\nunsigned long millis_eev_last_step \t= 0;\nunsigned long millis_eev_minworkpos_time =  0;\nunsigned long millis_eev_last_work \t=  0;\n\nunsigned long tmic1    =  0;\nunsigned long tmic2    =  0;\n\nint skipchars_485 = 0;\nint skipchars_local = 0;\n\n#define BUFSIZE          150   \n\nunsigned char dataBuf[BUFSIZE+1];\t// Allocate some space for the string, do not change that size!\nchar inChar= -1;      \t\t// space to store the character read\nbyte index = 0;       \t\t// Index into array; where to store the character\n\n//-------------temporary variables\nchar temp[10];\nint i\t= 0;\nint u\t= 0;\nint z\t= 0;\nint x\t= 0;\nint y\t= 0;\ndouble tempdouble\t= 0.0;\ndouble tempdouble_intpart\t= 0.0;\n\nint tempint       \t= 0;\nbool tempbool \t\t= 0;\n\nchar \t\tfp_integer\t= 0;\nchar\t\tfp_fraction\t= 0;\n\nString outString;\nString lastStopCauseTxt;\t\t//20 reserved, but use 12 chars of text max\nbool fl_printSS_lastStopCauseTxt = 0;\t//flag to call printSS\n#define LSCint_normal\t\t0\n#define LSCint_protective\t1\n#define LSCint_error\t\t2\nint \tLSCint\t=\tLSCint_normal;\t//0 = normal, 1 = protective, 2 = error\nString lastStartMsgTxt;\t\t\t//same as LSC\nbool fl_printSS_lastStartMsgTxt = 0;\t//flag to call printSS\nString t_sensorErrString;\n\nchar convBuf[13];\n\n//-------------EEPROM\nint eeprom_magic_read = 0x00;\nint eeprom_addr       = 0x00;      \n//initial values, saved to EEPROM and can be modified later\n//CHANGE eeprom_magic after correction!\nconst int eeprom_magic = MAGIC;\n\n//-------------ERROR states\n#define ERR_OK       \t0\n#define ERR_T_SENSOR   \t1\n#define ERR_P_HI\t2\n#define ERR_P_LO\t3\n\nint errorcode \t\t\t= 0;\nunsigned char sequential_errors = 0;\n\n//--------------------------- for wattage \n#define ADC_BITS 10                      //10 fo regular arduino\n#define ADC_COUNTS (1<<ADC_BITS)\nfloat em_calibration  \t= 62.5;\nint em_samplesnum   \t= 2960;   \t// Calculate Irms only 1480 == full 14 periods for 50Hz, 2960 = 28, 4440 = 42\n//double Irms       \t= 0;      \t//for tests with original procedure\nint supply_voltage   \t= 0;\nint em_i            \t= 0;\n//phase 1\nint sampleI_1       \t= 0;\ndouble filteredI_1  \t= 0;\ndouble offsetI_1    \t= ADC_COUNTS>>1;\t//Low-pass filter output\ndouble sqI_1,sumI_1 \t= 0;            \t//sq = squared, sum = Sum, inst = instantaneous\ndouble async_Irms_1 \t= 0;\ndouble async_wattage \t= 0;\n//--------------------------- for wattage END\n\nconst char str1[] PROGMEM = \"Valden Heat Pump Controller, https://github.com/OpenHP/\\n\\r\\n\\rCommands: \\n\\r(?) help\\n\\r(-) decrease setpoint T\\n\\r\\n\\r(+) increase setpoint T\";\nconst char str2[] PROGMEM = \"(<) decrease EEV T diff \\n\\r(>) increase EEV T diff\\n\\r\\n\\r(M) manual EEV mode\\n\\r(A) auto EEV mode\\n\\r\\n\\r(z) -1 EEV\\t(Z) -10 EEV\\n\\r(x) +1 EEV\\t(X) +10 EEV\\n\\r(G) get stats\";\nconst char str3[] PROGMEM = \"EEV:auto\";\nconst char str4[] PROGMEM = \"EEV:manual\";\nconst char str5[] PROGMEM = \"N/A,auto\";\nconst char str6[] PROGMEM = \"+10 ok\";\nconst char str7[] PROGMEM = \"-10 ok\";\nconst char str8[] PROGMEM = \"+1 ok\";\nconst char str9[] PROGMEM = \"-1 ok\";\nconst char str10[] PROGMEM = \"Max!\";\nconst char str11[] PROGMEM = \"Min!\";\nconst char str12[] PROGMEM = \"HWP ON by Setp. update\";\nconst char str13[] PROGMEM = \"EE->mem\";\nconst char str14[] PROGMEM = \"mem->EE\";\nconst char str15[] PROGMEM = \"OK:E.T.Sens.\";\nconst char str16[] PROGMEM = \"OK:Pr.Cold\";\nconst char str17[] PROGMEM = \"OK:Pr.Hot\";\nconst char str18[] PROGMEM = \"HWP_ON\";\nconst char str19[] PROGMEM = \"unkn_F\";\n\nPGM_P const const_strs[] PROGMEM = {\n\tstr1,\tstr2,\tstr3,\tstr4,\tstr5,\tstr6,\tstr7,\tstr8,\tstr9,\tstr10,\n\tstr11,\tstr12,\tstr13,\tstr14,\tstr15,\tstr16,\tstr17,\tstr18,\tstr19\n};\n\n#define IDX_HELP1 \t0\n#define IDX_HELP2 \t1\n#define IDX_EEVAUTO \t2\n#define IDX_EEVMANUAL\t3\n#define IDX_NAAUTO\t4\n#define IDX_PLUS10_OK\t5\n#define IDX_MINUS10_OK\t6\n#define IDX_PLUS1_OK\t7\n#define IDX_MINUS1_OK\t8\n#define IDX_MAX\t\t9\n#define IDX_MIN\t\t10\n#define IDX_HWP_ONBYUPD\t11\n#define IDX_EEtoMEM\t12\n#define IDX_MEMtoEE\t13\n#define IDX_OK_ETSENS\t14\n#define IDX_OK_PRCOLD\t15\n#define IDX_OK_PRHOT\t16\n#define IDX_HWPON\t17\n#define IDX_UNKNF\t18\n\n\n//--------------------------- functions\nlong ReadVcc() {\n\t// Read 1.1V reference against AVcc\n\t// set the reference to Vcc and the measurement to the internal 1.1V reference\n\t#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)\n\t\tADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);\n\t#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)\n\t\tADMUX = _BV(MUX5) | _BV(MUX0);\n\t#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)\n\t\tADMUX = _BV(MUX3) | _BV(MUX2);\n\t#else\n\t\tADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);\n\t#endif  \n\n\tdelay(2); // Wait for Vref to settle\n\tADCSRA |= _BV(ADSC); // Start conversion\n\twhile (bit_is_set(ADCSRA,ADSC)); // measuring\n\t\n\tuint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  \n\tuint8_t high = ADCH; // unlocks both\n\t\n\tlong result = (high<<8) | low;\n\t//constant NOT same as in battery controller!\n\tresult = 1126400L / result; // Calculate Vcc (in mV); (me: !!) 1125300  (!!) = 1.1*1023*1000\n\treturn result; // Vcc in millivolts\n}\n\n/*void PrintS (String str) {\n\t#ifdef RS485_HUMAN\n\t\tchar *outChar=&str[0];  \n\t\tdigitalWrite(SerialTxControl, RS485Transmit);\n\t\thalifise();\n\t\tdelay(1);    \n\t\tRS485Serial.print(outChar);\n\t\tRS485Serial.println();\n\t\tRS485Serial.flush();\n\t\tdigitalWrite(SerialTxControl, RS485Receive);  \n\t#endif\n}*/\n\nvoid PrintSS (String str) {\n\tchar *outChar=&str[0];  \n\tif (str == \"\") {\n\t\treturn;\n\t}\n\t#ifdef RS485_HUMAN\n\t\tdigitalWrite(SerialTxControl, RS485Transmit);\n\t\thalifise();\n\t\tdelay(1);    \n\t\tRS485Serial.print(outChar);\n\t\tRS485Serial.println();\n\t\tRS485Serial.flush();\n\t\tdigitalWrite(SerialTxControl, RS485Receive);  \n\t#endif\n\tSerial.println(outChar);\n\tSerial.flush();\n}\n\nvoid PrintSSch(char idx) {\n\tstrcpy_P(dataBuf, (PGM_P)pgm_read_word(&const_strs[idx]));\n\tSerial.println((const char *) dataBuf);\n\t#ifdef RS485_HUMAN\n\t\tdigitalWrite(SerialTxControl, RS485Transmit);\n\t\thalifise();\n\t\tdelay(1);    \n\t\tRS485Serial.print((const char *) dataBuf);\n\t\tRS485Serial.println();\n\t\tRS485Serial.flush();\n\t\tdigitalWrite(SerialTxControl, RS485Receive);  \n\t#endif\n}\nvoid PrintSS_SaD (double num) {\t//global string + double\n\t#ifdef RS485_HUMAN\n\t\tdigitalWrite(SerialTxControl, RS485Transmit);\n\t\thalifise();\n\t\tdelay(1);\n\t\tRS485Serial.print(outString);\n\t\tRS485Serial.println(num);\n\t\tRS485Serial.flush();\n\t\tdigitalWrite(SerialTxControl, RS485Receive);  \n\t#endif\n\tSerial.print(outString);\n\tSerial.println(num);\n\tSerial.flush();\n}\n\nvoid PrintSS_SaBl (bool num) {\t\n\t#ifdef RS485_HUMAN\n\t\tdigitalWrite(SerialTxControl, RS485Transmit);\n\t\thalifise();\n\t\tdelay(1);\n\t\tRS485Serial.print(outString);\n\t\tRS485Serial.println(num);\n\t\tRS485Serial.flush();\n\t\tdigitalWrite(SerialTxControl, RS485Receive);  \n\t#endif\n\tSerial.print(outString);\n\tSerial.println(num);\n\tSerial.flush();\n}\n\nvoid ApToOut_D (double num) {\n\toutString += String(num);\n}\n\nvoid PrintSS_SaI (int num) {\t\n\t#ifdef RS485_HUMAN\n\t\tdigitalWrite(SerialTxControl, RS485Transmit);\n\t\thalifise();\n\t\tdelay(1);\n\t\tRS485Serial.print(outString);\n\t\tRS485Serial.println(num);\n\t\tRS485Serial.flush();\n\t\tdigitalWrite(SerialTxControl, RS485Receive);  \n\t#endif\n\tSerial.print(outString);\n\tSerial.println(num);\n\tSerial.flush();\n}\n\n\n/*void PrintSS_SaI (int num) {\t//global string + double\n\t#ifdef RS485_HUMAN\n\t\tdigitalWrite(SerialTxControl, RS485Transmit);\n\t\thalifise();\n\t\tdelay(1);\n\t\tRS485Serial.print(outString);\n\t\tRS485Serial.println(num);\n\t\tRS485Serial.flush();\n\t\tdigitalWrite(SerialTxControl, RS485Receive);  \n\t#endif\n\tSerial.print(outString);\n\tSerial.println(num);\n\tSerial.flush();\n}*/\n\nvoid _PrintHelp(void) {   \n\tPrintSS(\"fw: \"\t+ fw_version  + \" board: \"+ hw_version);\n\tPrintSSch(IDX_HELP1);\n\t#ifndef NO_EEV\n\t\tPrintSSch(IDX_HELP2);\n\t#endif\n}\n\nvoid PrintSS_double (double double_to_print) {\n\tdtostrf(double_to_print,1,2,temp);\n\tPrintSS(temp);\n}\n\nvoid Add_Double_To_Buf_IntFract (double float_to_convert) {\t//uses tempdouble tempdouble_intpart fp_integer fp_fraction\n\tif (float_to_convert > 255.0 || float_to_convert < -127.0) {\n\t\tfp_integer\t= -127;\n\t\tfp_fraction\t= 0;\n\t} else {\n\t\ttempdouble = modf (float_to_convert , &tempdouble_intpart);\n\t\tfp_integer = trunc(tempdouble_intpart);\n\t\ttempdouble  = tempdouble * 100;\n\t\tfp_fraction = round(tempdouble);\n\t}\n\tdataBuf[i]  =  fp_integer;\n\ti++;\n\tdataBuf[i]  =  fp_fraction;\n\ti++;\n\t/*\n\tSerial.println(float_to_convert);\n\tSerial.println(fp_integer, DEC);\n\tSerial.println(fp_fraction, DEC);*/\n}\n\n\nvoid IntFract_to_tempdouble (char _int_to_convert, char _fract_to_convert) {\t//fract is also signed now!\n\ttempdouble = (double) _fract_to_convert / 100;\n\ttempdouble += _int_to_convert;\n\t/*Serial.println(_int_to_convert);\n\tSerial.println(_fract_to_convert);\n\tSerial.println(tempdouble);*/\n}\n\n\nvoid _ProcessInChar(void){\n\t//remote commands +,-,G,0x20/?/Enter/A/M/x/X/z/Z\n\tswitch (inChar) {\n\t\tcase 0x00:\n\t\t\tbreak;\n\t\tcase 0x20:\n\t\t\t_PrintHelp();\n\t\t\tbreak;\n\t\tcase 0x3F:\n\t\t\t_PrintHelp();\n\t\t\tbreak;\n\t\tcase 0x0D:\n\t\t\t_PrintHelp();\n\t\t\tbreak;\n\t\tcase 0x2B:\n\t\t\tInc_T();\n\t\t\tbreak;\n\t\tcase 0x2D:\n\t\t\tDec_T();\n\t\t\tbreak;\n\t\t#ifndef NO_EEV\n\t\t\tcase 0x3C:\n\t\t\t\tDec_E();\n\t\t\t\tbreak;\n\t\t\tcase 0x3E:\n\t\t\t\tInc_E();\n\t\t\t\tbreak;\n\t\t\tcase 0x41:\n\t\t\t\tEEV_manual = 0;\n\t\t\t\tPrintSSch(IDX_EEVAUTO);\n\t\t\t\tbreak;\n\t\t#endif\n\t\tcase 0x47:\n\t\t\tPrintStats_SS();\n\t\t\tmillis_last_printstats = millis_now;\n\t\t\tbreak;\n\t\t#ifndef NO_EEV\n\t\t\tcase 0x4D:\n\t\t\t\tEEV_manual = 1;\n\t\t\t\tPrintSSch(IDX_EEVMANUAL);\n\t\t\t\tbreak;\n\t\t\tcase 0x58:\t//+10\n\t\t\t\tif (EEV_manual != 1){\n\t\t\t\t\tPrintSSch(IDX_NAAUTO);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tEEV_apulses += 10;\n\t\t\t\tEEV_fast = 1;\n\t\t\t\tPrintSSch(IDX_PLUS10_OK);\n\t\t\t\tbreak;\n\t\t\tcase 0x5A:\t//-10\n\t\t\t\tif (EEV_manual != 1){\n\t\t\t\t\tPrintSSch(IDX_NAAUTO);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tEEV_apulses -= 10;\n\t\t\t\tEEV_fast = 1;\n\t\t\t\tPrintSSch(IDX_MINUS10_OK);\n\t\t\t\tbreak;\n\t\t\tcase 0x78:\t//+1\n\t\t\t\tif (EEV_manual != 1){\n\t\t\t\t\tPrintSSch(IDX_NAAUTO);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tEEV_apulses += 1;\n\t\t\t\tEEV_fast = 1;\n\t\t\t\tPrintSSch(IDX_PLUS1_OK);\n\t\t\t\tbreak;\n\t\t\tcase 0x7A:\t//-1\n\t\t\t\tif (EEV_manual != 1){\n\t\t\t\t\tPrintSSch(IDX_NAAUTO);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tEEV_apulses += 10;\n\t\t\t\tEEV_fast = 1;\n\t\t\t\tPrintSSch(IDX_MINUS1_OK);\n\t\t\t\tbreak;\n\t\t#endif\n\t}\n\n}\n\nint Inc_T (void) {\n\tif (T_setpoint + 0.5 > cT_setpoint_max) {\n\t\tPrintSSch(IDX_MAX);\n\t\tdelay (200);\n\t\treturn 0;\n\t}\n\tT_setpoint += 0.5;\n\tPrintSS_double(T_setpoint);\t\n\treturn 1;\t\n}\n\nint Dec_T (void) {\n\tif (T_setpoint - 0.5 < cT_setpoint_min) {\n\t\tPrintSSch(IDX_MIN);\n\t\tdelay (200);\n\t\treturn 0;\n\t}\n\tT_setpoint -= 0.5;\n\tPrintSS_double(T_setpoint);\t\n\treturn 1;\n}\n\nint Inc_E (void) {\t\t///!!! unprotected\n\tT_EEV_setpoint += 0.25;\n\tPrintSS_double(T_EEV_setpoint);\n\treturn 1;\t\n}\n\nint Dec_E (void) {\t\t///!!! unprotected\n\tT_EEV_setpoint -= 0.25;\n\tPrintSS_double(T_EEV_setpoint);\n\treturn 1;\n}\n\n\n\n\n\nvoid _HotWPon_by_Setpoint_update(void){\t//if setpoint updated: start hot circle to check temperature\n\tif (  (heatpump_state == 0)   &&  (hotside_circle_state  == 0)  && ((unsigned long)(millis_now - millis_last_hotWP_on) < HOTCIRCLE_START_EVERY)\t) {    //process START_EVERY for hot side\n\t\tmillis_last_hotWP_off = millis_now;\n\t\thotside_circle_state  = 1;\n\t\tPrintSSch(IDX_HWP_ONBYUPD);\n\t}\n}\n\nvoid PrintStats_SS (void) {\n\t\t\n\t\tif (TciE)\t{ \toutString = F(\"\\n\\r---\\n\\r\\tTbe:\\t\")\t;\tPrintSS_SaD(Tbe);\t}\n\t        if (TaeE)\t{\toutString = F(\"\\tTae:\\t\")\t;\tPrintSS_SaD(Tae);\t}\n\t\tif (TcoE)\t{\toutString = F(\"\\tTci:\\t\");\t\tPrintSS_SaD(Tci);\t}\n\t\tif (TcoE)\t{\toutString = F(\"\\tTco:\\t\")\t;\tPrintSS_SaD(Tco);\t}\n\t        \n\t        //if (TsgE)\t{\toutString = F(\"\\tTsg: \")\t;\tPrintSS_SaD(Tsg);\t}\n\t        //if (TslE)\t{\toutString = F(\"\\tTsl: \")\t;\tPrintSS_SaD(Tsl);\t}\n\t        //if (TbvE)\t{\toutString = F(\"\\tTbv: \")\t;\tPrintSS_SaD(Tbv);\t}\n\t        //if (TsucE)\t{\toutString = F(\"\\tTsuc: \")\t;\tPrintSS_SaD(Tsuc);\t}\n\t        if (Ts1E)\t{\toutString = F(\"\\tTs1:\\t\")\t;\tPrintSS_SaD(Ts1);\t}\n\t        if (Ts2E)\t{\toutString = F(\"\\tTs2:\\t\")\t;\tPrintSS_SaD(Ts2);\t}\n\t        //Tcrc misorder due to large string\n\t        if (TregE)\t{\toutString = F(\"\\tTreg:\\t\")\t;\tPrintSS_SaD(Treg);\t}\n\t        if (TbcE)\t{\toutString = F(\"\\tTbc:\\t\")\t;\tPrintSS_SaD(Tbc);\t}\n\t\tif (TacE)\t{\toutString = F(\"\\tTac:\\t\")\t;\tPrintSS_SaD(Tac);\t}\n\t        if (ThiE)\t{\toutString = F(\"\\tThi:\\t\")\t;\tPrintSS_SaD(Thi);\t}\n\t\tif (ThoE)\t{\toutString = F(\"\\tTho:\\t\")\t;\tPrintSS_SaD(Tho);\t}\n\t\tif (TcrcE)\t{\toutString = F(\"\\tTcrankcase:\\t\");\tPrintSS_SaD(Tcrc);\t}//misorder due to large string\n\t\toutString = F(\"\\tSetpoint:\\t\");\t\n\t\tPrintSS_SaD(T_setpoint); \n\t\t\n\t\toutString = F(\"\\n\\r\\tHP:\\t\");\n\t\tPrintSS_SaBl(heatpump_state);\n\t\toutString = F(\"\\tHWP:\\t\");\n\t\tPrintSS_SaBl(hotside_circle_state);\n\t\toutString = F(\"\\tCWP:\\t\");\n\t\tPrintSS_SaBl(coldside_circle_state);\n\t\toutString = F(\"\\tCRCheat:\");\n\t\tPrintSS_SaBl(crc_heater_state);\n\t\toutString = F(\"\\tWatts:\\t\")\t;\t\n\t\tPrintSS_SaD(async_wattage);\n\t\t\n\t\t#ifndef NO_EEV\n\t\t\toutString = F(\"\\n\\r\\tT_EEV_setpoint: \");\n\t\t\tPrintSS_SaD(T_EEV_setpoint);\n\t\t\toutString = \"\\tEEV_pos:\\t\";\n\t\t\tPrintSS_SaI(EEV_cur_pos);\n\t\t#endif \n\t\t\n\t\toutString = \"\\n\\r\\tErr:\\t\";\n\t\tPrintSS_SaI(errorcode);\n\t\toutString = F(\"\\tPr.Cold:\")\t;\t\n\t\tif (pr_low_state_bool == 1) {\n\t\t\toutString += F(\"OK\");\n\t\t} else {\n\t\t\toutString += F(\"ERR\");\n\t\t}\n\t\toutString += F(\"\\n\\r\\tPr.Hot:\\t\")\t;\t\n\t\tif (pr_high_state_bool == 1) {\n\t\t\toutString += F(\"OK\");\n\t\t} else {\n\t\t\toutString += F(\"ERR\");\n\t\t}\n\t\t\n\t\toutString += F(\"\\n\\r\\n\\r\\tLast Stop Cause:\\t\");\n\t\toutString += lastStopCauseTxt;\n\t\toutString += F(\"\\n\\r\\tLast Start Message:\\t\");\n\t\toutString += lastStartMsgTxt;\n\t\toutString += F(\"\\n\\r---\\n\\r\");\n\t\tPrintSS(outString);\n\t\t\n\t#ifdef RS485_HUMAN\n\t\tdigitalWrite(SerialTxControl, RS485Transmit);\n\t\thalifise();\n\t\tdelay(1);    \n\t\tRS485Serial.print(outString);\n\t\tRS485Serial.println();\n\t\tRS485Serial.flush();\n\t\tdigitalWrite(SerialTxControl, RS485Receive);  \n\t#endif\n}\n\nvoid Calc_CRC(unsigned char b) {\t//uses/changes y\n\tcrc16 ^= b & 0xFF;\n\tfor (y=0; y<8; y++) {\n\t\tcf = crc16 & 0x0001;\n\t\tcrc16>>=1;\n\t\tif (cf) { crc16 ^= POLY; }\n\t}\n}\n\nvoid CheckIsInvalidCRCAddr(unsigned char *addr) {\n\tif (OneWire::crc8( addr, 7) != addr[7] ) {\n\t\ti+= 1;\n\t}\n}\n\nvoid WriteFloatEEPROM(int addr, float val) { \n\tbyte *x = (byte *)&val;\n\tfor(byte u = 0; u < 4; u++) EEPROM.write(u+addr, x[u]);\n}\n \nfloat ReadFloatEEPROM(int addr) {   \n\tbyte x[4];\n\tfor(byte u = 0; u < 4; u++) x[u] = EEPROM.read(u+addr);\n\tfloat *y = (float *)&x;\n\treturn y[0];\n}\n\nvoid SaveSetpointEE(void) {\n\tif(  \t(T_setpoint_lastsaved != T_setpoint) && \n\t\t( ((unsigned long)(millis_now - millis_lasteesave) > 15*60*1000 )  ||  (millis_lasteesave == 0) )  ) {\n\t\t\teeprom_addr = 1;\n\t\t\tWriteFloatEEPROM(eeprom_addr, T_setpoint);\n\t\t\tmillis_lasteesave = millis_now;\n\t\t\tT_setpoint_lastsaved = T_setpoint;\n\t\t}\n}\n\ndouble GetT (int channel) {\n\tS0_state = bitRead(channel,0);\n\tS1_state = bitRead(channel,1);\n\tS2_state = bitRead(channel,2);\n\tS3_state = bitRead(channel,3);\n\thalifise();\n\t\n\ttempdouble = -127.0;\n\tfor ( i = 0; i < 8; i++) {\n\t\t#ifdef WATCHDOG\n\t\t\twdt_reset();\n\t\t#endif\n\t\teevise();\n\t\ttempdouble = s_allTsensors.getTempCByIndex(0);\n\t\tif ( (tempdouble == 85.0) || (tempdouble < -55.0) || (tempdouble == 0.0) || (tempdouble > 125.0) ) {\t//0.0 added to test\n\t\t\t//outString =  F(\"Warn:T_SensReRead!\");\n\t\t\t//PrintSS_SaD(tempdouble);\n\t\t\tif ( tempdouble == 85.0 || tempdouble == 0.0 ) {    //initial value in dallas register after poweron\n\t\t\t\ts_allTsensors.requestTemperatures();\t//!!!added to test, seems to work ok\n\t\t\t\tdelay (375);              //375 actual for 11 bits resolution, 2-3 retries OK for 12-bits resolution\n\t\t\t} else {\n\t\t\t\tdelay (37);\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\ts_allTsensors.requestTemperatures();\n\tif ( (tempdouble > 125.0) || (tempdouble < -55.0)) {\t//incorrect readings protection, rare\n\t\ttempdouble = -127.0;\n\t}\n\treturn tempdouble;\n}\n\n//older version of GetT\n/*double GetT (int channel) {\n\tS0_state = bitRead(channel,0);\n\tS1_state = bitRead(channel,1);\n\tS2_state = bitRead(channel,2);\n\tS3_state = bitRead(channel,3);\n\thalifise();\n\t\n\ttempdouble = -127.0;\n\tfor ( i = 0; i < 8; i++) {\n\t\t#ifdef WATCHDOG\n\t\t\twdt_reset();\n\t\t#endif\n\t\teevise();\n\t\ttempdouble = s_allTsensors.getTempCByIndex(0);\n\t\tif ( (tempdouble == 85.0) || (tempdouble == -127.0) ) {\n\t\t\tif ( tempdouble == 85.0 ) {    //initial value in dallas register after poweron\n\t\t\t\ts_allTsensors.requestTemperatures();//!!! added to test\n\t\t\t\tdelay (375);              //375 actual for 11 bits resolution, 2-3 retries OK for 12-bits resolution\n\t\t\t} else {\n\t\t\t\tdelay (37);\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\ts_allTsensors.requestTemperatures();\n\treturn tempdouble;\n}*/\n\nvoid GetTemperatures(void){\n\tif (TciE)\t{ \tTci\t= GetT(0);}\n\tif (TcoE)\t{\tTco\t= GetT(1);}\n\tif (TbeE)\t{\tTbe\t= GetT(2);}\n\tif (TaeE)\t{\tTae\t= GetT(3);}\n\t//if (TsgE)\t{\tTsg\t= GetT(4);}\n\t//if (TslE)\t{\tTsl\t= GetT(5);}\n\t//if (TbvE)\t{\tTbv\t= GetT(6);}\n\t//if (TsucE)\t{\tTsuc\t= GetT(7);}\n\tif (Ts1E)\t{\tTs1\t= GetT(8);}\n\tif (Ts2E)\t{\tTs2\t= GetT(9);}\n\tif (TcrcE)\t{\tTcrc\t= GetT(10);}\n\tif (TregE)\t{\tTreg\t= GetT(11);}\n\tif (TacE)\t{\tTac\t= GetT(12);}\n\tif (TbcE)\t{\tTbc\t= GetT(13);}\n\tif (ThoE)\t{\tTho\t= GetT(14);}\n\tif (ThiE)\t{\tThi\t= GetT(15);}\t\n}\n\nvoid on_EEV(){\t\n\tx = EEV_steps[EEV_cur_step];\n\tEEV1_state\t=\tbitRead(x, 0);\n\tEEV2_state\t=\tbitRead(x, 1);\n\tEEV3_state\t=\tbitRead(x, 2);\n\tEEV4_state\t=\tbitRead(x, 3);\n\thalifise();\n}\n\nvoid off_EEV(){\t\n\tEEV1_state\t=\t0;\n\tEEV2_state\t=\t0;\n\tEEV3_state\t=\t0;\n\tEEV4_state\t=\t0;\n\t//PrintSS(\"off_EEV\");\n\thalifise();\n}\n\nvoid halifise(void){\n\t/*\n\trelay 1: heat pump\n\trelay 2: hot side circulator pump\n\trelay 3: cold side circulator pump\n\trelay 4: crankcase heater\n\t(no more v1.3mi) relay 5:\n\t\n\t#define RELAY_HEATPUMP        \tA2\n\t#define RELAY_HOTSIDE_CIRCLE  \tA1\n\t\n\tReg 1:\n\t595.0: 4067 S3\n\t595.1: 4067 S0\n\t595.2: 4067 S1\n\t595.3: 4067 S2\n\t595.4: EEV_1\n\t595.5: EEV_2\n\t595.6: EEV_3\n\t595.7: EEV_4\n\t\n\tReg 2:\n\t595.8: !! free\n\t595.9: ok/err LED 2\n\t595.A: Relay 6 \n\t595.B: Relay 7 \n\t595.C: Relay 5 \n\t595.D: Relay 4\n\t595.E: Relay 3\n\t595.F: ok/err LED 1\n\t\n\tReg 3:\n\t595.10: LED \"EEV opening\"\n\t595.11: LED \"EEV closing\"\n\t595.12: LED \"EEV Fast\"\n\t595.13: LED \"485 RX\"\n\t595.14: LED \"485 TX\"\n\t595.15: LED \"Manual mode\"\n\t595.16: LED \"LSC: error\"\n\t595.17: LED \"LSC: protection\"\n\t*/\n\n\tdigitalWrite(LATCH_595, 0);\n\t//17\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tif (LSCint == LSCint_protective) {\n\t\tdigitalWrite(DATA_595, 1);\n\t} else {\n\t\tdigitalWrite(DATA_595, 0);\n\t}\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//16\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tif (LSCint == LSCint_error) {\n\t\tdigitalWrite(DATA_595, 1);\n\t} else {\n\t\tdigitalWrite(DATA_595, 0);\n\t}\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//15\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, EEV_manual);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//14\n\ttempbool = digitalRead (13);\n\t\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, tempbool);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//13\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, !tempbool);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//12\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, EEV_fast);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//11\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tif ( EEV_apulses < 0 ) {\n\t\tdigitalWrite(DATA_595, 1);\n\t} else {\n\t\tdigitalWrite(DATA_595, 0);\n\t}\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//10\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tif ( EEV_apulses > 0 ) {\n\t\tdigitalWrite(DATA_595, 1);\n\t} else {\n\t\tdigitalWrite(DATA_595, 0);\n\t}\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//F\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, LED_ERR_state);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//E\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, coldside_circle_state);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//D\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, crc_heater_state);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//C\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//digitalWrite(DATA_595, reg_heater_state);\n\tdigitalWrite(DATA_595, 0);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//B\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//digitalWrite(DATA_595, relay7_state);\n\tdigitalWrite(DATA_595, 0);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//A\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//digitalWrite(DATA_595, relay6_state);\n\tdigitalWrite(DATA_595, 0);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//9\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, LED_OK_state);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//8\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, 0);\t//FREE\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//7\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, EEV4_state);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//6\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, EEV3_state);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//5\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, EEV2_state);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//4\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, EEV1_state);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//3\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, S2_state);\t\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//2\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, S1_state); \n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//1\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, S0_state);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\t//0\n\tdigitalWrite(CLK_595, 0);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(DATA_595, S3_state);\n\tdigitalWrite(CLK_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(CLK_595, 0);\n\t//\n\tdigitalWrite(LATCH_595, 1);\n\t__asm__ __volatile__ (\"nop\\n\\t\");\n\tdigitalWrite(LATCH_595, 0);\n\tdigitalWrite\t(RELAY_HEATPUMP,\theatpump_state);\n\tdigitalWrite\t(RELAY_HOTSIDE_CIRCLE, \thotside_circle_state);\n}\n\nvoid eevise(void) {\n\tif (  \t\t((( EEV_apulses < 0 ) && (EEV_fast == 1))\t\t\t\t\t\t&&\t ((unsigned long)(millis_now - millis_eev_last_step) > (EEV_PULSE_FCLOSE_MILLIS))  \t)\t||\n\t\t\t((( EEV_apulses < 0 ) && (EEV_fast == 0))\t\t\t\t\t\t&&\t ((unsigned long)(millis_now - millis_eev_last_step) > (EEV_PULSE_CLOSE_MILLIS)\t) \t)\t||\n\t\t\t((( EEV_apulses > 0 ) && \t\t\t(EEV_cur_pos <  EEV_MINWORKPOS  ))\t&&\t ((unsigned long)(millis_now - millis_eev_last_step) > (EEV_PULSE_WOPEN_MILLIS)\t) \t)\t||\n\t\t\t((( EEV_apulses > 0 ) && (EEV_fast == 1) &&  \t(EEV_cur_pos >= EEV_MINWORKPOS\t)) \t&&\t ((unsigned long)(millis_now - millis_eev_last_step) > (EEV_PULSE_FOPEN_MILLIS) )\t)\t||\t\n\t\t\t((( EEV_apulses > 0 ) && (EEV_fast == 0) &&  \t(EEV_cur_pos >= EEV_MINWORKPOS\t)) \t&&\t ((unsigned long)(millis_now - millis_eev_last_step) > (EEV_PULSE_OPEN_MILLIS)  )\t)\t||\n\t\t\t(millis_eev_last_step == 0)\n\t\t\t) {\n\t\t\tif ( EEV_apulses != 0 ) {\n\t\t\t\tif ( EEV_apulses > 0 ) {\n\t\t\t\t\tif (EEV_cur_pos + 1 <= EEV_MAXPULSES) {\n\t\t\t\t\t\tEEV_cur_pos += 1;\n\t\t\t\t\t\tEEV_cur_step += 1;\n\t\t\t\t\t\tEEV_apulses -= 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tEEV_apulses = 0;\n\t\t\t\t\t\t//PrintSS(\"EEmax!\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( EEV_apulses < 0 ) {\n\t\t\t\t\tif (\t(EEV_cur_pos - 1 >= EEV_MINWORKPOS)\t|| (EEV_adonotcare == 1) ) {\n\t\t\t\t\t\tEEV_cur_pos -= 1;\n\t\t\t\t\t\tEEV_cur_step -= 1;\n\t\t\t\t\t\tEEV_apulses += 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tEEV_apulses = 0;\n\t\t\t\t\t\t//PrintSS(\"EEmin!\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (EEV_cur_step  > 3) EEV_cur_step = 0;\n\t\t\t\tif (EEV_cur_step  < 0) EEV_cur_step = 3;\n\t\t\t\tx = EEV_steps[EEV_cur_step];\n\t\t\t\tEEV1_state\t=\tbitRead(x, 0);\n\t\t\t\tEEV2_state\t=\tbitRead(x, 2);\t\t//!!!here pins are swapped fot sanhua\n\t\t\t\tEEV3_state\t=\tbitRead(x, 1);\t\t//!!!here pins are swapped fot sanhua\n\t\t\t\tEEV4_state\t=\tbitRead(x, 3);\n\t\t\t}\n\t\t\tif (EEV_cur_pos < 0) { \n\t\t\t\tEEV_cur_pos = 0;\t\n\t\t\t}\n\t\t\tmillis_eev_last_step = millis_now;\n\t\t\t#ifdef EEV_DEBUG \n\t\t\t\tPrintSS(String(EEV_cur_pos));\t\n\t\t\t#endif\n\t\t\thalifise();\n\t}\n}\n\n//--------------------------- functions END\n\nvoid setup(void) {\n\tpinMode\t\t(LATCH_595, \t\tOUTPUT);\n\tpinMode\t\t(CLK_595, \t\tOUTPUT);\n\tpinMode\t\t(DATA_595, \t\tOUTPUT);\n\tpinMode\t\t(OE_595, \t\tOUTPUT);\n\tpinMode\t\t(RELAY_HEATPUMP,\tOUTPUT);\n\tpinMode\t\t(RELAY_HOTSIDE_CIRCLE, \tOUTPUT);\n\tpinMode\t\t(PR_LOW, \t\tINPUT);\n\tpinMode\t\t(PR_HIGH, \t\tINPUT);\n\t\n\t\n\tdigitalWrite\t(LATCH_595, \t\tLOW);\n\tdigitalWrite\t(CLK_595, \t\tLOW);\n\tdigitalWrite\t(DATA_595, \t\tLOW);\n\tdigitalWrite\t(OE_595, \t\tLOW);\n\tdigitalWrite\t(RELAY_HEATPUMP,\tLOW);\n\tdigitalWrite\t(RELAY_HOTSIDE_CIRCLE, \tLOW);\n\thalifise();\n\t\n\t#ifdef WATCHDOG\n\t\twdt_disable();\n\t\tdelay(2000);\n\t#endif\n\t\n\t// start serial port\n\tSerial.begin(9600);\n\t//Serial.print(\"Starting, dev_id:\");\n\t//Serial.println(devID);\n\n\tRS485Serial.begin(9600);\n\tpinMode(SerialTxControl, OUTPUT); \n\tpinMode(SerialTX, OUTPUT);   \t\n\tpinMode(SerialRX, INPUT);   \n\tdigitalWrite(SerialTxControl, RS485Receive);\n\tdelay(100);\n\tPrintSS(\"ID: 0x\" + String(devID, HEX));\n\n\tdelay(200);\n\toff_EEV();\n\t\n\tpinMode\t(em_pin1, INPUT);\n\t\n\t//PrintSS(\"setpoint (C):\");\n\t//PrintSS(setpoint);\n\t\n\t//PrintSS(String(freeMemory()));\n\t\n\ts_allTsensors.begin();\n\ts_allTsensors.setWaitForConversion(false);  //ASYNC mode, request before get, see Dallas library for details\n\t\n\t//----------------------------- self-tests ----------------------------- ----------------------------- ----------------------------- \n\t/*\n\tindex = 0;\n\toutChar[index] = 0xFF;\n\tindex++;\n\toutChar[index] = 0xAA;\n\tindex++;\n\toutChar[index] = 0xBB;\n\tindex++;\n\toutChar[index] = 0xCC;\n\tindex++;\n\t\n\tcrc16 = SEED;\n\tfor (z = 0; z < index; z++) {   \n\t\tCalc_CRC(outChar[z]); \n        }\n        outChar[index]=crc16 & 0xFF;\n        index++;\n\toutChar[index]=crc16 >> 8;\n\tindex++;\n\toutChar[index]=0x00;\n\tindex++;\n\t\n\tSerial.println(crc16, HEX);\n\tfor (z = 0; z < index; z++) {   \n\t\tSerial.print(\" \");\n\t\tSerial.print(outChar[z], HEX); \n        }\n\tSerial.println(\" \");\n\t*/\n\t\n\t//Relays self-test\n\t#if (defined SELFTEST_RELAYS_LEDS_SPEAKER || defined SELFTEST_EEV || defined SELFTEST_T_SENSORS)\n\t\twhile ( 1 == 1) {\n\t\t\t#if defined SELFTEST_RELAYS_LEDS_SPEAKER \n\t\t\t\tPrintSS(F(\"Relays and LEDS self-test\"));\n\t\t\t\t\n\t\t\t\tanalogWrite(speakerOut, 10);\n\t\t\t\tdelay (1500);\n\t\t\t\tanalogWrite(speakerOut, 0);\n\t\t\t\n\t\t\t\theatpump_state    \t= 1;\thalifise();\tdelay(1000);\n\t\t\t\thotside_circle_state  \t= 1;\thalifise();\tdelay(1000);\n\t\t\t\tcoldside_circle_state \t= 1;\thalifise();\tdelay(1000);\n\t\t\t\tcrc_heater_state    \t= 1;\thalifise();\tdelay(1000);\n\t\t\t\t//reg_heater_state \t= 1;\thalifise();\tdelay(1000);\n\t\t\t\t\n\t\t\t\t//relay6_state\t\t= 1;\thalifise();\tdelay(1000);\n\t\t\t\t//relay7_state\t\t= 1;\thalifise();\tdelay(1000);\n\t\t\t\n\t\t\t\tEEV_apulses\t\t= 10;\thalifise();\tdelay(1000);\n\t\t\t\tEEV_apulses\t\t= -10;\thalifise();\tdelay(1000);\n\t\t\t\tEEV_fast\t\t= 1;\thalifise();\tdelay(1000);\n\t\t\t\tdigitalWrite(SerialTxControl, RS485Transmit);\thalifise();\tdelay(1000);\n\t\t\t\tEEV_manual\t\t= 1;\t\thalifise();\tdelay(1000);\n\t\t\t\tLSCint \t\t= LSCint_error;\t\thalifise();\tdelay(1000);\n\t\t\t\tLSCint \t\t= LSCint_protective;\thalifise();\tdelay(1000);\t\n\t\t\t\t\n\t\t\t\tLED_OK_state\t\t= 1;\thalifise();\tdelay(1000);\n\t\t\t\tLED_ERR_state\t\t= 1;\thalifise();\tdelay(1000);\n\t\t\t\n\t\t\t\tanalogWrite(speakerOut, 10);\n\t\t\t\tdelay (1500);\n\t\t\t\tanalogWrite(speakerOut, 0);\n\t\t\t\t\n\t\t\t\theatpump_state    \t= 0;\thalifise();\tdelay(1000);\n\t\t\t\thotside_circle_state  \t= 0;\thalifise();\tdelay(1000);\n\t\t\t\tcoldside_circle_state \t= 0;\thalifise();\tdelay(1000);\n\t\t\t\tcrc_heater_state    \t= 0;\thalifise();\tdelay(1000);\n\t\t\t\t//reg_heater_state \t= 0;\thalifise();\tdelay(1000);\n\t\t\t\t\n\t\t\t\t//relay6_state\t\t= 0;\thalifise();\tdelay(1000);\n\t\t\t\t//relay7_state\t\t= 0;\thalifise();\tdelay(1000);\n\t\t\t\t\n\t\t\t\tEEV_apulses\t\t= 10;\thalifise();\tdelay(1000);\n\t\t\t\tEEV_apulses\t\t= -10;\thalifise();\tdelay(1000);\n\t\t\t\tEEV_fast\t\t= 0;\thalifise();\tdelay(1000);\n\t\t\t\tdigitalWrite(SerialTxControl, RS485Receive);\thalifise();\tdelay(1000);\n\t\t\t\tdigitalWrite(SerialTxControl, RS485Transmit);\thalifise();\tdelay(1000);\n\t\t\t\tEEV_manual\t\t= 0;\t\thalifise();\tdelay(1000);\t\t\n\t\t\t\tLSCint \t\t= LSCint_error;\t\thalifise();\tdelay(1000);\n\t\t\t\tLSCint \t\t= LSCint_protective;\thalifise();\tdelay(1000);\n\t\t\t\t\n\t\t\t\tLED_OK_state\t\t= 0;\thalifise();\tdelay(1000);\n\t\t\t\tLED_ERR_state\t\t= 0;\thalifise();\tdelay(1000);\n\t\t\n\t\t\t\tanalogWrite(speakerOut, 10);\n\t\t\t\tdelay (1500);\n\t\t\t\tanalogWrite(speakerOut, 0);\n\t\t\t#endif\n\t\t\t#if defined SELFTEST_EEV\n\t\t\t\tEEV_apulses\t\t= 0;\n\t\t\t\tEEV_fast\t\t= 0;\n\t\t\t\thalifise();\t\n\t\t\t\tdelay(1000);\n\t\t\t\t//EEV self-test, also can be used for compressor test\n\t\t\t\t//vacuuming/charge via low pressure side: leave EEV opened\n\t\t\t\t//PrintSS(\"EEV self-test\");\n\t\t\t\tEEV_apulses =  -(EEV_MAXPULSES + EEV_CLOSE_ADD_PULSES);\n\t\t\t\tEEV_adonotcare = 1;\n\t\t\t\tEEV_fast = 1;\n\t\t\t\twhile (EEV_apulses < 0){\n\t\t\t\t\tmillis_now = millis();\n\t\t\t\t\teevise();\n\t\t\t\t}\n\t\t\t\tanalogWrite(speakerOut, 10);\n\t\t\t\tdelay (1500);\n\t\t\t\tanalogWrite(speakerOut, 0);\n\t\t\t\tdelay(1000);\n\t\t\t\t//EEV_apulses =  EEV_MAXPULSES;\n\t\t\t\tEEV_apulses =  50;\n\t\t\t\tEEV_fast = 1;\n\t\t\t\twhile (EEV_apulses > 0){\n\t\t\t\t\tmillis_now = millis();\n\t\t\t\t\teevise();\n\t\t\t\t}\n\t\t\t\tanalogWrite(speakerOut, 10);\n\t\t\t\tdelay (1500);\n\t\t\t\tanalogWrite(speakerOut, 0);\n\t\t\t\tdelay(1000);\n\t\t\t#endif\n\t\t\t#if defined SELFTEST_T_SENSORS\n\t\t\t\tGetTemperatures();\n\t\t\t\t\n\t\t\t\toutString=F(\"Tbe: \");\t\tPrintSS_SaD(Tbe);\n\t\t\t\toutString=F(\"Tae: \");\t\tPrintSS_SaD(Tae);\n\t\t\t\toutString=F(\"Tci: \");\t\tPrintSS_SaD(Tci);\n\t\t\t\toutString=F(\"Tco: \");\t\tPrintSS_SaD(Tco);\n\t\t\t\toutString=F(\"Tbc: \");\t\tPrintSS_SaD(Tbc);\n\t\t\t\toutString=F(\"Tac: \");\t\tPrintSS_SaD(Tac);\n\t\t\t\toutString=F(\"Thi: \");\t\tPrintSS_SaD(Thi);\n\t\t\t\toutString=F(\"Tho: \");\t\tPrintSS_SaD(Tho);\n\t\t\t\toutString=F(\"Ts1: \");\t\tPrintSS_SaD(Ts1);\n\t\t\t\toutString=F(\"Tcrc: \");\t\tPrintSS_SaD(Tcrc);\n\t\t\t\toutString=F(\"Ts2: \");\t\tPrintSS_SaD(Ts2);\n\t\t\t\toutString=F(\"Treg: \");\t\tPrintSS_SaD(Treg);\n\t\t\t\tanalogWrite(speakerOut, 10);\n\t\t\t\tdelay (1500);\n\t\t\t\tanalogWrite(speakerOut, 0);\n\t\t\t\tdelay(1000);\n\t\t\t#endif\n\n\t//---------DEBUG END--------  \n\n\t\t}\n\t#endif\n\t\n\t//----------------------------- self-test END----------------------------- ----------------------------- ----------------------------- \n\t\n\t\n\teeprom_magic_read = EEPROM.read(eeprom_addr);\n\teeprom_addr += 1;\n\t//EEPROM content: 0x00 - magic,   0x01..0x04 target value\n\tif (eeprom_magic_read == eeprom_magic){\n\t\tPrintSSch(IDX_EEtoMEM);\n\t} else {\n\t\tPrintSSch(IDX_MEMtoEE);\n\t\tWriteFloatEEPROM(eeprom_addr, T_setpoint);\n\t\tEEPROM.write(0x00, eeprom_magic);\n\t}\n\tT_setpoint = ReadFloatEEPROM(eeprom_addr);\n\tPrintSS_double(T_setpoint);\n\t//eeprom_addr += 4;\n\t\n\tT_setpoint_lastsaved = T_setpoint;\n\n\t#ifdef WATCHDOG\n\t\twdt_enable (WDTO_8S);\n\t#endif\n\t\n\tGetTemperatures();\n\t\n\toutString.reserve(80);\n\tlastStopCauseTxt.reserve(20);\n\tlastStartMsgTxt.reserve(20);\n\tt_sensorErrString.reserve(12);\n\t//PrintSS(String(freeMemory()));\n\t\n\tLED_OK_state\t\t= 1;\n\t\n\t_PrintHelp();\n\t\n\tanalogWrite(speakerOut, 10);\n\tdelay (1500); \n\tanalogWrite(speakerOut, 0);\n\tlastStopCauseTxt = F(\"Start Pause\");\n\tlastStartMsgTxt = \"\";\n}\n\n \nvoid loop(void) {  \n\t\n\tdigitalWrite(SerialTxControl, RS485Receive);\n\tmillis_now = millis();\n\thalifise();\n\teevise();\n\t\n\tif (((unsigned long)(millis_now - millis_last_printstats) > HUMAN_AUTOINFO)   ||   (millis_last_printstats == 0)  ) {\n\t\tPrintStats_SS();\n\t\tmillis_last_printstats = millis_now;\n\t}\n\t//--------------------async fuctions start\n\tif (em_i == 0) {  \n\t\tsupply_voltage = ReadVcc();\n\t}\n\tif (em_i < em_samplesnum) {\n\t\tsampleI_1 = analogRead(em_pin1);\n\t\t// Digital low pass filter extracts the 2.5 V or 1.65 V dc offset, then subtract this - signal is now centered on 0 counts.\n\t\toffsetI_1 = (offsetI_1 + (sampleI_1-offsetI_1)/1024);\n\t\tfilteredI_1 = sampleI_1 - offsetI_1;\n\t\n\t\t// Root-mean-square method current\n\t\t// 1) square current values\n\t\tsqI_1 = filteredI_1 * filteredI_1;\n\t\t// 2) sum\n\t\tsumI_1 += sqI_1;\n\t\t\n\t\tem_i += 1;\n\t} else {\n\t\tem_i = 0;\n\t\tdouble I_RATIO = em_calibration *((supply_voltage/1000.0) / (ADC_COUNTS));\n\t\tasync_Irms_1 = I_RATIO * sqrt(sumI_1 / em_samplesnum);\n\t\tasync_wattage = async_Irms_1*220.0;\n\t\n\t\t//Reset accumulators\n\t\tsumI_1 = 0;\n\t\t\n\t\t//----------------------------- self-test !!!\n\t\t/*\n\t\tPrintSS(\"Async impl. results 1:  \");\n\t\tPrintSS(String(async_wattage));\t           // Apparent power\n\t\tPrintSS(String(async_Irms_1));\t           // Irms\n\t\tPrintSS(\" voltage: \");\n\t\tPrintSS(String(supply_voltage));\n\t\t*/\n\t\t//----------------------------- self-test END\n\t\t\n\t}\n\teevise();\n\n\t//--------------------async fuctions END    \n\t\n\tif ( heatpump_state == 1   &&  async_wattage > c_wattage_max  ) {\n\t\tif (  ((unsigned long)(millis_now - millis_last_heatpump_off) > POWERON_HIGHTIME )\t||\t(async_wattage > c_wattage_max*3)) {\n\t\t\tmillis_last_heatpump_on = millis_now;\n\t\t\theatpump_state = 0;\n\t\t\tLSCint = LSCint_protective;\n\t\t\thalifise();\n\t\t\tlastStopCauseTxt = (\"P.WtMax:\") + String(async_wattage);\n\t\t\tPrintSS(lastStopCauseTxt);\n\t\t}\n\t}\n\t\t\n\t//-------------------check cycle\n\tif(  ((unsigned long)(millis_now - millis_prev) > millis_cycle )  ||  (millis_prev == 0) ) {\n\t\tmillis_prev = millis_now;\n\t\tGetTemperatures();  //      wdt_reset here due to 85.0'C filtration\n\t\tSaveSetpointEE();\n\t\tpr_low_state_anal  \t= analogRead(PR_LOW);\t//\n\t\tpr_high_state_anal  \t= analogRead(PR_HIGH);\t//shotrcut test shows 993-994 for analogRead (10.4ma)\n\t\tif (pr_low_state_anal > 200) {\n\t\t\tpr_low_state_bool = 1;\n\t\t} else {\n\t\t\tpr_low_state_bool = 0;\n\t\t}\n\t\tif (pr_high_state_anal > 200) {\n\t\t\tpr_high_state_bool = 1;\n\t\t} else {\n\t\t\tpr_high_state_bool = 0;\n\t\t}\t\n\t\t//--------------------important logic\n\t\t//check T sensors\n\t\tif ( errorcode == ERR_OK ) {\n\t\t\tif (TbeE == 1 \t&& Tbe == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Tbe\");}\n\t\t\tif (TaeE == 1 \t&& Tae == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Tae\");}\n\t\t\tif (TciE == 1 \t&& Tci == -127 )\t{errorcode = ERR_T_SENSOR; outString = F(\"E.Tci\");}\n\t\t\tif (TcoE == 1 \t&& Tco == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Tco\");} \n\t\t\tif (TbcE == 1 \t&& Tbc == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Tbc\");}\n\t\t\tif (TacE == 1 \t&& Tac == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Tac\");}\n\t\t\tif (ThiE == 1 \t&& Thi == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Thi\");}\n\t\t\tif (ThoE == 1 \t&& Tho == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Tho\");}\n\t\t\t//if (TsgE == 1 \t&& Tsg == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Tsg\");}\n\t\t\t//if (TslE == 1 \t&& Tsl == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Tsl\");}\n\t\t\t//if (TbvE == 1 \t&& Tbv == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Tbv\");}\n\t\t\t//if (TsucE == 1 \t&& Tsuc == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Tsuc\");}\n\t\t\tif (Ts1E == 1 \t&& Ts1 == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Ts1\");}\n\t\t\tif (Ts2E == 1\t&& Ts2 == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Ts2\");}\n\t\t\tif (TcrcE == 1 \t&& Tcrc == -127 )  \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Tcrc\");}\n\t\t\tif (TregE == 1 \t&& Treg == -127 ) \t{errorcode = ERR_T_SENSOR; outString = F(\"E.Treg\");}\n\t\t\t\n\t\t\tif (errorcode == ERR_T_SENSOR){\n\t\t\t\t//PrintSS(String(outString));\n\t\t\t\tt_sensorErrString = String(outString);\t\n\t\t\t\t//printed to console below\n\t\t\t}\n\t\t}\n\t\t\n\t\t//auto-clean sensor error on sensor appears\n\t\t// add 1xor enable here!\n\t\tif ( ( errorcode == ERR_T_SENSOR )     && (   \t((TciE == 1 \t&& Tci != -127 )  \t||\t(TciE\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t((TcoE == 1 \t&& Tco != -127 )  \t||\t(TcoE\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t((TbeE == 1 \t&& Tbe != -127 )  \t||\t(TbeE\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t((TaeE == 1 \t&& Tae != -127 )  \t||\t(TaeE\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t//((TsgE == 1 \t&& Tsg != -127 )  \t||\t(TsgE\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t//((TslE == 1 \t&& Tsl != -127 )  \t||\t(TslE\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t//((TbvE == 1 \t&& Tbv != -127 )  \t||\t(TbvE\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t//((TsucE == 1 \t&& Tsuc != -127 )  \t||\t(TsucE\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t((Ts1E == 1 \t&& Ts1 != -127 )  \t||\t(Ts1E\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t((Ts2E == 1\t&& Ts2 != -127 )  \t||\t(Ts2E ^1)) \t&&\t\n\t\t\t\t\t\t\t\t((TcrcE == 1 \t&& Tcrc != -127 )  \t||\t(TcrcE\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t((TregE == 1 \t&& Treg != -127 )  \t||\t(TregE\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t((TacE == 1 \t&& Tac != -127 )  \t||\t(TacE\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t((TbcE == 1 \t&& Tbc != -127 )  \t||\t(TbcE\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t((ThoE == 1 \t&& Tho != -127 )  \t||\t(ThoE\t^1)) \t&&\t\n\t\t\t\t\t\t\t\t((ThiE == 1 \t&& Thi != -127 )  \t||\t(ThiE\t^1)) \t)) {\n\t\t\t\t\t\t\t\t\t\t\terrorcode = ERR_OK;\n\t\t\t\t\t\t\t\t\t\t\tPrintSSch(IDX_OK_ETSENS);\n\t\t\t\t\t\t\t\t\t\t\tsequential_errors = 0;\n\t\t\t\t\t\t\t\t\t\t\tt_sensorErrString = \"\";\n\t\t}\n\t\t\n\t\t//check pressure sensors\n\t\t//auto-clean prev. errors first\n\t\tif ( errorcode == ERR_P_LO ) {\n\t\t\tif (pr_low_state_bool == 1) \t{\n\t\t\t\terrorcode = ERR_OK; \n\t\t\t\tPrintSSch(IDX_OK_PRCOLD);\n\t\t\t}\n\t\t}\n\t\tif ( errorcode == ERR_P_HI ) {\n\t\t\tif (pr_high_state_bool == 1) \t{\n\t\t\t\terrorcode = ERR_OK; \n\t\t\t\tPrintSSch(IDX_OK_PRHOT);\n\t\t\t}\n\t\t}\n\n\t\t\n\t\t//recheck, if another sensor\n\t\tif ( errorcode == ERR_OK ) {\n\t\t\tif (pr_low_state_bool == 0) \t{errorcode = ERR_P_LO;}\t//for PrintSS scroll down\n\t\t\tif (pr_high_state_bool == 0)\t{errorcode = ERR_P_HI;} //for PrintSS scroll down\n\t\t}\n\t\t\t\n\t\t//-------------- EEV cycle\n\t\t/*\n\t\t//v1 algo\n\t\tif ( EEV_apulses == 0 )\t{\n\t\t\tif ( \t((async_wattage < c_workingOK_wattage_min) && ((unsigned long)(millis_now - millis_eev_last_close) > EEV_CLOSEEVERY))\t\t||  millis_eev_last_close == 0  ){\n\t\t\t\tPrintSS(\"EEV: FULL closing\");\n\t\t\t\tif ( millis_eev_last_close != 0 ) {\n\t\t\t\t\tEEV_apulses =  -(EEV_cur_pos + EEV_CLOSE_ADD_PULSES);\n\t\t\t\t} else {\n\t\t\t\t\tEEV_apulses =  -(EEV_MAXPULSES + EEV_CLOSE_ADD_PULSES);\n\t\t\t\t}\n\t\t\t\tEEV_adonotcare = 1;\n\t\t\t\tEEV_fast = 1;\n\t\t\t\t//delay(EEV_STOP_HOLD);\n\t\t\t\tmillis_eev_last_close = millis_now;\n\t\t\t} else if (errorcode != 0 || async_wattage <= c_workingOK_wattage_min) {\t\t//err or sleep\n\t\t\t\tPrintSS(\"EEV: err or sleep\");\n\t\t\t\tif (EEV_cur_pos <= 0 && EEV_OPEN_AFTER_CLOSE != 0) {\t\t\t\t//set waiting pos\n\t\t\t\t\tEEV_apulses = +EEV_OPEN_AFTER_CLOSE;\n\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t}\n\t\t\t\tif (EEV_cur_pos > 0  && EEV_cur_pos != EEV_OPEN_AFTER_CLOSE && EEV_cur_pos <= EEV_MAXPULSES) {\t//waiting pos. set\n\t\t\t\t\tPrintSS(\"EEV: close\");\n\t\t\t\t\tEEV_apulses =  -(EEV_cur_pos + EEV_CLOSE_ADD_PULSES);\n\t\t\t\t\tEEV_adonotcare = 1;\n\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t}\n\t\t\t} else if (errorcode == 0 && async_wattage > c_workingOK_wattage_min) {\n\t\t\t\tT_EEV_dt = Tae.T - Tbe.T;\n\t\t\t\tPrintSS(\"EEV: driving \" + String(T_EEV_dt));\n\t\t\t\tif (EEV_cur_pos <= 0){\n\t\t\t\t\tPrintSS(\"EEV: full close protection\");\t\n\t\t\t\t\tif (EEV_OPEN_AFTER_CLOSE != 0) {\t\t\t\t//full close protection\n\t\t\t\t\t\tEEV_apulses = +EEV_OPEN_AFTER_CLOSE;\n\t\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t\t}\n\t\t\t\t} else if (EEV_cur_pos > 0) {\n\t\t\t\t\tif (T_EEV_dt  < (T_EEV_setpoint - EEV_EMERG_DIFF) ) {\t\t\t\t//emerg!\n\t\t\t\t\t\tPrintSS(\"EEV: emergency closing!\");\n\t\t\t\t\t\tEEV_apulses = -EEV_EMERG_STEPS;\n\t\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t\t} else if (T_EEV_dt  < T_EEV_setpoint) {\t\t\t\t\t//too\n\t\t\t\t\t\tPrintSS(\"EEV: closing\");\n\t\t\t\t\t\t//EEV_apulses = -EEV_NONPRECISE_STEPS;\n\t\t\t\t\t\tEEV_apulses = -1;\n\t\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\t\tEEV_fast = 0;\n\t\t\t\t\t} else if (T_EEV_dt  > T_EEV_setpoint + EEV_HYSTERESIS + EEV_PRECISE_START) {\t//very\n\t\t\t\t\t\tPrintSS(\"EEV: fast opening\");\n\t\t\t\t\t\t//EEV_apulses =  +EEV_NONPRECISE_STEPS;\n\t\t\t\t\t\tEEV_apulses =  +1;\n\t\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t\t} else if (T_EEV_dt > T_EEV_setpoint + EEV_HYSTERESIS) {\t\t\t//too\n\t\t\t\t\t\tPrintSS(\"EEV: opening\");\n\t\t\t\t\t\tEEV_apulses =  +1;\n\t\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\t\tEEV_fast = 0;\n\t\t\t\t\t} else if (T_EEV_dt  > T_EEV_setpoint) {\t\t\t\t\t//ok\n\t\t\t\t\t\tPrintSS(\"EEV: OK\");\n\t\t\t\t\t\t//\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\toff_EEV();\n\t\t\t} \n\t\t\t\n\t\t}\n\t\t*/\n\t\t//v1.2 algo: reopen added\n\t\t#ifndef NO_EEV\n\t\t\tif ( EEV_manual == 0 && errorcode == 0 && async_wattage >= c_workingOK_wattage_min && EEV_cur_pos > 0 )\t{\n\t\t\t\tT_EEV_dt = Tae - Tbe;\n\t\t\t\t#ifdef EEV_DEBUG\n\t\t\t\t\tPrintSS(\"EEV Td: \" + String(T_EEV_dt));\n\t\t\t\t#endif\n\t\t\t\tif ( EEV_apulses >= 0 && EEV_cur_pos >= EEV_MINWORKPOS)\t{\n\t\t\t\t\tif (T_EEV_dt  < (T_EEV_setpoint - EEV_EMERG_DIFF) ) {\t\t\t\t//emerg!\n\t\t\t\t\t\t#ifdef EEV_DEBUG\n\t\t\t\t\t\t\tPrintSS(F(\"EEV: 1 emergency closing!\"));\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\tEEV_apulses = -1;\n\t\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t\t} else if (T_EEV_dt  < T_EEV_setpoint) {\t\t\t\t\t//too\n\t\t\t\t\t\t#ifdef EEV_DEBUG\n\t\t\t\t\t\t\tPrintSS(F(\"EEV: 2 closing\"));\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\t//EEV_apulses = -EEV_NONPRECISE_STEPS;\n\t\t\t\t\t\tEEV_apulses = -1;\n\t\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\t\tEEV_fast = 0;\n\t\t\t\t\t}\n\t\t\t\t\t//faster open when needed, condition copypasted (see EEV_apulses <= 0)\n\t\t\t\t\tif (T_EEV_dt  > T_EEV_setpoint + EEV_HYSTERESIS + EEV_PRECISE_START) {\t\t//very\n\t\t\t\t\t\t#ifdef EEV_DEBUG\n\t\t\t\t\t\t\tPrintSS(F(\"EEV: 3 enforce faster opening\"));\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\t//EEV_apulses =  +EEV_NONPRECISE_STEPS;\n\t\t\t\t\t\t//EEV_apulses =  +1;\n\t\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( EEV_apulses <= 0 )\t{\n\t\t\t\t\t\n\t\t\t\t\tif ( EEV_must_reopen_flag == 1 && (T_EEV_dt > T_EEV_setpoint + EEV_HYSTERESIS)  && ((unsigned long)(millis_now - millis_eev_minworkpos_time) > EEV_REOPENMINTIME)   &&  (millis_eev_last_work <\tmillis_eev_minworkpos_time)  ) {\t//reopen\n\t\t\t\t\t\tEEV_must_reopen_flag = 0;\n\t\t\t\t\t\tEEV_apulses = EEV_reopen_pos - EEV_cur_pos;\n\t\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t\t\t#ifdef EEV_DEBUG\n\t\t\t\t\t\t\tPrintSS(F(\"EEV: 14 reopening last\"));\n\t\t\t\t\t\t\tPrintSS(String(EEV_apulses));\n\t\t\t\t\t\t\tPrintSS(String(millis_now));\n\t\t\t\t\t\t\tPrintSS(String(millis_eev_minworkpos_time));\n\t\t\t\t\t\t\tPrintSS(String(millis_eev_last_work));\n\t\t\t\t\t\t#endif\n\t\t\t\t\t} else if (T_EEV_dt  > T_EEV_setpoint + EEV_HYSTERESIS + EEV_PRECISE_START) {\t//very\n\t\t\t\t\t\t#ifdef EEV_DEBUG\n\t\t\t\t\t\t\tPrintSS(F(\"EEV: 4 fast opening\"));\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\t//EEV_apulses =  +EEV_NONPRECISE_STEPS;\n\t\t\t\t\t\tEEV_apulses =  +1;\n\t\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t\t} else if (T_EEV_dt > T_EEV_setpoint + EEV_HYSTERESIS) {\t\t\t//too\n\t\t\t\t\t\t#ifdef EEV_DEBUG\n\t\t\t\t\t\t\tPrintSS(F(\"EEV: 5 opening\"));\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\tEEV_apulses =  +1;\n\t\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\t\tEEV_fast = 0;\n\t\t\t\t\t} else if (T_EEV_dt  > T_EEV_setpoint) {\t\t\t\t\t//ok\n\t\t\t\t\t\t#ifdef EEV_DEBUG\n\t\t\t\t\t\t\tPrintSS(F(\"EEV: 6 OK\"));\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\t//\n\t\t\t\t\t}\n\t\t\t\t\t//faster closing when needed, condition copypasted (see EEV_apulses >= 0)\n\t\t\t\t\tif (T_EEV_dt  < (T_EEV_setpoint - EEV_EMERG_DIFF) ) {\t\t\t\t//emerg!\n\t\t\t\t\t\t#ifdef EEV_DEBUG\n\t\t\t\t\t\t\tPrintSS(F(\"EEV: 7 enforce faster closing!\"));\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\t//EEV_apulses = -EEV_EMERG_STEPS;\n\t\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\toff_EEV();\n\t\t\t}\n\t\t\t\n\t\t\tif ( EEV_manual == 0 && EEV_apulses == 0 )\t{\n\t\t\t\tif ( \t((async_wattage < c_workingOK_wattage_min) && ((unsigned long)(millis_now - millis_eev_last_close) > EEV_CLOSEEVERY))\t\t||  millis_eev_last_close == 0  ){\t//close every 24h by default\n\t\t\t\t\t#ifdef EEV_DEBUG\n\t\t\t\t\t\tPrintSS(F(\"EEV: 10 FULL closing\"));\n\t\t\t\t\t#endif\n\t\t\t\t\tif ( millis_eev_last_close != 0 ) {\n\t\t\t\t\t\tEEV_apulses =  -(EEV_cur_pos + EEV_CLOSE_ADD_PULSES);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tEEV_apulses =  -(EEV_MAXPULSES + EEV_CLOSE_ADD_PULSES);\n\t\t\t\t\t}\n\t\t\t\t\tEEV_adonotcare = 1;\n\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t\t//delay(EEV_STOP_HOLD);\n\t\t\t\t\tmillis_eev_last_close = millis_now;\n\t\t\t\t}\n\t\t\t\telse if (errorcode != 0 || async_wattage < c_workingOK_wattage_min) {\t\t//err or sleep\n\t\t\t\t\tif (EEV_cur_pos > 0  && EEV_cur_pos > EEV_OPEN_AFTER_CLOSE) {\t\t//waiting pos. set\n\t\t\t\t\t\tEEV_reopen_pos\t\t= EEV_cur_pos;\t\t\t\t//reopen pos. set\n\t\t\t\t\t\tEEV_must_reopen_flag\t= 1;\n\t\t\t\t\t\tmillis_eev_last_work\t= millis_now;\n\t\t\t\t\t\t#ifdef EEV_DEBUG\n\t\t\t\t\t\t\tPrintSS(F(\"EEV: 11 close before open\"));\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\tEEV_apulses =  -(EEV_cur_pos + EEV_CLOSE_ADD_PULSES);\n\t\t\t\t\t\tEEV_adonotcare = 1;\n\t\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\toff_EEV();\n\t\t\t}\n\t\t\tif ( EEV_manual == 0 && EEV_apulses == 0 && async_wattage < c_workingOK_wattage_min && EEV_cur_pos < EEV_OPEN_AFTER_CLOSE) {\n\t\t\t\t#ifdef EEV_DEBUG\n\t\t\t\t\tPrintSS(F(\"EEV: 12 full close protection\"));\n\t\t\t\t#endif\n\t\t\t\tif (EEV_OPEN_AFTER_CLOSE != 0) {\t\t\t\t//full close protection\n\t\t\t\t\tEEV_apulses = EEV_OPEN_AFTER_CLOSE - EEV_cur_pos;\n\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t}\n\t\t\t\toff_EEV();\n\t\t\t}\n\t\t\tif ( EEV_manual == 0 && EEV_apulses == 0 && async_wattage >= c_workingOK_wattage_min && EEV_cur_pos < EEV_MINWORKPOS) {\n\t\t\t\t#ifdef EEV_DEBUG\n\t\t\t\t\tPrintSS(F(\"EEV: 13 open to work\"));\t\n\t\t\t\t#endif\n\t\t\t\tif (EEV_MINWORKPOS != 0) {\t\t\t\n\t\t\t\t\tEEV_apulses = EEV_MINWORKPOS - EEV_cur_pos;\n\t\t\t\t\tEEV_adonotcare = 0;\n\t\t\t\t\tEEV_fast = 1;\n\t\t\t\t\t//millis_eev_minworkpos_time = millis_now;\n\t\t\t\t}\n\t\t\t\toff_EEV();\n\t\t\t}\n\t\t\tif (EEV_cur_pos < EEV_MINWORKPOS) {\t//for reopen\n\t\t\t\tmillis_eev_minworkpos_time = millis_now;\n\t\t\t}\n\t\t\tif ( EEV_manual == 0 && EEV_apulses == 0 && EEV_fast == 1 ) {//just for LED\n\t\t\t\tEEV_fast = 0;\n\t\t\t}\n\t\t\tif (\t((unsigned long)(millis_now - millis_eev_last_on) > 10000)  ||  millis_eev_last_on == 0 ) {\n\t\t\t\t//PrintSS(\"EEV: ON/OFF\");\n\t\t\t\ton_EEV();\n\t\t\t\t//delay(30);\n\t\t\t\t//off_EEV();\t//off_EEV called somewhere else takes care of it\n\t\t\t\tmillis_eev_last_on  =  millis_now;\n\t\t\t}\n\t\t\t//-------------- EEV cycle END\n\t\t#endif\n\t\t#ifndef EEV_ONLY\n\t\t\t//process heatpump crankcase heater\n\t\t\tif (TcrcE == 1) {\n\t\t\t\tif ( Tcrc < cT_crc_heat_threshold   &&   crc_heater_state == 0   &&   Tcrc != -127) {\n\t\t\t\t\tcrc_heater_state = 1;\n\t\t\t\t} else if (Tcrc >= cT_crc_heat_threshold  && crc_heater_state == 1) {\n\t\t\t\t\tcrc_heater_state = 0;\n\t\t\t\t} else if (Tcrc == -127) {\n\t\t\t\t\tcrc_heater_state = 0;\n\t\t\t\t}\n\t\t\t\thalifise();\n\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t//main logic\n\t\t\tif (_1st_start_sleeped == 0) {\n\t\t\t\t//enable hot WP immidiately\n\t\t\t\tif (hotside_circle_state  == 0){\n\t\t\t\t\tmillis_last_hotWP_off = millis_now;\n\t\t\t\t\thotside_circle_state  = 1;\n\t\t\t\t}\n\t\t\t\t//_1st_start_sleeped = 1;\n\t\t\t\tif ( (millis_now < poweron_pause) && (_1st_start_sleeped == 0) ) {\n\t\t\t\t\toutString = String(((poweron_pause-millis_now))/1000);\n\t\t\t\t\t//PrintSS(\"Wait: \" + outString + \" s.\");\n\t\t\t\t\tlastStartMsgTxt = \"StCntd:\" + outString; //start countdown, max 5 numerical places\n\t\t\t\t\tfl_printSS_lastStartMsgTxt = 1;\n\t\t\t\t\t//PrintSS(lastStartMsgTxt);\n\t\t\t\t\t//return;\n\t\t\t\t} else {\n\t\t\t\t\t_1st_start_sleeped = 1;\n\t\t\t\t\tlastStopCauseTxt=\"\";\n\t\t\t\t\tlastStartMsgTxt=\"\";\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t//process_heatpump:\n\t\t\t//start if\n\t\t\t//    (last_on > N or not_started_yet)\n\t\t\t//    and (no errors)\n\t\t\t//    and (t hot out < t target)\n\t\t\t//    and (t hot out < t hot max)\n\t\t\t//    and (t hot in < t hot max)\n\t\t\t//    and (crc t > min'C)\n\t\t\t//    and (crc t < max'C)\n\t\t\t//    and (t watertank < target)\n\t\t\t//    and (t after evaporator > after evaporator min)\n\t\t\t//    and (t cold in > cold min)\n\t\t\t//    and (t cold out > cold min)\n\t\t\tif (heatpump_state == 0 &&\terrorcode == ERR_T_SENSOR) {\n\t\t\t\tlastStartMsgTxt = t_sensorErrString;\n\t\t\t\t//fl_printSS_lastStartMsgTxt = 1;\n\t\t\t}\n\t\t\t\n\t\t\tif (heatpump_state == 0 && errorcode == ERR_P_LO ) {\n\t\t\t\tlastStartMsgTxt = F(\"E.PresCold\");\n\t\t\t}\n\t\t\t\n\t\t\tif (heatpump_state == 0 && errorcode == ERR_P_HI ) {\n\t\t\t\tlastStartMsgTxt = F(\"E.PresHot\");\n\t\t\t}\n\n\t\t\tif (heatpump_state == 0 &&\terrorcode == ERR_OK \t&& \t_1st_start_sleeped == 1) {\n\t\t\t\ti = 0;\n\t\t\t\t#ifdef SETPOINT_THI\n\t\t\t\tif ( Thi < T_setpoint )  \t\t\t\t\t\t\t\t{i+=1;} else { lastStartMsgTxt = F(\"#Thi>Setp.\"); }\t//or1\t//Thi = warm floor heat pump\n\t\t\t\t#endif\n\t\t\t\t#ifdef SETPOINT_TS1\n\t\t\t\t\tif ( Ts1 < T_setpoint )  \t\t\t\t\t\t\t\t{i+=1;} else { lastStartMsgTxt = F(\"#Ts1>Setp.\"); }\t//or1\t//Ts1 = tank heater\n\t\t\t\t#endif\n\t\t\t\t//2\twait cold circe if needed\n\t\t\t\tif ( coldside_circle_state  == 1 && ((unsigned long)(millis_now - millis_last_coldWP_off) > COLDCIRCLE_PREPARE) ){\n\t\t\t\t\ti+= 1;\n\t\t\t\t//only if hot runned and T < setpoint\n\t\t\t\t} else if ((coldside_circle_state  == 0) && (hotside_circle_state  == 1) && ((unsigned long)(millis_now - millis_last_hotWP_off) > HOTCIRCLE_CHECK_PREPARE) ) {\n\t\t\t\t\t#ifdef SETPOINT_THI\n\t\t\t\t\tif ( Thi < T_setpoint ) \t{\n\t\t\t\t\t#endif\n\t\t\t\t\t#ifdef SETPOINT_TS1\n\t\t\t\t\tif ( Ts1 < T_setpoint )  \t{\n\t\t\t\t\t#endif\n\t\t\t\t\t\tlastStartMsgTxt = F(\"#CPpStart\");\n\t\t\t\t\t\tmillis_last_coldWP_off = millis_now;\n\t\t\t\t\t\tcoldside_circle_state  = 1;\n\t\t\t\t\t\tfl_printSS_lastStartMsgTxt = 1;\n\t\t\t\t\t\t//PrintSS(lastStartMsgTxt);\n\t\t\t\t\t}\n\t\t\t\t} else if (coldside_circle_state  == 1) {\n\t\t\t\t\tlastStartMsgTxt = \"#CPp:\" + String( (COLDCIRCLE_PREPARE -(unsigned long)(millis_now - millis_last_coldWP_off))/1000 );\n\t\t\t\t}\n\t\t\t\t//3\twait hot circe if needed\n\t\t\t\t#ifdef SETPOINT_THI\n\t\t\t\t\tif ((hotside_circle_state  == 1) && ((unsigned long)(millis_now - millis_last_hotWP_off) > HOTCIRCLE_CHECK_PREPARE)\t)\t{\t\n\t\t\t\t\t\ti+=1;\n\t\t\t\t\t} else if (hotside_circle_state  == 1) {\t//waiting for T stabilisation\n\t\t\t\t\t\tlastStartMsgTxt = \"#HotPrp:\" + String( (HOTCIRCLE_CHECK_PREPARE -(unsigned long)(millis_now - millis_last_hotWP_off))/1000 );\n\t\t\t\t\t} else if (hotside_circle_state  == 0) {\t//sleeping, hot CP off, waiting for next check cycle\n\t\t\t\t\t\tlastStartMsgTxt = \"#HotSlp:\" + String( (HOTCIRCLE_START_EVERY -(unsigned long)(millis_now - millis_last_hotWP_on))/1000 );\n\t\t\t\t\t}\n\t\t\t\t#else ifdef SETPOINT_TS1\n\t\t\t\t\ti+=1;\n\t\t\t\t#endif\n\t\t\t\t//4\tcountdown, compressor min. cycle\n\t\t\t\tif (((unsigned long)(millis_now - millis_last_heatpump_on) > mincycle_poweroff)   ||   (millis_last_heatpump_on == 0)  )  \t{\t\n\t\t\t\t\ti+=1;\n\t\t\t\t} else {\n\t\t\t\t\tif (millis_last_heatpump_on != 0){\n\t\t\t\t\t\tlastStartMsgTxt = \"#HPSlp:\" + String( (mincycle_poweroff -(unsigned long)(millis_now - millis_last_heatpump_on))/1000 );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif ( (TcrcE == 1 \t&& Tcrc > cT_crc_min)  \t\t\t||\t(TcrcE^1))\t{i+=1;} else { lastStartMsgTxt = F(\"#CaseCold\"); }\t//5\n\t\t\t\tif ( (TaeE == 1 \t&& Tae > cT_coldref_min)\t\t||\t(TaeE^1))\t{i+=1;} else { lastStartMsgTxt = F(\"#Tae<RefMin\"); }\t//6\n\t\t\t\tif ( (TbeE == 1 \t&& Tbe > cT_coldref_min)\t\t||\t(TbeE^1))\t{i+=1;} else { lastStartMsgTxt = F(\"#Tbe<RefMin\"); }\t//7\n\t\t\t\tif ( (TciE == 1 \t&& Tci > cT_cold_min)  \t\t\t||\t(TciE^1))\t{i+=1;} else { lastStartMsgTxt = F(\"#Tci<ColdMin\"); }\t//8\n\t\t\t\tif ( (TcoE == 1 \t&& Tco > cT_cold_min) \t\t\t||\t(TcoE^1))\t{i+=1;} else { lastStartMsgTxt = F(\"#Tco<ColdMin\"); }\t//9\n\t\t\t\tif ( (ThoE == 1 \t&& Tho \t< cT_hot_max)\t\t\t||\t(ThoE^1))\t{i+=1;} else { lastStartMsgTxt = F(\"#Tho>Max\"); }\t//10\n\t\t\t\tif ( (ThiE == 1 \t&& Thi \t< cT_hot_max)\t\t\t||\t(ThiE^1))\t{i+=1;} else { lastStartMsgTxt = F(\"#Thi>Max\"); }\t//11\n\t\t\t\t//t1_crc > t2_cold_in   && ???\n\t\t\t\tif ( (TcrcE == 1 \t&& Tcrc < cT_crc_max)  \t\t\t||\t(TcrcE^1))\t{i+=1;} else { lastStartMsgTxt = F(\"#CaseHot\"); }\t//12\n\t\t\t\tif ( (TbcE == 1 \t&& Tbc < cT_before_condenser_max) \t||\t(TbcE^1))\t{i+=1;} else { lastStartMsgTxt = F(\"#Tbc>Max\"); }\t//13\n\t\t\t\t//if ( (TregE == 1 \t&& Treg > cT_crc_min)  \t\t\t||\t(TregE^1))\t{i+=1;} else { lastStartMsgTxt = F(\"RegCold\"); }\t//14\n\t\t\t\t//if ( (TsucE == 1 \t&& Tsuc > cT_coldref_min)\t\t||\t(TsucE^1))\t{i+=1;} else { lastStartMsgTxt = F(\"Suc<CRMin\"); }\t//15\n\t\t\t\tif (i == 13) {\n\t\t\t\t\t\t\t//PrintSS(F(\"HP Started\"));\n\t\t\t\t\t\t\tlastStartMsgTxt = F(\"HP_Started\");\n\t\t\t\t\t\t\tfl_printSS_lastStartMsgTxt = 1;\n\t\t\t\t\t\t\tmillis_last_heatpump_off = millis_now;\n\t\t\t\t\t\t\theatpump_state = 1;\n\t\t\t\t\t\t\tlastStopCauseTxt = \"\";\n\t\t\t\t\t\t\t//lastStartMsgTxt = \"\";\n\t\t\t\t} else if (i < 13){\n\t\t\t\t\t//\"waiting for something\" state, do nothing here\n\t\t\t\t} else {\n\t\t\t\t\t//lastStartMsgTxt = F(\"UErr:1897\");\n\t\t\t\t\t//PrintSS(lastStartMsgTxt);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t//\n\t\t\t\n\t\t\t//stop if\n\t\t\t//    ( (last_off > N) and (t watertank > target) )\n\t\t\t#ifdef SETPOINT_THI\n\t\t\tif ( heatpump_state == 1     &&     ((unsigned long)(millis_now - millis_last_heatpump_off) > mincycle_poweron)    &&    (Thi > T_setpoint) &&  errorcode == ERR_OK) {//or Ts1, if tank heater\n\t\t\t#endif\n\t\t\t#ifdef SETPOINT_TS1\n\t\t\tif ( heatpump_state == 1     &&     ((unsigned long)(millis_now - millis_last_heatpump_off) > mincycle_poweron)    &&    (Ts1 > T_setpoint) &&  errorcode == ERR_OK) {//or Thi, if default warm floor heat pump\n\t\t\t#endif\n\t\t\t\tmillis_last_heatpump_on = millis_now;\n\t\t\t\theatpump_state = 0;\n\t\t\t\tLSCint = LSCint_normal;\n\t\t\t\tlastStopCauseTxt=F(\"Normal_stop\");\n\t\t\t\tfl_printSS_lastStopCauseTxt = 1;\n\t\t\t\t//PrintSS(lastStopCauseTxt);\n\t\t\t}\n\n\t\t\t//process_hot_side_pump:\n\t\t\t//start if (heatpump_enabled)\n\t\t\t//stop if (heatpump_disabled and (t hot out or in < t target + heat delta min) )\n\t\t\tif (  ((heatpump_state == 1)   &&  (hotside_circle_state  == 0) ) \t|| \t((_1st_start_sleeped == 0 ) && (hotside_circle_state  == 0))\t){\n\t\t\t\tPrintSSch(IDX_HWPON);\n\t\t\t\tmillis_last_hotWP_off = millis_now;\n\t\t\t\thotside_circle_state  = 1;\n\t\t\t}\n\t\t\t#ifdef SETPOINT_THI\n\t\t\t\tif (  (heatpump_state == 0)   &&  (hotside_circle_state  == 0)  && ((unsigned long)(millis_now - millis_last_hotWP_on) > HOTCIRCLE_START_EVERY)\t) {    //process START_EVERY for hot side\n\t\t\t\t\tmillis_last_hotWP_off = millis_now;\n\t\t\t\t\thotside_circle_state  = 1;\n\t\t\t\t\t//PrintSS(F(\"HWP ON by startevery\"));\n\t\t\t\t\tlastStartMsgTxt = F(\"HWP_ON_by_ev\");\n\t\t\t\t\tfl_printSS_lastStartMsgTxt = 1;\n\t\t\t\t}\n\t\t\t#endif\n\t\t\t\n\t\t\tif (  (heatpump_state == 0)        &&    (hotside_circle_state  == 1) ) {\n\t\t\t\tif (\t( (unsigned long)(millis_now - millis_last_heatpump_on) > deffered_stop_hotcircle) \t|| \tmillis_last_heatpump_on == 0) \t{ //deffered stop aftret heat pump stop and correct processing of 1st start, 1st_start sleeped flag not used - there's another logic\n\t\t\t\t\t/*\n\t\t\t\t\t//useful for tank heater with Ts1 as setpont control and large intermediate water reservoir\n\t\t\t\t\tif ( \t(ThoE == 1 && Tho < (Ts1 + cT_hotcircle_delta_min))\t||\n\t\t\t\t\t\t(ThiE == 1 && Thi < (Ts1 + cT_hotcircle_delta_min))\t) {\n\t\t\t\t\t\tPrintSS(F(\"Hot CP OFF 1\"));\n\t\t\t\t\t\tmillis_last_hotWP_on = millis_now;\n\t\t\t\t\t\thotside_circle_state  = 0;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tPrintSS(F(\"Hot CP OFF 2\"));\n\t\t\t\t\t\tmillis_last_hotWP_on = millis_now;\n\t\t\t\t\t\thotside_circle_state  = 0;\n\t\t\t\t\t}\n\t\t\t\t\t*/\n\t\t\t\t\tif ( (unsigned long)(millis_now - millis_last_hotWP_off) > HOTCIRCLE_STOP_AFTER) {\t//and START_EVERY processing\n\t\t\t\t\t\t#ifdef SETPOINT_THI\n\t\t\t\t\t\tif ( Thi > T_setpoint ) \t{\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\t#ifdef SETPOINT_TS1\n\t\t\t\t\t\tif ( Ts1 > T_setpoint )  \t{\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\t\t//PrintSS(F(\"HWP OFF\"));\n\t\t\t\t\t\t\tlastStartMsgTxt = F(\"HWP_OFF\");\n\t\t\t\t\t\t\tfl_printSS_lastStartMsgTxt = 1;\n\t\t\t\t\t\t\tmillis_last_hotWP_on = millis_now;\n\t\t\t\t\t\t\thotside_circle_state  = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t//heat if we can, just in case, ex. if lost power, usefull for tank heater with large intermediate water reservoir\n\t\t\t/*\n\t\t\tif ( (hotside_circle_state  == 0) && \n\t\t\t\t( ThoE == 1 && Tho > (Ts1 + cT_hotcircle_delta_min)  )  \t||\n\t\t\t\t( ThiE == 1 && Thi > (Ts1 + cT_hotcircle_delta_min)  )  ) \t{\n\t\t\t\t\tPrintSS(F(\"Hot WP ON\"));\n\t\t\t\t\thotside_circle_state  = 1;\n\t\t\t}\n\t\t\t*/\n\t\t\t\n\t\t\t//process_cold_side_pump:\n\t\t\t//start if (heatpump_enabled)\n\t\t\t//stop if (heatpump_disbled)\n\t\t\t//start if tci < cold_min\n\t\t\tif (  (heatpump_state == 1)   &&  (coldside_circle_state  == 0)  ) {\n\t\t\t\t//PrintSS(F(\"CWP_ON\"));\n\t\t\t\tmillis_last_coldWP_off = millis_now;\n\t\t\t\tcoldside_circle_state  = 1;\n\t\t\t}\n\t\t\t\n\t\t\tif (\t(heatpump_state == 0)   \t&&\t(TciE == 1) \t&& \t(Tci > -127.0) \t&& \t(Tci < cT_cold_min) \t&& \t(coldside_circle_state  == 0)\t) {\n\t\t\t\t//PrintSS(F(\"CWP ON by ColdMin\"));\n\t\t\t\tlastStartMsgTxt = F(\"CWP_ON_CoMin\");\n\t\t\t\tfl_printSS_lastStartMsgTxt = 1;\n\t\t\t\tmillis_last_coldWP_off = millis_now;\n\t\t\t\tcoldside_circle_state  = 1;\n\t\t\t}\n\t\t\t\n\t\t\tif (  \t(heatpump_state == 0)   \t&&  \t(coldside_circle_state  == 1)\t)\t{\t//is on\n\t\t\t\tif ( (TciE == 1 \t&& Tci > cT_cold_min)  \t\t||\t(TciE^1))\t{ \t//does not overfrozen\n\t\t\t\t\t//next: deal with unstable env. to prevent false starts (water tank with dynamic flows, maybe air heating): stop CWP while waiting period if false start\n\t\t\t\t\t//stop if T>S OR if not needed by prepare\n\t\t\t\t\t#ifdef SETPOINT_THI\n\t\t\t\t\tif (    ( Thi > T_setpoint )  || ((unsigned long)(millis_now - millis_last_coldWP_off) > (COLDCIRCLE_PREPARE*2)) \t) {\n\t\t\t\t\t#endif\n\t\t\t\t\t#ifdef SETPOINT_TS1\n\t\t\t\t\tif (\t( Ts1 > T_setpoint )  || ((unsigned long)(millis_now - millis_last_coldWP_off) > (COLDCIRCLE_PREPARE*2))\t) {\n\t\t\t\t\t#endif\n\t\t\t\t\t\t//PrintSS(F(\"CWP_OFF\"));\n\t\t\t\t\t\tcoldside_circle_state  = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t//protective_cycle:\n\t\t\t//stop if\n\t\t\t//      (error)\n\t\t\t//      (t hot out > hot max)\n\t\t\t//      (t hot in  > hot max)\n\t\t\t//      (crc t > max'C)\n\t\t\t//      or (t after evaporator < after evaporator min)\n\t\t\t//      or (t cold in < cold min)\n\t\t\t//      or (t cold out < cold min)\n\t\t\t//      \n\t\t\tif (  heatpump_state == 1   &&  errorcode == ERR_OK ){\n\t\t\t\tif (ThoE \t== 1 \t&&\tTho \t> cT_hot_max)\t\t\t{heatpump_state = 0; \tlastStopCauseTxt = F(\"P.Tho\");\t\t}\n\t\t\t\tif (ThiE \t== 1 \t&&\tThi \t> cT_hot_max)\t\t\t{heatpump_state = 0; \tlastStopCauseTxt = F(\"P.Thi\");\t\t}\n\t\t\t\tif (TcrcE \t== 1 \t&&\tTcrc\t> cT_crc_max)   \t\t{heatpump_state = 0; \tlastStopCauseTxt = F(\"P.Tcrc\"); \t}\n\t\t\t\tif (TaeE \t== 1 \t&& \tTae \t< cT_coldref_min)\t\t{heatpump_state = 0; \tlastStopCauseTxt = F(\"P.Tae\"); \t\t}\n\t\t\t\tif (TbeE \t== 1 \t&& \tTbe \t< cT_before_evap_work_min) \t{heatpump_state = 0; \tlastStopCauseTxt = F(\"P.Tbe\");\t\t}\n\t\t\t\t//if (TsucE \t== 1 \t&& \tTsuc \t< cT_coldref_min)\t\t{heatpump_state = 0; \tlastStopCauseTxt = F(\"P.Tsuc\");\t\t}\n\t\t\t\tif (TbcE \t== 1 \t&& \tTbc \t> cT_before_condenser_max)\t{heatpump_state = 0; \tlastStopCauseTxt = F(\"P.Tbc\");\t\t}\n\t\t\t\tif (TciE \t== 1 \t&& \tTci \t< cT_cold_min)       \t\t{heatpump_state = 0; \tlastStopCauseTxt = F(\"P.Tci\");\t\t}\n\t\t\t\tif (TcoE \t== 1 \t&& \tTco \t< cT_cold_min)\t\t\t{heatpump_state = 0; \tlastStopCauseTxt = F(\"P.Tco\");\t\t}\n\t\t\t\tif (heatpump_state == 0){\n\t\t\t\t\tLSCint = LSCint_protective;\n\t\t\t\t\tfl_printSS_lastStopCauseTxt = 1;\n\t\t\t\t\t//PrintSS(lastStopCauseTxt);\n\t\t\t\t\tmillis_last_heatpump_on = millis_now;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t//5 minutes workout checks\n\t\t\t//alive_check_cycle_after_5_mins:\n\t\t\t//(old)error if\n\t\t\t//(new)not error, just poweroff all\n\t\t\t//next disabled: issues after a deep freeze, long time needed for stabilisation\n\t\t\t//DISABLED//      or (t cold in - t cold out < t workingok min diff) \n\t\t\t//DISABLED//      or (t hot out - t hot in < t workingok min diff)\n\t\t\t//      or (crc t < 25'C)\n\t\t\t//      or wattage too low\n\t\t\t\n\t\t\tif (  heatpump_state == 1   &&  ((unsigned long)(millis_now - millis_last_heatpump_off) > 300000)  ) {\n\t\t\t\t//cold side processing simetimes works incorrectly, after long period of inactivity, due to T inertia on cold tube sensor, commented out\n\t\t\t\t//if ( ( errorcode == ERR_OK )     &&   (  tr_cold_in - tr_cold_out < cT_workingOK_cold_delta_min ) ) {\n\t\t\t\t//    errorcode = ERR_COLD_PUMP;\n\t\t\t\t//}\n\t\t\t\t//if ( ( errorcode == ERR_OK )     &&   (  Tho.e == 1 && Thi.e == 1 && (Tho.T - Thi.T < cT_workingOK_hot_delta_min )) ) {\n\t\t\t\t//\terrorcode = ERR_HOT_PUMP;\n\t\t\t\t//}\n\t\t\t\tif ( ( errorcode == ERR_OK )     &&   (  TcrcE == 1 && Tcrc < cT_workingOK_crc_min )  ) {\n\t\t\t\t\t//errorcode = ERR_HEATPUMP;\n\t\t\t\t\tmillis_last_heatpump_on = millis_now;\n\t\t\t\t\theatpump_state = 0;\n\t\t\t\t\tLSCint = LSCint_protective;\n\t\t\t\t\tlastStopCauseTxt = F(\"P.W.TcrcMIN\");\n\t\t\t\t\tfl_printSS_lastStopCauseTxt = 1;\n\t\t\t\t\t//PrintSS(lastStopCauseTxt);\n\t\t\t\t}\n\t\t\t\tif ( ( errorcode == ERR_OK )     &&   ( async_wattage < c_workingOK_wattage_min )  ) {\n\t\t\t\t\t//errorcode = ERR_WATTAGE;\n\t\t\t\t\tmillis_last_heatpump_on = millis_now;\n\t\t\t\t\theatpump_state = 0;\n\t\t\t\t\tLSCint = LSCint_protective;\n\t\t\t\t\tlastStopCauseTxt = F(\"P.W.wattMIN\");\n\t\t\t\t\tfl_printSS_lastStopCauseTxt = 1;\n\t\t\t\t\t//PrintSS(lastStopCauseTxt);\n\t\t\t\t}\n\t\t\t\t//digitalWrite(RELAY_HEATPUMP, heatpump_state);\t////!!! old, now halifised\n\t\t\t}\n\n\t\t\t\t\n\t\t\t//disable pump by t.sensor error, sequentially\n\t\t\tif ( heatpump_state == 1   &&  errorcode == ERR_T_SENSOR ) {\n\t\t\t\tsequential_errors += 1;\n\t\t\t\tif (sequential_errors > MAX_SEQUENTIAL_ERRORS) {\n\t\t\t\t\tmillis_last_heatpump_on = millis_now;\n\t\t\t\t\theatpump_state = 0;\n\t\t\t\t\tLSCint = LSCint_error;\n\t\t\t\t\tlastStopCauseTxt = t_sensorErrString;\n\t\t\t\t\tfl_printSS_lastStopCauseTxt = 1;\n\t\t\t\t}\n\t\t\t\t//PrintSS(t_sensorErrString);\n\t\t\t}\n\t\t\t\n\t\t\tif ( errorcode == ERR_OK ) {\t//auto-clean counter just in case\n\t\t\t\tsequential_errors = 0;\n\t\t\t}\n\t\t\t\n\t\t\t//disable pump by pressure error, immediately\n\t\t\tif ( heatpump_state == 1   &&  ( errorcode == ERR_P_HI || errorcode == ERR_P_LO ) ) {\n\t\t\t\tmillis_last_heatpump_on = millis_now;\n\t\t\t\theatpump_state = 0;\n\t\t\t\tif (errorcode == ERR_P_HI) {\n\t\t\t\t\tlastStopCauseTxt = F(\"E.PressHot\");\t\t\t\t\n\t\t\t\t} else if (errorcode == ERR_P_LO) {\n\t\t\t\t\tlastStopCauseTxt = F(\"E.PressCold\");\n\t\t\t\t}\n\t\t\t\tLSCint = LSCint_error;\n\t\t\t\tfl_printSS_lastStopCauseTxt = 1;\n\t\t\t\t//PrintSS(lastStopCauseTxt);\n\t\t\t}\n\n\t\t\t//!!! self-test\n\t\t\t///heatpump_state = 1;\n\t\t\t\n\t\t\thalifise();\n\t\t\t\n\t\t\tif (errorcode == ERR_T_SENSOR) {\n\t\t\t\tPrintSS(t_sensorErrString);\n\t\t\t}\n\t\t\t\n\t\t\tif (fl_printSS_lastStartMsgTxt == 1){\n\t\t\t\tPrintSS(lastStartMsgTxt);\n\t\t\t\tfl_printSS_lastStartMsgTxt = 0;\n\t\t\t}\n\t\t\t\n\t\t\tif (fl_printSS_lastStopCauseTxt == 1){\n\t\t\t\tPrintSS(lastStopCauseTxt);\n\t\t\t\tfl_printSS_lastStopCauseTxt = 0;\n\t\t\t}\n\t\t#endif\n\t\t\n\t\t//process errors\n\t\t//beep N times error\n\t\tif ( errorcode != ERR_OK ) {\n\t\t\tLED_OK_state\t\t= 0;\n\t\t\tLED_ERR_state\t\t= 1;\n\t\t\tif (  ((unsigned long)(millis_now - millis_notification) > millis_notification_interval)  ||  millis_notification == 0 ) {\n\t\t\t\tmillis_notification = millis_now;\n\t\t\t\toutString = F(\"Err: \");\n\t\t\t\tPrintSS_SaI(errorcode);\n\t\t\t\tfor ( i = 0; i < errorcode; i++) {\n\t\t\t\t\tLED_ERR_state\t\t= 0;\n\t\t\t\t\thalifise();\n\t\t\t\t\tanalogWrite(speakerOut, 10);  \tdelay (500);      \n\t\t\t\t\tLED_ERR_state\t\t= 1;\n\t\t\t\t\thalifise();\n\t\t\t\t\tanalogWrite(speakerOut, 0);\tdelay (500);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tLED_OK_state\t\t= 1;\n\t\t\tLED_ERR_state\t\t= 0;\n\t\t\thalifise();\n\t\t}\n\t}\n\t\n\tif (Serial.available() > 0) {\n\t\tinChar = Serial.read();\n\t\tif ( inChar == 0x1B ) {\n\t\t\tskipchars_local += 3;\n\t\t\tinChar = 0x00;\n\t\t\tmillis_escinput_local = millis();\n\t\t}\n\t\tif ( skipchars_local != 0 ) {\n\t\t\tmillis_charinput_local = millis();\n\t\t\tif ((unsigned long)(millis_charinput_local - millis_escinput_local) < 16*2 ) {\t//2 chars for 2400\n\t\t\t\tif (inChar != 0x7e) {\n\t\t\t\t\tskipchars_local -= 1;\n\t\t\t\t}\n\t\t\t\tif (inChar == 0x7e) {\n\t\t\t\t\tskipchars_local = 0;\n\t\t\t\t}\n\t\t\t\tif (inChar >= 0x30 && inChar <= 0x35) {\n\t\t\t\t\tskipchars_local += 1;\n\t\t\t\t}\n\t\t\t\tinChar = 0x00;\n\t\t\t} else {\n\t\t\t\tskipchars_local = 0;\n\t\t\t}\n\t\t}\n\t\t_ProcessInChar();\n\t}\n\t\n\tif (RS485Serial.available() > 0) {\n\t\t//PrintSS(\"some on 485..\");\t//!!!debug\n\t\t#ifdef RS485_HUMAN\n\t\t\tif (RS485Serial.available()) {\n\t\t\t\tinChar = RS485Serial.read();\n\t\t\t\t//RS485Serial.print(inChar);\t//!!!debug\n\t\t\t\tif ( inChar == 0x1B ) {\n\t\t\t\t\tskipchars_485 += 3;\n\t\t\t\t\tinChar = 0x00;\n\t\t\t\t\tmillis_escinput_485 = millis();\n\t\t\t\t}\n\t\t\t\tif ( skipchars_485 != 0 ) {\n\t\t\t\t\tmillis_charinput_485 = millis();\n\t\t\t\t\t//if (millis_escinput_485 + 2 > millis_charinput_485)\n\t\t\t\t\tif ((unsigned long)(millis_charinput_485 - millis_escinput_485) < 16*2 ) {\t//2 chars for 2400\n\t\t\t\t\t\tif (inChar != 0x7e) {\n\t\t\t\t\t\t\tskipchars_485 -= 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (inChar == 0x7e) {\n\t\t\t\t\t\t\tskipchars_485 = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (inChar >= 0x30 && inChar <= 0x35) {\n\t\t\t\t\t\t\tskipchars_485 += 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tinChar = 0x00;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tskipchars_485 = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t_ProcessInChar();\n\t\t\t}\n\t\t#endif\n        \n\t\t#ifdef RS485_JSON\n\t\t\tindex = 0;\n\t\t\twhile (RS485Serial.available() > 0) { // Don't read unless you know there is data\n\t\t\t\tif(index < 49) {   //  size of the array minus 1\n\t\t\t\t\tinChar = RS485Serial.read(); \t// Read a character\n\t\t\t\t\tdataBuf[index] = inChar;      \t// Store it\n\t\t\t\t\tindex++;                     \t// Increment where to write next\n\t\t\t\t\tdataBuf[index] = '\\0';        \t// clear next symbol, null terminate the string\n\t\t\t\t\tdelayMicroseconds(80);       \t//80 microseconds - the best choice at 9600, \"no answer\"disappeared\n\t\t\t\t\t\t\t\t\t//40(20??) microseconds seems to be good, 9600, 49 symbols\n\t\t\t\t\t\t\t\t\t//\n\t\t\t\t} else {            //too long message! read it to nowhere\n\t\t\t\t\tinChar = RS485Serial.read();\n\t\t\t\t\tdelayMicroseconds(80);\n\t\t\t\t\t//break;    //do not break if symbols!!\n\t\t\t\t}\n\t\t\t}\n\t\t\n\t\t\t//!!!debug, be carefull, can cause strange results\n\t\t\t/*\n\t\t\tif (dataBuf[0] != 0x00) {\n\t\t\tPrintSS(\"-\");\n\t\t\tPrintSS(dataBuf);\n\t\t\tPrintSS(\"-\");\n\t\t\t}\n\t\t\t*/\n\t\t\t//or this debug\n\t\t\t/*\n\t\t\tdigitalWrite(SerialTxControl, RS485Transmit);\n\t\t\thalifise();\n\t\t\tdelay(10);\n\t\t\tRS485Serial.println(dataBuf);\n\t\t\tRS485Serial.flush();\n\t\t\tRS485Serial.println(index);\n\t\t\t*/\n\t\t\t\n\t\t\t//ALL lines must be terminated with \\n!\n\t\t\tif ( (dataBuf[0] == hostID) && (dataBuf[1] == devID) ) {             \n\t\t\t\t//  COMMANDS:\n\t\t\t\t// G (0x47): (G)et main data\n\t\t\t\t// TNN.NN (0x54): set aim (T)emperature\n\t\t\t\t// ENN.NN (0x45): set (E)EV difference aim\n\t\t\t\tdigitalWrite(SerialTxControl, RS485Transmit);\n\t\t\t\thalifise();\n\t\t\t\tdelay(1);\n\t\t\t\t//PrintSS(freeMemory());\n\t\t\t\toutString = \"\";\n\t\t\t\toutString = devID;\n\t\t\t\toutString += hostID;\n\t\t\t\toutString +=  \"A \";  //where A is Answer, space after header\n\t\t\t\tchar *outChar=&outString[0];\n\t\t\t\tif ( (dataBuf[2] == 0x47 ) ) {\n\t\t\t\t\t//PrintSS(\"G\");\n\t\t\t\t\t//WARNING: this procedure can cause \"NO answer\" effect if no or few T sensors connected\n\t\t\t\t\t\n\t\t\t\t\t//outString = \"\";\n\t\t\t\t\t//if (TsgE)\t{\toutString += \",\\\"TSG\\\":\" + String(Tsg);\t}\n\t\t\t\t\t//if (TslE)\t{\toutString += \",\\\"TSL\\\":\" + String(Tsl);\t}\n\t\t\t\t\t//if (TbvE)\t{\toutString += \",\\\"TBV\\\":\" + String(Tbv);\t}\n\t\t\t\t\t//if (TsucE)\t{\toutString += \",\\\"TSUC\\\":\" + String(Tsuc);}\n\t\t\t\t\t//RS485Serial.write(outChar);                    \t//dirty hack to transfer long string\n\t\t\t\t\t//RS485Serial.flush();\n\t\t\t\t\t//delay (1);                                      //lot of errors without delay\n\t\t\t\t\toutString += \"{\";\n\t\t\t\t\toutString += \"\\\"E1\\\":\" + String(errorcode);  \n\t\t\t\t\tif (TciE)\t{ \toutString += \",\\\"TCI\\\":\"; \tApToOut_D(Tci);\t}\n\t\t\t\t\tif (TcoE)\t{\toutString += \",\\\"TCO\\\":\"; \tApToOut_D(Tco);\t}\n\t\t\t\t\tif (TbeE)\t{\toutString += \",\\\"TBE\\\":\"; \tApToOut_D(Tbe);\t}\n\t\t\t\t\tif (TaeE)\t{\toutString += \",\\\"TAE\\\":\"; \tApToOut_D(Tae);\t}\n\t\t\t\t\tif (Ts1E)\t{\toutString += \",\\\"TS1\\\":\"; \tApToOut_D(Ts1);\t}\n\t\t\t\t\tif (Ts2E)\t{\toutString += \",\\\"TS2\\\":\"; \tApToOut_D(Ts2);\t}\n\t\t\t\t\tif (TcrcE)\t{\toutString += \",\\\"TCRC\\\":\"; \tApToOut_D(Tcrc);}\n\t\t\t\t\tif (TregE)\t{\toutString += \",\\\"TR\\\":\"; \tApToOut_D(Treg);}\n\t\t\t\t\tRS485Serial.write(outChar);                    \t//dirty hack to transfer long string\n\t\t\t\t\tRS485Serial.flush();\n\t\t\t\t\tdelay (1);                                      //lot of errors without delay\n\t\t\t\t\t\n\t\t\t\t\toutString = \"\";\n\t\t\t\t\tif (TacE)\t{\toutString += \",\\\"TAC\\\":\"; \tApToOut_D(Tac);\t}\n\t\t\t\t\tif (TbcE)\t{\toutString += \",\\\"TBC\\\":\"; \tApToOut_D(Tbc);\t}\n\t\t\t\t\tif (ThoE)\t{\toutString += \",\\\"THO\\\":\"; \tApToOut_D(Tho);\t}\n\t\t\t\t\tif (ThiE)\t{\toutString += \",\\\"THI\\\":\"; \tApToOut_D(Thi);}\n\t\t\t\t\toutString += \",\\\"W1\\\":\";\tApToOut_D(async_wattage);\n\t\t\t\t\toutString += \",\\\"EEVP\\\":\" \t+ String(EEV_cur_pos);\n\t\t\t\t\toutString += \",\\\"EEVA\\\":\"; \tApToOut_D(T_EEV_setpoint);\n\t\t\t\t\t\n\t\t\t\t\t#ifndef EEV_ONLY\n\t\t\t\t\t\toutString += \",\\\"A1\\\":\"; \tApToOut_D(T_setpoint);  //(A)im (target)\n\t\t\t\t\t\toutString += \",\\\"RP\\\":\" \t+ String(heatpump_state*RELAY_HEATPUMP);  \n\t\t\t\t\t\toutString += \",\\\"RH\\\":\" \t+ String(hotside_circle_state*RELAY_HOTSIDE_CIRCLE);                  \n\t\t\t\t\t\toutString += \",\\\"RC\\\":\" \t+ String(coldside_circle_state*1);  \n\t\t\t\t\t\toutString += \",\\\"RCRCH\\\":\" \t+ String(crc_heater_state*3);                 \n\t\t\t\t\t\t//if (TregE)\t{\toutString += \",\\\"RRH\\\":\" + String(reg_heater_state*4);}                 \n\t\t\t\t\t\t//RS485Serial.write(outChar);                    \t//dirty hack to transfer long string\n\t\t\t\t\t\t//RS485Serial.flush();\n\t\t\t\t\t\t//delay (1);                                      //lot of errors without delay\n\t\t\t\t\t#endif\n\t\t\t\t\tRS485Serial.write(outChar);                    \t//dirty hack to transfer long string\n\t\t\t\t\tRS485Serial.flush();\n\t\t\t\t\tdelay (1);                                      //lot of errors without delay\n\t\t\t\t\t\n\t\t\t\t\toutString = \"\";\n\t\t\t\t\toutString = \",\\\"LSC\\\":\\\"\";\n\t\t\t\t\toutString += lastStopCauseTxt;\n\t\t\t\t\toutString += (\"\\\"\");\n\t\t\t\t\t//RS485Serial.write(outChar);                    \t//dirty hack to transfer long string\n\t\t\t\t\t//RS485Serial.flush();\n\t\t\t\t\t//delay (1);                                      //lot of errors without delay\n\t\t\t\t\toutString += \",\\\"LSM\\\":\\\"\";\n\t\t\t\t\toutString += lastStartMsgTxt;\n\t\t\t\t\toutString += (\"\\\"\");\n\t\t\t\t\toutString += \"}\";\n\t\t\t\t\t\n\t\t\t\t} else if ( (dataBuf[2] == 0x54 ) || (dataBuf[2] == 0x45 )) {  //(T)arget or (E)EV target format NN.NN, text\n\t\t\t\t\tif ( isDigit(dataBuf[ 3 ]) && isDigit(dataBuf[ 4 ]) && (dataBuf[ 5 ] == 0x2e)  && isDigit(dataBuf[ 6 ]) && isDigit(dataBuf[ 7 ]) && ( ! isDigit(dataBuf[ 8 ])) ) {\n\t\t\t\t\t\t\n\t\t\t\t\t\tanalogWrite(speakerOut, 10);\n\t\t\t\t\t\tdelay (100); \n\t\t\t\t\t\tanalogWrite(speakerOut, 0);\n\t\t\t\t\t\t\n\t\t\t\t\t\tchar * carray = &dataBuf[ 3 ];\n\t\t\t\t\t\ttempdouble = atof(carray);                \n\t\t\t\t\t\tif (dataBuf[2] == 0x54 ){\n\t\t\t\t\t\t\tif (tempdouble > cT_setpoint_max) {\n\t\t\t\t\t\t\t\toutString += \"{\\\"r\\\":\\\"too hot!\\\"}\";\n\t\t\t\t\t\t\t} else if (tempdouble < cT_setpoint_min) {\n\t\t\t\t\t\t\t\toutString += \"{\\\"r\\\":\\\"too cold!\\\"}\";\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tT_setpoint = tempdouble;\n\t\t\t\t\t\t\t\t_HotWPon_by_Setpoint_update();\n\t\t\t\t\t\t\t\toutString += \"{\\\"r\\\":\\\"ok, new value: \"; \n\t\t\t\t\t\t\t\tApToOut_D(T_setpoint);\n\t\t\t\t\t\t\t\toutString += \"\\\"}\";\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (dataBuf[2] == 0x45 ) {\n\t\t\t\t\t\t\tif (tempdouble > 10.0) {\t\t//!!!!!!! hardcode !!!\n\t\t\t\t\t\t\t\toutString += \"{\\\"r\\\":\\\"too hot!\\\"}\";\n\t\t\t\t\t\t\t} else if (tempdouble < 0.1) {\t\t//!!!!!!! hardcode !!!\n\t\t\t\t\t\t\t\toutString += \"{\\\"r\\\":\\\"too cold!\\\"}\";\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tT_EEV_setpoint = tempdouble;\n\t\t\t\t\t\t\t\toutString += \"{\\\"r\\\":\\\"ok, new EEV value: \";\n\t\t\t\t\t\t\t\tApToOut_D(T_EEV_setpoint);\n\t\t\t\t\t\t\t\toutString += \"\\\"}\";\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\toutString += \"{\\\"r\\\":\\\"NaN, format: NN.NN\\\"}\";\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t//default, just for example\n\t\t\t\t\toutString += \"{\\\"r\\\":\\\"no_command\\\"}\";\n\t\t\t\t}\n\t\t\t\t//crc.integer = CRC16.xmodem((uint8_t& *) outString, outString.length());\n\t\t\t\t//outString += (crc, HEX);\n\t\t\t\toutString += \"\\n\";\n\t\t\t\tRS485Serial.write(outChar);\n\t\t\t}\n\t\t\t\n\t\t\tindex = 0;\n\t\t\tfor (i=0;i < (BUFSIZE);i++) {  //clear buffer\n\t\t\t\tdataBuf[i]=0;\n\t\t\t}\n\t\t\tRS485Serial.flush();\n\t\t\tdigitalWrite(SerialTxControl, RS485Receive);\n\t\t\tdelay(1);\n\t\t#endif\n\t\t\n\t\t#ifdef RS485_MODBUS\n\t\t\tindex = 0;\n\t\t\tz = 0;  //error flag\n\t\t\twhile ( 1 == 1 ) {//9600\n\t\t\t\t//read\n\t\t\t\t//!!!!!!!\n\t\t\t\t//Serial.println(\"-\");\n\t\t\t\tif (RS485Serial.available()) {\n\t\t\t\t\tif(index < BUFSIZE) {\n\t\t\t\t\t\tinChar = RS485Serial.read();\t \n\t\t\t\t\t\t//Serial.print(inChar, HEX);\n\t\t\t\t\t\t//Serial.print(\" \");\n\t\t\t\t\t\tdataBuf[index] = inChar;      \t\n\t\t\t\t\t\tindex++;                   \t\n\t\t\t\t\t\tdataBuf[index] = '\\0';        \t\n\t\t\t\t\t\tdelayMicroseconds(80);       \t//yep, 80, HERE\n\t\t\t\t\t} else {\n\t\t\t\t\t\tz = 1;\n\t\t\t\t\t\twhile (RS485Serial.available()) {\n\t\t\t\t\t\t\tinChar = RS485Serial.read();\n\t\t\t\t\t\t\tdelayMicroseconds(1800);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t//Serial.print(\".\");\n\t\t\t\t\ttmic1 = micros();\n\t\t\t\t\tfor (i = 0; i < 10; i++) {    \n\t\t\t\t\t\tdelayMicroseconds(180);\n\t\t\t\t\t\tif (RS485Serial.available()){\n\t\t\t\t\t\t\t//Serial.print(\"babaika\");\n\t\t\t\t\t\t\t//Serial.println(i);\n\t\t\t\t\t\t\ttmic2 = micros();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttmic2 = micros();\n\t\t\t\t\t\tif ( (unsigned long)(tmic2 - tmic1) > 1800 ){\n\t\t\t\t\t\t\ti = 10;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (i == 10 && RS485Serial.available()) {\n\t\t\t\t\t\tz = 2;\n\t\t\t\t\t\ti = 0;\n\t\t\t\t\t\twhile (RS485Serial.available()) {\n\t\t\t\t\t\t\tif (i > 200){ \n\t\t\t\t\t\t\t\tbreak; \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tinChar = RS485Serial.read();\n\t\t\t\t\t\t\tdelayMicroseconds(1800);\n\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else if (!RS485Serial.available()) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else if (RS485Serial.available()) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t//PrintSS(F(\"e2245\"));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t//check CRC\n\t\t\tif (index < 3) { \n\t\t\t\tz+= 10;\n\t\t\t}\n\t\t\tif ( dataBuf[1] == 0x03 && ( (index % 8 ) == 0) && index > 8 ) { //automatic \"duplicated message\" detector, can be found if lot of T sensors absent and requests are too fast\n\t\t\t\tindex = 8;\n\t\t\t}\n\t\t\t\t\n\t\t\tcrc16 = SEED;\n\t\t\tfor (x = 0; x < (index-2); x++) {   \n\t\t\t\tCalc_CRC(dataBuf[x]); \n\t\t\t}\n\t\t\tx = dataBuf[index - 2];\n\t\t\ty = dataBuf[index - 1];\n\t\t\tif (( x !=  (crc16 & 0xFF )) || ( y != (crc16 >> 8))) {\n\t\t\t\tz += 100;\n\t\t\t}\n\t\t\t//PrintSS(F(\"-----\"));\n\t\t\tif ( z != 0 ) {\n\t\t\t\t//probably another proto\n\t\t\t\t//PrintSS(F(\"MmsgERR: \"));\n\t\t\t\t/*Serial.println(z);\n\t\t\t\tfor (x =0; x<index; x++){\n\t\t\t\t\tSerial.print(dataBuf[x], HEX);\n\t\t\t\t\tSerial.print(\" \");\n\t\t\t\t}\n\t\t\t\tSerial.println();*/\n\t\t\t}  else {\t\t\n\t\t\t\t/*PrintSS(F(\"ModbusMSG: \"));\n\t\t\t\tSerial.println(z);\n\t\t\t\tfor (x =0; x<index; x++){\n\t\t\t\t\tSerial.print(dataBuf[x], HEX);\n\t\t\t\t\tSerial.print(\" \");\n\t\t\t\t}\n\t\t\t\tSerial.println();*/\n\t\t\t\t\n\t\t\t\tdigitalWrite(SerialTxControl, RS485Transmit);\n\t\t\t\thalifise();\n\t\t\t\tz = 0;\n\t\t\t\tif (dataBuf[0] != 0x00 && dataBuf[0] != devID ) {\t//will reply to 0x00\n\t\t\t\t\tz = 0xFF;\n\t\t\t\t}\n\t\t\t\tif (dataBuf[1] != 0x03 && dataBuf[1] != 0x06) { //0x01\n\t\t\t\t\tz = 1;\n\t\t\t\t}\n\t\t\t\tif (dataBuf[1] == 0x03 && dataBuf[2] != 0x00 && dataBuf[4] != 0x00) { //0x02\n\t\t\t\t\tz = 2;\n\t\t\t\t}\n\t\t\t\tif (dataBuf[1] == 0x06 && dataBuf[2] != 0x00) { \t//0x02\n\t\t\t\t\tz = 2;\n\t\t\t\t}\n\t\t\t\tif (dataBuf[1] == 0x06 && dataBuf[3] > MODBUS_MR)  {\t//0x03\n\t\t\t\t\tz = 3;\n\t\t\t\t}\n\t\t\t\tif (dataBuf[1] == 0x03 && dataBuf[5] > MODBUS_MR)  {\t//0x05 \n\t\t\t\t\tz = 5;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\ti = 0;\n\t\t\t\t//dataBuf[i]  =  devID;\n\t\t\t\t//unchanged! can be devID or 0x00\n\t\t\t\ti++;\n\t\t\t\tif (z == 0) {\n\t\t\t\t\t//PrintSS(F(\"ModParse\"));\n\t\t\t\t\tx = dataBuf[3]; \t//addr\t\n\t\t\t\t\ty = dataBuf[5];\t\t//num\n\t\t\t\t\tif (dataBuf[1]  ==  0x03) {\n\t\t\t\t\t\t//PrintSS(F(\"F03\"));\n\t\t\t\t\t\tdataBuf[i]  = 0x03;\n\t\t\t\t\t\ti++;\t\n\t\t\t\t\t\t//the most significant byte is sent first\n\t\t\t\t\t\tdataBuf[i]  =  y*2;\n\t\t\t\t\t\ti++;  // data\n\t\t\t\t\t\tfor (u = x; u < (x+y); u++) {\n\t\t\t\t\t\t\tif (u > MODBUS_MR){\n\t\t\t\t\t\t\t\tz = 2;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tswitch (u) {\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tcase 0x00:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(Tci); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x01:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(Tco); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x02:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(Tbe); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x03:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(Tae); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x04:\n\t\t\t\t\t\t\t\t\t//Add_Double_To_Buf_IntFract(Tsg); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = 0;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = 0;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x05:\n\t\t\t\t\t\t\t\t\t//Add_Double_To_Buf_IntFract(Tsl); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = 0;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = 0;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x06:\n\t\t\t\t\t\t\t\t\t//Add_Double_To_Buf_IntFract(Tbv); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = 0;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = 0;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x07:\n\t\t\t\t\t\t\t\t\t//Add_Double_To_Buf_IntFract(Tsuc); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = 0;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = 0;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x08:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(Ts1); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x09:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(Ts2); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x0A:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(Tcrc); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x0B:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(Treg); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x0C:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(Tac); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x0D:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(Tbc); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x0E:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(Tho); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x0F:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(Thi); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x10:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = 0;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = errorcode;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x11:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = (int)async_wattage >> 8;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = (int)async_wattage & 0xFF;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x12:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = 0;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = 0;\n\t\t\t\t\t\t\t\t\tbitWrite(dataBuf[i], 0, heatpump_state);\n\t\t\t\t\t\t\t\t\tbitWrite(dataBuf[i], 1, hotside_circle_state);\n\t\t\t\t\t\t\t\t\tbitWrite(dataBuf[i], 2, coldside_circle_state);\n\t\t\t\t\t\t\t\t\tbitWrite(dataBuf[i], 3, crc_heater_state);\n\t\t\t\t\t\t\t\t\t//bitWrite(dataBuf[i], 4, reg_heater_state);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x13:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(T_EEV_setpoint); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x14:\n\t\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(T_setpoint); //uses dataBuf, i\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x15:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = (int)EEV_cur_pos >> 8;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = (int)EEV_cur_pos & 0xFF;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x16:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStopCauseTxt.charAt(0);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStopCauseTxt.charAt(1);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x17:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStopCauseTxt.charAt(2);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStopCauseTxt.charAt(3);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x18:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStopCauseTxt.charAt(4);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStopCauseTxt.charAt(5);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x19:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStopCauseTxt.charAt(6);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStopCauseTxt.charAt(7);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x1A:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStopCauseTxt.charAt(8);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStopCauseTxt.charAt(9);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x1B:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStopCauseTxt.charAt(10);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStopCauseTxt.charAt(11);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x1C:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStartMsgTxt.charAt(0);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStartMsgTxt.charAt(1);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x1D:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStartMsgTxt.charAt(2);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStartMsgTxt.charAt(3);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x1E:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStartMsgTxt.charAt(4);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStartMsgTxt.charAt(5);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x1F:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStartMsgTxt.charAt(6);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStartMsgTxt.charAt(7);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x20:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStartMsgTxt.charAt(8);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStartMsgTxt.charAt(9);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 0x21:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStartMsgTxt.charAt(10);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = lastStartMsgTxt.charAt(11);\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = 0x00;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tdataBuf[i]  = 0x00;\n\t\t\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (dataBuf[1]  ==  0x06) {\t//de-facto echo\n\t\t\t\t\t\t//PrintSS(F(\"F06\"));\n\t\t\t\t\t\tdataBuf[i]  = 0x06;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\tdataBuf[i]  = 0x00;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\tdataBuf[i]  = x;\n\t\t\t\t\t\ti++;\n\n\t\t\t\t\t\tswitch (x) {\n\t\t\t\t\t\t\tcase 0x13:\n\t\t\t\t\t\t\t\t//PrintSS(F(\"06F_EEV_setpoint\"));\n\t\t\t\t\t\t\t\tIntFract_to_tempdouble(dataBuf[4], dataBuf[5]);\n\t\t\t\t\t\t\t\t//Serial.println(tempdouble);\n\t\t\t\t\t\t\t\tif (tempdouble > 15.0 || tempdouble < -15.0) {\t\t//incorrectest values filter\n\t\t\t\t\t\t\t\t\tz = 3;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tT_EEV_setpoint = tempdouble;\n\t\t\t\t\t\t\t\t//Serial.println(T_EEV_setpoint);\n\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(T_EEV_setpoint); //uses dataBuf, i\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase 0x14:\n\t\t\t\t\t\t\t\t//PrintSS(F(\"06F_T_setpoint\"));\n\t\t\t\t\t\t\t\tIntFract_to_tempdouble(dataBuf[4], dataBuf[5]);\n\t\t\t\t\t\t\t\t//Serial.println(tempdouble);\n\t\t\t\t\t\t\t\tif (tempdouble > cT_setpoint_max || tempdouble < cT_setpoint_min) {\t//incorrectest values filter\n\t\t\t\t\t\t\t\t\tz = 3;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tT_setpoint = tempdouble;\n\t\t\t\t\t\t\t\t_HotWPon_by_Setpoint_update();\n\t\t\t\t\t\t\t\t//Serial.println(T_setpoint);\n\t\t\t\t\t\t\t\tAdd_Double_To_Buf_IntFract(T_setpoint); //uses dataBuf, i\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t//case 0x15:\n\t\t\t\t\t\t\t//\t//EEV_cur_pos\n\t\t\t\t\t\t\t//\tbreak;\n\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\tz = 3;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tPrintSSch(IDX_UNKNF);\n\t\t\t\t\t\tz = 1;\n\t\t\t\t\t}\n\t\t\t\t\tif (z != 0) {\n\t\t\t\t\t\ti = 1;\n\t\t\t\t\t\tbitWrite(dataBuf[i], 7, 1);\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\tdataBuf[i] = z;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tcrc16 = SEED;\n\t\t\t\t\tfor (x = 0; x < (i); x++) {   \n\t\t\t\t\t\tCalc_CRC(dataBuf[x]); \n\t\t\t\t\t}\n\t\t\t\t\tdataBuf[i] = crc16 & 0xFF;\n\t\t\t\t\ti++;\n\t\t\t\t\tdataBuf[i] = crc16 >> 8;\n\t\t\t\t\ti++;\n\t\t\t\t\t\n\t\t\t\t\tRS485Serial.write(dataBuf, i);\n\t\t\t\t\tRS485Serial.flush();\t\n\t\t\t\t\tdelay (1);              \n\n\t\t\t\t\t//!!! debug\n\t\t\t\t\t/*\n\t\t\t\t\tfor (x = 0; x<i; x++){\n\t\t\t\t\t\tSerial.print(dataBuf[x], HEX);\n\t\t\t\t\t\tSerial.print(\" \");\n\t\t\t\t\t}\n\t\t\t\t\t*/\n\t\t\t\t\t/*Serial.println(\"ModResp\");\n\t\t\t\t\tfor (z = 0; z < i; z++){\n\t\t\t\t\t\tSerial.print(dataBuf[z], HEX);  \n\t\t\t\t\t\tSerial.print(\" \");  \n\t\t\t\t\t\tif ( z%50 == 0) Serial.println();\n\t\t\t\t\t}\n\t\t\t\t\tSerial.println();*/\n\t\t\t\t\t\n\t\t\t\t\tdigitalWrite(SerialTxControl, RS485Receive);\n\t\t\t\t}\n\t\t\t}\n\t\t#endif\n\t}\n}\n"
  }
]