Example #1
0
 public static function createNew(TIVarType $type = null, $name = '', TIModel $model = null)
 {
     if ($type !== null) {
         $instance = new self();
         $instance->type = $type;
         $instance->calcModel = $model !== null ? $model : TIModel::createFromName('84+');
         // default
         $name = $instance->fixVarName($name);
         if (!$instance->calcModel->supportsType($instance->type)) {
             throw new \RuntimeException('This calculator model (' . $instance->calcModel->getName() . ') does not support the type ' . $instance->type->getName());
         }
         $instance->header = ['signature' => $instance->calcModel->getSig(), 'sig_extra' => [0x1a, 0xa, 0x0], 'comment' => str_pad('Created by tivars_lib on ' . date('M j, Y'), 42, ""), 'entries_len' => 0];
         // Default cases for >= TIFeatureFlags::hasFlash. It's fixed right after if necessary.
         // This is done that way because the field order is important - the ones that change can't simply be added afterwards.
         $instance->varEntry = ['entryMetaLen' => [self::varEntryNewLength, 0x0], 'data_length' => 0, 'typeID' => $type->getId(), 'varname' => str_pad($name, 8, ""), 'version' => 0, 'archivedFlag' => 0, 'data_length2' => 0, 'data' => []];
         // Deal with the hasFlash flag "issue" mentioned above.
         if ($instance->calcModel->getFlags() < TIFeatureFlags::hasFlash) {
             $instance->varEntry['entryMetaLen'] = [self::varEntryOldLength, 0x0];
             unset($instance->varEntry['version']);
             unset($instance->varEntry['archivedFlag']);
         }
         return $instance;
     } else {
         throw new \InvalidArgumentException('No type given');
     }
 }
 public static function createNew(TIVarType $type = null, $name = '', TIModel $model = null)
 {
     if ($type !== null) {
         $instance = new self();
         $instance->type = $type;
         $instance->calcModel = $model !== null ? $model : TIModel::createFromName('84+');
         // default
         $name = $instance->fixVarName($name);
         if (!$instance->calcModel->supportsType($instance->type)) {
             throw new \Exception('This calculator model (' . $instance->calcModel->getName() . ') does not support the type ' . $instance->type->getName());
         }
         $instance->header = ['signature' => $instance->calcModel->getSig(), 'sig_extra' => [0x1a, 0xa, 0x0], 'comment' => str_pad("Created by tivars_lib on " . date("M j, Y"), 42, ""), 'entries_len' => 0];
         $calcFlags = $instance->calcModel->getFlags();
         $instance->varEntry = ['constBytes' => [0xd, 0x0], 'data_length' => 0, 'typeID' => $type->getId(), 'varname' => str_pad($name, 8, ""), 'version' => $calcFlags >= TIFeatureFlags::hasFlash ? 0 : null, 'archivedFlag' => $calcFlags >= TIFeatureFlags::hasFlash ? 0 : null, 'data_length2' => 0, 'data' => []];
         return $instance;
     } else {
         throw new \Exception("No type given");
     }
 }