(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@ionic/angular'), require('@iotize/ionic')) :
    typeof define === 'function' && define.amd ? define('@iotize/ionic/gpio', ['exports', '@angular/core', '@angular/common', '@ionic/angular', '@iotize/ionic'], factory) :
    (global = global || self, factory((global.iotize = global.iotize || {}, global.iotize.ionic = global.iotize.ionic || {}, global.iotize.ionic.gpio = {}), global.ng.core, global.ng.common, global.angular, global.iotize.ionic));
}(this, (function (exports, core, common, angular, ionic) { 'use strict';

    /**
     * @fileoverview added by tsickle
     * Generated from: lib/definitions.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    /**
     * @record
     */
    function PowerPin() { }
    if (false) {
        /** @type {?} */
        PowerPin.prototype.type;
        /** @type {?} */
        PowerPin.prototype.power;
    }
    /**
     * @record
     */
    function GPIOPin() { }
    if (false) {
        /** @type {?} */
        GPIOPin.prototype.type;
        /** @type {?} */
        GPIOPin.prototype.num;
    }
    /**
     * @record
     */
    function GroundPin() { }
    if (false) {
        /** @type {?} */
        GroundPin.prototype.type;
    }
    /**
     * @record
     */
    function DisabledPin() { }
    if (false) {
        /** @type {?} */
        DisabledPin.prototype.type;
    }
    /**
     * @record
     */
    function PinEntry() { }
    if (false) {
        /** @type {?} */
        PinEntry.prototype.num;
        /** @type {?} */
        PinEntry.prototype.pin;
    }

    (function (GPIO) {
        var Mode;
        (function (Mode) {
            Mode["IN"] = "IN";
            Mode["OUT"] = "OUT";
        })(Mode = GPIO.Mode || (GPIO.Mode = {}));
        var Signal;
        (function (Signal) {
            Signal["HIGH"] = "HIGH";
            Signal["LOW"] = "LOW";
        })(Signal = GPIO.Signal || (GPIO.Signal = {}));
    })(exports.GPIO || (exports.GPIO = {}));
    /**
     * @record
     */
    function IGPIOController() { }
    if (false) {
        /** @type {?} */
        IGPIOController.prototype.conf;
        /**
         * @return {?}
         */
        IGPIOController.prototype.low = function () { };
        /**
         * @return {?}
         */
        IGPIOController.prototype.high = function () { };
        /**
         * @param {?} direction
         * @param {?} initial
         * @return {?}
         */
        IGPIOController.prototype.setup = function (direction, initial) { };
    }

    /**
     * @fileoverview added by tsickle
     * Generated from: lib/tap-extension.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    /** @enum {number} */
    var GPIO_MODE = {
        INPUT_FLOATING: 0,
        OUTPUT_OPENDRAIN: 1,
        OUTPUT_PUSHPULL: 3,
        INPUT_PULLUP: 4,
        OUTPUT_OPENDRAIN_PULLUP: 5,
        INPUT_PULLDOWN: 8,
        INPUT_ANALOG_FLOATING: 128,
        OUTPUT_ANALOG_PWM: 131,
    };
    GPIO_MODE[GPIO_MODE.INPUT_FLOATING] = 'INPUT_FLOATING';
    GPIO_MODE[GPIO_MODE.OUTPUT_OPENDRAIN] = 'OUTPUT_OPENDRAIN';
    GPIO_MODE[GPIO_MODE.OUTPUT_PUSHPULL] = 'OUTPUT_PUSHPULL';
    GPIO_MODE[GPIO_MODE.INPUT_PULLUP] = 'INPUT_PULLUP';
    GPIO_MODE[GPIO_MODE.OUTPUT_OPENDRAIN_PULLUP] = 'OUTPUT_OPENDRAIN_PULLUP';
    GPIO_MODE[GPIO_MODE.INPUT_PULLDOWN] = 'INPUT_PULLDOWN';
    GPIO_MODE[GPIO_MODE.INPUT_ANALOG_FLOATING] = 'INPUT_ANALOG_FLOATING';
    GPIO_MODE[GPIO_MODE.OUTPUT_ANALOG_PWM] = 'OUTPUT_ANALOG_PWM';
    var TapGPIOController = /** @class */ (function () {
        function TapGPIOController(tap, conf) {
            this.tap = tap;
            this.conf = conf;
        }
        /**
         * @return {?}
         */
        TapGPIOController.prototype.toggle = /**
         * @return {?}
         */
        function () {
            if (this._state == exports.GPIO.Signal.HIGH) {
                return this.low();
            }
            else {
                return this.high();
            }
        };
        /**
         * @return {?}
         */
        TapGPIOController.prototype.low = /**
         * @return {?}
         */
        function () {
            var _this = this;
            return this.tap.lwm2m.post("/1029/" + this.conf.num + "/5", Uint8Array.from([0]))
                .then((/**
             * @param {?} response
             * @return {?}
             */
            function (response) {
                response.successful();
                _this._state = exports.GPIO.Signal.LOW;
            }));
        };
        /**
         * @return {?}
         */
        TapGPIOController.prototype.high = /**
         * @return {?}
         */
        function () {
            var _this = this;
            // let value = 0xFF & this.conf.num;
            // let value = 0b00011101;
            /** @type {?} */
            var value = 1;
            return this.tap.lwm2m.post("/1029/" + this.conf.num + "/5", Uint8Array.from([value]))
                .then((/**
             * @param {?} response
             * @return {?}
             */
            function (response) {
                response.successful();
                _this._state = exports.GPIO.Signal.HIGH;
            }));
        };
        /**
         * @return {?}
         */
        TapGPIOController.prototype.read = /**
         * @return {?}
         */
        function () {
            return this.tap.lwm2m.get("/1029/" + this.conf.num + "/4")
                .then((/**
             * @param {?} response
             * @return {?}
             */
            function (response) {
                /** @type {?} */
                var result = response.body()[0];
                /** @type {?} */
                var decoded = result == 1 ? exports.GPIO.Signal.HIGH : exports.GPIO.Signal.LOW;
                console.log('READ RESULT', decoded);
                return decoded;
            }));
        };
        /**
         * @param {?=} direction
         * @param {?=} initial
         * @return {?}
         */
        TapGPIOController.prototype.setup = /**
         * @param {?=} direction
         * @param {?=} initial
         * @return {?}
         */
        function (direction, initial) {
            var _this = this;
            if (direction === void 0) { direction = exports.GPIO.Mode.OUT; }
            if (initial === void 0) { initial = exports.GPIO.Signal.LOW; }
            // let value = 0xFF & this.conf.num;
            // let value = 0b00011101;
            /** @type {?} */
            var value = 1;
            switch (direction) {
                case exports.GPIO.Mode.IN:
                    return this.tap.lwm2m.post("/1029/" + (this.conf.num + 10) + "/5", Uint8Array.from([value]))
                        .then((/**
                     * @param {?} response
                     * @return {?}
                     */
                    function (response) {
                        response.successful();
                        _this._mode = exports.GPIO.Mode.IN;
                    }));
                case exports.GPIO.Mode.OUT:
                    return this.tap.lwm2m.post("/1029/" + (this.conf.num + 10) + "/5", Uint8Array.from([0x00]))
                        .then((/**
                     * @param {?} response
                     * @return {?}
                     */
                    function (response) {
                        response.successful();
                        _this._mode = exports.GPIO.Mode.OUT;
                    }));
                default:
                    throw new Error("Invalid setup");
            }
        };
        return TapGPIOController;
    }());
    if (false) {
        /** @type {?} */
        TapGPIOController.prototype._state;
        /** @type {?} */
        TapGPIOController.prototype._mode;
        /** @type {?} */
        TapGPIOController.prototype.tap;
        /** @type {?} */
        TapGPIOController.prototype.conf;
    }

    /**
     * @fileoverview added by tsickle
     * Generated from: lib/tap-gpio.component.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    var TapGpioComponent = /** @class */ (function () {
        function TapGpioComponent(tapService) {
            var _this = this;
            this.tapService = tapService;
            this.schema = [];
            this.lines = 'full';
            this.pins = this.schema.map((/**
             * @param {?} entry
             * @return {?}
             */
            function (entry) {
                if (entry.pin.type == 'GPIO') {
                    ((/** @type {?} */ (entry))).controller = new TapGPIOController(_this.tap, entry.pin);
                }
                return (/** @type {?} */ (entry));
            }));
        }
        Object.defineProperty(TapGpioComponent.prototype, "tap", {
            get: /**
             * @return {?}
             */
            function () {
                return this.tapService.tap;
            },
            enumerable: true,
            configurable: true
        });
        /**
         * @return {?}
         */
        TapGpioComponent.prototype.ngOnInit = /**
         * @return {?}
         */
        function () {
        };
        TapGpioComponent.decorators = [
            { type: core.Component, args: [{
                        selector: 'tap-gpio',
                        template: "\r\n<ion-list [lines]=\"lines\">\r\n  <ion-item *ngFor=\"let config of pins\">\r\n    <ng-template [ngIf]=\"config.pin.type == 'GROUND'\" #ground>\r\n        <span slot=\"start\">{{config.num}}</span>\r\n        <ion-label>\r\n          <span slot=\"start\">{{config.pin.type}}</span>\r\n        </ion-label>\r\n    </ng-template>\r\n    <ng-template [ngIf]=\"config.pin.type == 'POWER'\" #power>\r\n        <span slot=\"start\">{{config.num}}</span>\r\n        <span slot=\"start\">{{config.pin.type}}</span>\r\n        <ion-label>\r\n          <span slot=\"start\">{{config.power}}V</span>\r\n        </ion-label>\r\n    </ng-template>\r\n    <ng-template [ngIf]=\"config.pin.type == 'DISABLED'\" #disabledpin>\r\n        <span slot=\"start\">{{config.num}}</span>\r\n        <ion-label>\r\n          <span slot=\"start\">{{config.pin.type}}</span>\r\n        </ion-label>\r\n    </ng-template>\r\n    <ng-template [ngIf]=\"config.pin.type == 'GPIO'\" #gpio>\r\n        <span slot=\"start\">{{config.num}}</span>\r\n        <span slot=\"start\">{{config.pin.type}} {{config.pin.num}}</span> \r\n        <ion-label>\r\n          {{config.title}}\r\n        </ion-label>\r\n        <ion-buttons slot=\"end\">\r\n            <ion-button [color]=\"config.controller._mode == 'OUT' ? 'primary' : ''\" (click)=\"config.controller.setup('OUT')\">OUT</ion-button>\r\n            <ion-button (click)=\"config.controller.read()\">READ</ion-button>\r\n        </ion-buttons>\r\n        <ion-buttons slot=\"end\">\r\n            <ion-button [color]=\"config.controller._mode == 'IN' ? 'primary' : ''\" (click)=\"config.controller.setup('IN')\">IN</ion-button>\r\n            <!-- <ion-toggle (click)=\"config.controller.toggle()\"></ion-toggle> -->\r\n            <ion-button [color]=\"config.controller._state == 'LOW' ? 'primary': ''\" (click)=\"config.controller.low()\">LOW</ion-button>\r\n            <ion-button [color]=\"config.controller._state == 'HIGH' ? 'primary': ''\" (click)=\"config.controller.high()\">HIGH</ion-button>\r\n        </ion-buttons>\r\n    </ng-template>\r\n  </ion-item>\r\n</ion-list>",
                        styles: [""]
                    }] }
        ];
        /** @nocollapse */
        TapGpioComponent.ctorParameters = function () { return [
            { type: ionic.CurrentDeviceService }
        ]; };
        TapGpioComponent.propDecorators = {
            schema: [{ type: core.Input }],
            lines: [{ type: core.Input }]
        };
        return TapGpioComponent;
    }());
    if (false) {
        /** @type {?} */
        TapGpioComponent.prototype.schema;
        /** @type {?} */
        TapGpioComponent.prototype.lines;
        /** @type {?} */
        TapGpioComponent.prototype.pins;
        /** @type {?} */
        TapGpioComponent.prototype.tapService;
    }

    /**
     * @fileoverview added by tsickle
     * Generated from: lib/tap-gpio.module.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    var TapGpioModule = /** @class */ (function () {
        function TapGpioModule() {
        }
        TapGpioModule.decorators = [
            { type: core.NgModule, args: [{
                        declarations: [
                            TapGpioComponent,
                        ],
                        exports: [
                            TapGpioComponent
                        ],
                        imports: [
                            common.CommonModule,
                            angular.IonicModule
                        ]
                    },] }
        ];
        return TapGpioModule;
    }());

    /**
     * @fileoverview added by tsickle
     * Generated from: lib/pinschema.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    /** @type {?} */
    var J1PinSchema = [
        {
            num: 1,
            pin: {
                power: 3.3,
                type: 'POWER'
            },
            title: 'Vcc',
        },
        {
            num: 2,
            pin: {
                num: 4,
                // ???
                type: "GPIO"
            },
            title: 'SP3PIO/SWDIO (TMS)',
        },
        {
            num: 3,
            pin: {
                type: "GROUND"
            },
            title: 'Gnd',
        },
        {
            num: 4,
            pin: {
                num: 2,
                type: "GPIO"
            },
            title: 'S3PCLK/SWDCLK (TCK)',
        },
        {
            num: 5,
            pin: {
                type: "GROUND"
            },
            title: 'Gnd',
        },
        {
            num: 6,
            pin: {
                num: 3,
                type: "GPIO"
            },
            title: 'SWO (TDO)',
        },
        {
            num: 7,
            pin: {
                type: "DISABLED"
            },
            title: 'Not connected',
        },
        {
            num: 8,
            pin: {
                num: 4,
                type: "GPIO"
            },
            title: 'TDI',
        },
        {
            num: 9,
            pin: {
                type: "GROUND"
            },
            title: 'Gnd',
        },
        {
            num: 10,
            pin: {
                num: 0,
                type: "GPIO"
            },
            title: 'RST'
        }
    ];
    /** @type {?} */
    var J3PinSchema = [
        {
            num: 1,
            pin: {
                power: 3.3,
                type: 'POWER'
            },
            title: 'Vcc',
        },
        {
            num: 2,
            pin: {
                type: "GROUND"
            },
            title: 'Gnd',
        },
        {
            num: 2,
            pin: {
                num: 4,
                type: "GPIO"
            },
            title: 'SP3PIO/SWDIO (TMS)',
        },
        {
            num: 4,
            pin: {
                num: 2,
                type: "GPIO"
            },
            title: 'S3PCLK/SWDCLK (TCK)',
        },
        {
            num: 10,
            pin: {
                num: 0,
                type: "GPIO"
            },
            title: 'RST'
        }
    ];

    exports.J1PinSchema = J1PinSchema;
    exports.J3PinSchema = J3PinSchema;
    exports.TapGpioModule = TapGpioModule;
    exports.ɵa = TapGpioComponent;

    Object.defineProperty(exports, '__esModule', { value: true });

})));
//# sourceMappingURL=iotize-ionic-gpio.umd.js.map
