1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CALIBRATION_FILE_H_ 18 #define CALIBRATION_FILE_H_ 19 20 #include <inttypes.h> 21 #include <unistd.h> 22 23 #include <memory> 24 25 #include "file.h" 26 #include "noncopyable.h" 27 #include "JSONObject.h" 28 #include <utils/RefBase.h> 29 30 namespace android { 31 32 class CalibrationFile : public NonCopyable { 33 public: 34 // Get a pointer to the singleton instance 35 static std::shared_ptr<CalibrationFile> Instance(); 36 37 const sp<JSONObject> GetJSONObject() const; 38 39 bool SetSingleAxis(const char *key, int32_t value); 40 bool SetSingleAxis(const char *key, float value); 41 bool SetTripleAxis(const char *key, int32_t x, int32_t y, int32_t z); 42 bool SetFourAxis(const char *key, int32_t x, int32_t y, int32_t z, 43 int32_t w); 44 45 bool Save(); 46 47 private: CalibrationFile()48 CalibrationFile() : file_(nullptr), json_root_(nullptr) {} 49 50 static std::shared_ptr<CalibrationFile> instance_; 51 bool Initialize(); 52 53 std::unique_ptr<File> file_; 54 sp<JSONObject> json_root_; 55 56 bool Read(); 57 }; 58 59 } // namespace android 60 61 #endif // CALIBRATION_FILE_H_ 62