#!/usr/bin/env python

import sys
import time
import array

import Image
import GDprep
import gameduino

import unittest

gd = gameduino.Gameduino(sys.argv[1], 115200)

class GameduinoTest(unittest.TestCase):

    def test_j1_flash(self):
        for iomode in (0, 1, ord('J'), ord('F'), 181, 255):
            gd.wr(gameduino.IOMODE, iomode)
            gd.wr(gameduino.COMM, 0)
            gd.microcode(gameduino.readarray("../j1firmware/testflash.binle"))
            if iomode == ord('J'):
                expected = 0x94     # flash status OK
            else:
                expected = 0x00
            self.assertEqual(gd.rd(gameduino.COMM), expected)   # expected flash status

if __name__ == '__main__':
    unittest.main(argv=sys.argv[1:])
