def Get_PowerMode(self): """Power mode.""" powermode = self.__readFromRegister(self.__REG_RW_CTRL_REG1, self.__MASK_CTRL_REG1_PD | self.__MASK_CTRL_REG1_Xen | self.__MASK_CTRL_REG1_Yen | self.__MASK_CTRL_REG1_Zen) print(bin(powermode)) dictval = 4 if not bitOps.CheckBit(powermode, 3): dictval = 0 elif powermode == 0b1000: dictval = 1 elif bitOps.CheckBit(powermode, 3): dictval = 2 for key in self.__PowerModeDict.keys(): if self.__PowerModeDict[key] == dictval: return key
def test_CheckBit(self): self.assertEqual(bitOps.CheckBit(0x01, 0), True, 'Check lsb') self.assertEqual(bitOps.CheckBit(0x80, 7), True, 'Check msb') self.assertEqual(bitOps.CheckBit(0x00, 1), False, 'Check from empty')